How do I plot an FFT of a large data set?

I have a very large data set that I am trying to use to plot a FFT. The sampling frequency is 20000 and there are 555201 data points. My code is not giving me an accurate graph for figure 2, the plot of the FFT.
Here is my code:
filename = 'Sample192.xlsx';
T = readtable(filename);
x = T{1:555201,1};
y = T{1:555201,2};
%
figure(1)
plot(x,y);
%
Y = fft(y);
Fs = 20000;
f = (0:length(Y)-1)*(Fs/length(Y));
figure(2)
plot(f,abs(Y))

3 Comments

I've also tried this code and it's also only giving me a peak at zero:
filename = 'Sample192.xlsx';
T = readtable(filename);
x = T{1:555201,1};
y = T{1:555201,2};
%
figure(1)
plot(x,y);
%
Y = fft(y);
Fs = 20000;
f = (0:length(Y)-1)/length(Y);
%
figure(2)
plot(x,abs(Y))
%
figure(3)
plot(f,abs(Y));
%
n = length(y);
fshift = (-n/2:n/2-1)*(Fs/n);
yshift = fftshift(Y);
%
figure(4)
plot(fshift,abs(yshift));
%
hello
can you share the data file as well ?
tx
The data file is too large for me to upload but I can probably attach a snippet of the data if that'll work.

Sign in to comment.

 Accepted Answer

David Goodmanson
David Goodmanson on 10 Dec 2021
Edited: David Goodmanson on 10 Dec 2021
Hi Angelica,
One possible reason is that the data has a DC offset, i.e. its mean is not zero. What can happen is that the DC offset, which is the f=0 point in the resulting transform, is much, much larger that any other point in the fft, so all you see is a peak at f = 0. For a signal S, If you take away the mean with S = S - mean(S) and then do the transform, you may well do better. Or you could do the equivalent by taking the existing transform (let's say the fft output is Y) and zero out the first point (which corresponds to f=0 if you have not used fftshift) with Y(1) = 0 and see what that looks like on a plot.

More Answers (0)

Categories

Products

Release

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!