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!


