0

I have a wave of frequency 100 Hz (it is a set of data). I would like to plot the amplitude and the phase angle vs frequency. This is what I do but my amplitude shows at the wrong frequency, what am I missing?

given x=[....] set of data representing wave of frequency = 100 Hz, of length 1500.
first: Nfft = 2^nextpow2(length(x));
second: Fs = 1000; (that is 10 times my frequency of 100, is that correct?)
third: get fft : xdft = fft(x,Nfft);
forth: get amplitude: amp = abs(xdft);
fifth: get phase :    ang = unwrap(angle(xdft));

Now my main issue is to set up the frequency vector correctly, this is what i did

f_fold = Fs/2; % folding frequency = max frequency of FFT (Hz)
T = Nfft/Fs % total sample time (s)
del_f = 1/T; % (Hz)
f_v = [0:del_f:f_fold]'; % frequency (Hz)

I also tried matlab's suggestion: f_v = Fs*(0:Nfft-1)/Nfft

But my amplitudes always show at the wrong frequency. What can I do to fix this? Thank you

Paul R
  • 208,748
  • 37
  • 389
  • 560
Amani Lama
  • 305
  • 7
  • 14

2 Answers2

3

First off, FS (your sampling frequency) is not arbitrary. If you are given a set of data in the time domain, then the sampling frequency of that data is already determined. You can get a higher sampling frequency by upsampling (interpolating between the existing data points) or a lower sampling frequency (downsampling) by removing data points.

Second, when you take an fft of a row vector in Matlab, you get back

[positive frequency data, negative frequency data]

The function fftshift can be used to put this in a more "viewable" format.

fftshift(fft(x))

will return

[negative frequency data, positive frequency data]

Without your data set, I can't provide an exact solution to why your amplitudes don't line up (although I suspect it has to do with your choice of sampling frequency). However, here is an example illustrating the concepts.

fs = 500; % 500 Hz sampling frequency: 500 > 2*100 => satifies Nyquist
t = 0:1/fs:10; % 10 seconds of data sampled at fs
y = sin(2*pi*100.*t) + sin(2*pi*25.*t); % Two sinusoids at 25 Hz and 100 Hz
Y=fftshift(fft(y));
f=linspace(-fs/2, fs/2, length(Y));
plot(f, abs(Y));

You should have four amplitude spikes at -100, -25, 25, and 100.

Here is another example that resembles your code a bit more.

fs = 500; % 500 Hz sampling frequency: 500 > 2*100 => satifies Nyquist
t = 0:1/fs:10; % 10 seconds of data sampled at fs
y = sin(2*pi*100.*t) + sin(2*pi*25.*t); % Two sinusoids at 25 Hz and 100 Hz
NFFT = 2^nextpow2(y); %8192
Y=fft(y, NFFT);
delta_f = fs/(NFFT-1);
f=0:delta_f:fs/2;
plot(f, abs(Y(1:length(f)));
PaxRomana99
  • 564
  • 1
  • 5
  • 12
0

You can use my little tool easyFFT. It calculates the correct frequency vector for you, in addition to the FFT.

Daniel1000
  • 779
  • 4
  • 11