Finding MNF for every second inteval
显示 更早的评论
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 个评论
Mathieu NOE
2024-4-22
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
2024-4-22
BTW, the code does not show how you generate the 1s data PSD - did you remove that from the posted code intentionnaly ?
Keisha Alfreda
2024-4-23
编辑:Keisha Alfreda
2024-4-23
Mathieu NOE
2024-4-23
NB your ylabel says psd is in dB / Hz but you are plotting a psd in linear units ² / Hz
Mathieu NOE
2024-4-24
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 ?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Parametric Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


