Re: FFT acting strangely...



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 Fs
is not
specified. You need to specify it and make sure that the
vector
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
.



Relevant Pages

  • Re: Hilbert transform using FFT approach
    ... >>> sequence of data using the analytic signal approach using the FFT ... Then multiply the taps by sine ... and cosine of 240 kHz to make them into BPFs. ...
    (comp.dsp)
  • Re: Hilbert transform using FFT approach
    ... >>> sequence of data using the analytic signal approach using the FFT ... Then multiply the taps by sine ... and cosine of 240 kHz to make them into BPFs. ...
    (comp.dsp)
  • Re: Stream Cipher for encypting voice traffic
    ... A fast fourier transform to define the stream takes the sine relation ... You get to have fun defining the standard fft data block!! ...
    (sci.crypt)
  • Re: Help!!! : large value in the Real part of a fft(sine)
    ... Was wondering if the FFT code on a sine that i have written is correct? ... Is your sine wave antisymmetric with respect to the ... random sine wave is zero at one end of an FFT aperture, ...
    (comp.dsp)
  • Re: zero-padding and normalization for fft
    ... I had assumed from context that there was an integer number of sine ... zeropadded FFT size. ... The basis vector set of a DFT/FFT depends on it length. ... Thus the dot products won't be of the same two sinusoids ...
    (comp.dsp)