Re: FFT acting strangely...
- From: Randy Poe <poespam-trap@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 13:12:52 -0800 (PST)
Top-posting repaired.
On Feb 29, 3:51 pm, "Michael Stachowsky" <mstachow...@xxxxxxxxx>
wrote:
Rune Allnor <all...@xxxxxxxxxxxx> wrote in message
<f187d8bb-5e73-491c-94ae-56d64264c...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On 29 Feb, 20:56, "Michael Stachowsky"<mstachow...@xxxxxxxxx> wrote:
I am trying to perform an FFT on some data. =A0My data is:
times =3D [1:1000];
accelArray =3D 0.7*sin(50*times);
Then I do:
fftAccel =3D (fft(accelArray))/length(accelArray);
fftFreqs =3D Fs/2*linspace(0,1,length(accelArray)/2);
Then, when plotting, I do this:
plot(fftFreqs,2*abs(fftAccel(1:length(accelArray)/2)));
Now, I'm expecting to get a peak at 50Hz, but instead I get
a peak at 42.8Hz. =A0I've tried to put
sin(2*pi*50*times), but
that just gives me numbers that are close to 10^-11.
The reason this happened is that the way you
defined "times" was as a set of integers. So
you are calculating sin(2*pi*50*integer), which
is the sine of an integer multiple of 2*pi, which is
0.
I tried to run your code, but got an error message that Fsis not
specified. You need to specify it and make sure that thevector
times is set up as
Fs = <????>
times = (0:1000)/Fs;
Ah, sorry. Fs = 1000;
sin(2*pi*f*times) is correct for a sine wave of frequency
f, but if you want to sample at rate Fs, then your times
should be multiples of 1/Fs as Rune suggested.
If you want 1000 samples, then you should use
times = (0:999)/Fs;
In general, if you want N samples at rate Fs, your times
are
times = (0:N-1)/Fs;
I discovered my problem: it was one of aliasing. I had
mistyped the example data.
But I came upon another issue. This may stem from my lack
of familiarity with FFT, but, how do I make the proper array
of frequencies for my analysis?
The frequency spacing is 1/(time of sample). If you have
N samples at rate Fs, then it is 1/(N/Fs) = Fs/N
Thus, your frequency array should be (0:N-1) * (Fs/N)
This is going to be used in an experiment with reasonably
strict accuracy controls (at least +/- 0.1Hz), and my FFT
analysis gave me 120.12Hz when I gave it a 120Hz sine wave...
My guess is that this is because you used a 1001-point
time sample instead of a 1000-point time sample, since
your frequency seems to be off by 1 part in 1000.
- Randy
.
- References:
- FFT acting strangely...
- From: Michael Stachowsky
- Re: FFT acting strangely...
- From: Rune Allnor
- Re: FFT acting strangely...
- From: Michael Stachowsky
- FFT acting strangely...
- Prev by Date: Re: NI DAQ Hw Trigger Output
- Next by Date: Re: FFT acting strangely...
- Previous by thread: Re: FFT acting strangely...
- Next by thread: Re: FFT acting strangely...
- Index(es):
Relevant Pages
|