FFT analysis from imported data

1 view (last 30 days)
Faissal
Faissal on 2 Aug 2014
Answered: Star Strider on 3 Aug 2014
I am having trouble with using the fft command. The signal I am attempting to process is shown below and is pretty straight forward with a fundamental frequency~4Hz. I am importing the data collected from excel and running a DFT on it but I am getting weird results.
CODE:
close all
clear all
clc
%get the data from excel first
timeNoWind = ((xlsread('DFTpurpose.xlsx',1,'A4721:A5021'))*10^-3)';
dataNoWind = xlsread('DFTpurpose.xlsx',1,'E4721:E5021');
figure(1)
plot(timeNoWind,dataNoWind,'r');
xlabel('time (s)')
ylabel('bits')
grid on
N = 2^nextpow2(length(dataNoWind));
Y = fft(dataNoWind,N);
Fs = 8; %Sampling frequency set at 10 Hz since signal is ~4Hz
f = Fs/2*linspace(0,1,N);
p = Y.*conj(Y)/N; %Power of signal
figure(2)
plot(f,p)
************************
  2 Comments
Star Strider
Star Strider on 2 Aug 2014
You can find the sampling interval Ts easily enough by taking the mean of the differences between the time points in TimeNoWind. The actual Fs is the inverse of that Ts.
I don’t have your data, but I would define:
Ts = mean(diff(TimeNoWind));
Fs = 1/Ts;
This assumes TimeNoWind is in some sort of continuous serial format rather than ‘HH:MM:DD:FFF’.
Faissal
Faissal on 3 Aug 2014
I am importing data from excel that was initially collected from an arduino. So my time resolution (Ts) is around 2 ms. I have tried previously to use 500 Hz as my sampling frequency however from what I have learned, I thought the sampling frequency should be at least twice the signal frequency. And as seen from my graph, the signal frequency is 4 Hz. Nevertheless, the way I see it is that Fs is just for setting up your frequency domain for your fft output correct? I mean its not required as an input for the fft function. Shouldn't I see a nice peak at 4 Hz in my frequency domain graph. The frequency domain graph I get using 1/0.002 as my Fs is shown below.
It is odd also that my y-domain reaches 10^7
Really confused here... thanks for your help in advance.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 3 Aug 2014
The fft is not as intuitive as it might seem. It takes some effort to understand it.
The sampling interval, Ts, and its inverse, the sampling frequency Fs, are fixed when you set up your experiment and collect your data. The highest resolvable frequency in your data is the Nyquist frequency, Fn with Fn = 1/(2*Ts). Fs also defines the fundamental frequency of your fft.
Your statement:
p = Y.*conj(Y)/N; %Power of signal
isn’t quite correct. Changing it to:
p = abs(Y)/N; %Power of signal
will produce the correct result.
You should definitely see a nice peak at 4 Hz. The only error I see in the code you posted is your choice of Fs. Choose the correct Fs, and your fft should be plotted just as you expect it.
The documentation for fft explains it much better than I can, so I direct you to it. I also suggest a good signal processing textbook, such as the one by Proakis and Manolakis, if you don’t already have one.

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!