What to do for the right FFT in Matlab (two peaks and incorrect amplitude)?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This is the FFT I'm using. But two peaks (did not expect the one in the beginning) are occurring and the amplitude is not as specified (expecting a value of 2). Any help is much appreciated!
Amp = 2;
freqHz = 10000;
fsHz = freqHz*2+1;
dt = 1/fsHz;
sine = Amp*sin(2*pi*freqHz*(0:dt:1-dt));
transform = fft(sine,fsHz)/fsHz;
magTransform = abs(transform);
faxis = linspace(0,fsHz/2,fsHz);
plot(faxis,fftshift(magTransform));
xlabel('Frequency')
1 commentaire
Image Analyst
le 26 Juin 2018
Why do you (incorrectly) think the fft of a sinewave should have only one peak instead of 2? It has 2 because it's supposed to have 2.
Réponses (1)
David Goodmanson
le 28 Juin 2018
Hi mldmnn,
Since
A*sin(2*pi*f0*t) = (A/(2i)) * ( exp(2*pi*i*f0*t) - exp(-2*pi*i*f0*t) ),
the transform of sin has two peaks, one at positive frequency, one at negative frequency. Each has absolute value of half the amplitude of the sine function. You are getting the correct result. But with your values of freqHz and dt,
freqHz*dt = .499975 % cycles per point.
The frequency is very high and there are only about two points per cycle. So it's hard to see what's going on. If you plot your sine as a function of time, you get something ugly. (Actually it's kind of pretty, but ugly in this context). The following example uses a more suitable frequency and you can see peaks at +-f0.
N = 1000;
fs = 1000;
dt = 1/fs;
t = (0:N-1)*dt;
df = fs/N;
f = (-N/2:N/2-1)*df;
f0 = 20;
y = 2*sin(2*pi*f0*t);
figure(1)
plot(t,y)
z = fft(y)/N;
figure(2)
plot(f,fftshift(abs(z)))
ylim([0 1.2])
0 commentaires
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!