What to do for the right FFT in Matlab (two peaks and incorrect amplitude)?

조회 수: 6 (최근 30일)
mldmnn
mldmnn 2018년 6월 26일
답변: David Goodmanson 2018년 6월 28일
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
Image Analyst
Image Analyst 2018년 6월 26일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

David Goodmanson
David Goodmanson 2018년 6월 28일
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])

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by