Finding MNF for every second inteval
Mostrar comentarios más antiguos
Hello everyone! I'm currently trying to plot the MNF value from every 1 second interval of filtered signal. Here is the code I write:
%% MNF and MDF of signal
%Calculate MNF from every 1 s interval of the filtered signal
start = 0;
stop = 120;
%num_windows = floor(length(psd1) / fs);
interval=ceil((stop-start)/fs);
t_mnf = linspace(start,stop,interval+1);
mnf_s = zeros(1, interval+1);
for i=start:stop
% Check for starting index (avoid going below 1)
start_index = max(1, (i-1)*fs+1);
% Check for ending index (avoid exceeding psd1 length)
end_index = min(length(psd1), i*fs);
%Extract current window data by assuming 1 second window
window_data = psd1(start_index:end_index);
mnf_s(i-start+1)=meanfreq(window_data,fs);
end
figure(5)
plot(t,mnf_s,'-*k')
xlabel('Time (s)'); ylabel('MNF (Hz)')
title('MNF')
The 'psd1' variable contains the PSD value of filtered signal. The code doesn't work. Where could it went wrong?
5 comentarios
Mathieu NOE
el 22 de Abr. de 2024
hello
it would help if you could supply the data as well
but I have a feeling the problem is here
mnf_s(i-start+1)=meanfreq(window_data,fs);
^^
according to meanfreq doc
freq = meanfreq(pxx,f) returns the mean frequency of a power spectral density (PSD) estimate, pxx. The frequencies, f, correspond to the estimates in pxx.
what you have coded is kinda mix up of both possibilities , but that is not gonna work
please provide the frequency vector (and not the sampling frequency) when dealing with psd input
Mathieu NOE
el 22 de Abr. de 2024
BTW, the code does not show how you generate the 1s data PSD - did you remove that from the posted code intentionnaly ?
Keisha Alfreda
el 23 de Abr. de 2024
Editada: Keisha Alfreda
el 23 de Abr. de 2024
Mathieu NOE
el 23 de Abr. de 2024
NB your ylabel says psd is in dB / Hz but you are plotting a psd in linear units ² / Hz
Mathieu NOE
el 24 de Abr. de 2024
it's not clear for me , but your main code should compute the psd for every second of data
is it what you are doing ?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Parametric Spectral Estimation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


