Calculation of mean signal frequency
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi everyone,
I'm trying to perform an analysis in the frequency domain, but I'm confused regarding how to obtain the PSD signal.
Currently, I'm using the following to obtain the PSD:
L = length(data);
% Compute Fast Fourier Transform
Y = fft(data);
% Compute the two-sided spectrum P2
P2 = abs(Y/L);
% Compute the single-sided spectrum P1 based on P2
P1 = P2(1:ceil(L/2)+1);
P1(2:end-1) = 2*P1(2:end-1);
power = P1;
% Define the frequency domain axis
frequencies = fs*(0:ceil(L/2))/L;
I have tested this with the following signal:
fs = 200;
x = 0:1/fs:20
data = sin(2*pi*5*x);
And I get the following PSD:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/337669/image.png)
I'm trying to calculate the mean frequency using the following formula:
mean_frequency = sum(power.*frequencies)/sum(frequencies)
Where I obtain
mean_frequency = 5.0587e-04
which is obviously wrong. However, when I use MATLAB's meanfreq function, I get meanfreq(data, fs) = 4.999Hz, which is the expected.
Can please anyone tell me what I'm doing wrong? After this I want to perform a complete analysis in the frequency domain (e.g, median frequency, total power, etc) and I need to make sure my PSD data is correct.
Many thanks for your attention,
Diogo
댓글 수: 1
Abhineet Ram
2022년 9월 15일
Hi, where did you get this formula? I would like to understand the concept of this method/code. Thanks
채택된 답변
Star Strider
2020년 7월 27일
There are two small errors.
Correcting them:
P2 = abs(Y/L).^2; % Power = Amplitude^2
and:
mean_frequency = sum(power.*frequencies)/sum(power) % Divide By Sum Of Power
producing:
meanfreq =
4.99913568484097
.
댓글 수: 6
Abhineet Ram
2022년 9월 15일
Hi, where did you get this formula? I would like to understand the concept of this method/code. Thanks
Star Strider
2022년 9월 15일
@Abhineet Ram — Probably Wikipedia. (It’s been a few years.)
It would have been easier had I used and linked to the meanfreq function (introduced in R2015a, proving once again that reading the Release Notes is time well-spent, something I obviously did not spend enough time on), that I now refer you to.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!