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!


