signal amplitude using FFT - conflicting results and misunderstandings
Show older comments
I am trying to measure the amplitude of different frequencies composing a signal using some code found here on this post.
Using this code
Fs=20000;
nfft = length(seg1); % calculate lenght of signal, seg1 is my signal
res = fft(seg1,nfft)/ nfft; % calculate fft over the whole segment normalizing the fft
f = Fs/2*linspace(0,1,nfft/2+1); % choosing correct frequency axes
res = res(1:nfft/2+1);
figure(2), plot(f,abs(res));
xlabel('Frequency in Hz');ylabel('Amplitude (mV)');
xlim([200 600])
ytix = yticks*1000; % convert signal in mV (the original signal units are in V)
yticklabels(ytix);
I get this

It seems fine, now I cannot verify if the signal amp is really around 45 mV but I could test it.
Just for proofing, I checked the help of the FFT function in MATLAB and I found this code to calculate signal power
figure(3)
Fs = 20000;
L = length(seg1); % length of signal
n = 2^nextpow2(L); % determine adjustable window size based on powers of 2
dim=2;
Y = fft(seg1,n,dim); % calculate fft of signal over the whole segment
P2 = abs(Y/L); % calculate signal power
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
xlim([200 600])
what I get is this

I think the result is the same and it is just a matter of converting the units in the right way. Besides the 10^3 conversion, I think there is a 2x factor that needs to be removed somewhere...however I am not sure which would be the more correct way to calculate it.
While in the first code power is simply calculated as the absolute value of the fft transformed signal, In the second case it seems that, besides that (see the line commented with "calculate signal power"), the signal power is also multiplied per 2. As a result I get a double of the first power measurement in the second plot (note: the units in this second plot are not converted in millivolts but if one does it, the value seems to me double). And in fact I checked it, and it is the case.
Just wondering what would be the correct way to calculate signal amplitude. My signal is a sinewave voltage signal at 400 Hz. The amplitude should be in the range of few tens of mV (so the first calculation could be realistic... but the second too).
Thank you for your feedback !
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!