Wrong amplitude values after the FFT

3 次查看(过去 30 天)
Hi all, At the plot of the code that written below, i should see amplitude between values of 75 to 200 uV but there is something strange in my plot, can you help me and advise, what wrong with my code and how can i correct that ?
Thank you all
Here is the code :
clear all;
close all;
Fs = 200
t= 0:1/Fs:180
y_in=zeros (1, length(t));
for i = 1:18
F = randi ([4 7], 1);% frequency
A = randi ([75 200],1);% amplitude A=75~200 uV.
y_tmp =A*sin (2*pi*F*t);
y_in=y_in+ y_tmp;
end;
L=length (y_in);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y_new = fft(y_in,NFFT)/L;
f_new = Fs/2*linspace(0,1,NFFT/2+1);
figure(1)
plot(f_new,2*abs(Y_new(1:NFFT/2+1))) ;
title('Single-Sided Amplitude Spectrum of y_in(t)')
xlabel('Frequency (Hz)')
ylabel('|y_in(f)|')

采纳的回答

Wayne King
Wayne King 2012-6-12
The main issue you have is that you are only randomly sampling from a small set of frequencies and you are doing that 18 times, then you don't vary the phase at all. Therefore, you're going to generate the same frequency more than once. You're adding sine waves at the same frequency and phase with different amplitudes. Therefore the resulting amplitude is going to be the sum of the individual amplitudes.
I'll verify this for a frequency of 4 Hz.
Fs = 200;
t= 0:1/Fs:180-1/Fs;
y_in=zeros (1, length(t));
for i = 1:18
F = randi ([4 7], 1);% frequency
freqv(i) = F;
A = randi ([75 200],1);% amplitude A=75~200 uV.
amp(i) = A;
y_tmp =A*sin (2*pi*F*t);
y_in=y_in+ y_tmp;
end;
L=length(y_in);
Y_new = fft(y_in);
Y_new = Y_new(1:length(y_in)/2+1)/L;
Y_new(2:end-1) = 2*Y_new(2:end-1);
f_new = Fs/2*linspace(0,1,length(y_in)/2+1);
plot(f_new,abs(Y_new));
title('Single-Sided Amplitude Spectrum of y_in(t)')
xlabel('Frequency (Hz)')
ylabel('|y_in(f)|')
Note that if we find the number of times, 4 Hz is added and sum the amplitudes of those components, you get your answer.
indices = find(freqv == 4);
amp4 = sum(amp(indices));
You see that amp4 is the amplitude of your component at 4 Hz in the plot.

更多回答(1 个)

engineer bsc
engineer bsc 2012-6-12
guys, please,someone ?
it is really important to me.
thanks

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by