-1

Trying to do a Fourier Transform on a random but discrete time-domain signal, so that I can look into the dominant frequencies etc, but I'm struggling to plot it correctly.

The data has been gathered using a vibration-sensor app on my phone, which can also do FT within (which I am assuming to be fairly accurate), so I have been comparing the FT from the app to the FT from MATLAB. The lines are similar in shape, but the MATLAB one is mirrored, possibly stretched, and the scaling is totally off.

Does anyone know of any guides or tutorials on how to correctly display a FFT?

This is my code so far, the xls file is simply a column of the accelerations. Anything look particularly wrong?

Any help would be great!

clc
clear

T = 5.57;                                           % Sampling time (s)
L = 512;                                            % Length of signal (No. samples taken)
Fs = L/T;                                           % Sampling frequency (Hz)
a = xlsread ('Randomshake19.02.xlsx', 'X-Time');    % X-plane accelerations (m/s^2)
t = linspace (0, T, L);                             % Time vector
NFFT = 2^nextpow2(L);                               % Number of points used to form FFT. Next power of 2 from length of y 
X = linspace (1, Fs, L);

Y = fft(a, NFFT);

subplot (1, 2, 1)                                   % Time domain plot
plot (t, a)                                        
xlabel('Time (s)')
ylabel('Magnitude of Acceleration (m/s^2)')

subplot (1, 2, 2)                                   % Frequency domain plot
plot (X,abs(Y))
xlabel('Frequency (Hz)')
ylabel('Magnitude of Acceleration (m/s^2)')
chappjc
  • 30,359
  • 6
  • 75
  • 132
  • Please add images (or links to images) of what you get and the desired output. – Eitan T Feb 26 '14 at 00:01
  • Look into the fftshift() command which will reorder the fourier transform properly. You can then scale the frequency axis so that it runs from -Fs/2 to Fs/2. – ewz Feb 26 '14 at 03:46
  • Why not follow the example provided in the `fft` documentation? – bdecaf Feb 26 '14 at 10:46

1 Answers1

0

you may want to look at: Understanding Matlab FFT example

for a simple fft understanding and some plots, and at MATLAB 'spectrogram' params

for spectrograms in matlab. i kinda guess thats what you want.

Community
  • 1
  • 1
ben
  • 1,380
  • 9
  • 14