how to create the frequency vector on FFT
Show older comments
FileName='Book2.xlsx';
a=xlsread(FileName);
time=a(:,1);
TC1=a(:,2);
TC13=a(:,3);
TC21=a(:,4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,2,1);
TC1_hat=fft(TC1);
L=length(TC1);
dt = .01;
fs=1/dt;
f=fs*(0:(L/2))/L;
plot(f,TC1_hat(1:numel(f))*2)
title(' FFT CONDENSER')
xlabel('FREQUANCY')
ylabel('AMPLITUDE')
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
subplot(2,2,2);
TC13_hat=fft(TC13);
plot(f,TC13_hat(1:numel(f))*2)
title(' FFT ADIABATIC')
xlabel('FREQUANCY')
ylabel('AMPLITUDE')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
subplot(3,2,[3,4]);
TC21_hat=fft(TC21);
plot(f,TC21_hat(1:numel(f))*2)
title(' FFT Evaporator')
xlabel('FREQUANCY')
ylabel('AMPLITUDE')
%%%%%%%%%%%%%%%%%%%%%%%%%%
Hi ,
I was trying to make FFT for 3 signals and plot the relation between the Amplitude and the frequency , but actullay I'm not sure about the frequency vector that I write it in the code , is it right ? also how can I determine the range for f ? also always when I run the code , show this msg ( Warning: Imaginary parts of complex X and/or Y arguments ignored )
ps : the number of data in each column is 33034 and the time from 0 - 330.33 ( step .01 )
3 Comments
dpb
on 2 Apr 2020
See the <FFT PSD Example Documentation> sample code for computing the PSD via FFT that illustrates several things including computing the frequency vector to match the sampling frequency and signal length as well as the calculation of a one-sided power spectrum.
In your code, you're plotting the FFT coefficients themselves which are complex and double-sided in frequency; the warning is plot telling you it doesn't know how to handle the imaginary portion of those values.
The FFT coefficients are really of only intermediary use anyways; it's the abs() value that represents the power in the signal that you're interested in and that the example illustrates.
Eva
on 2 Apr 2020
dpb
on 2 Apr 2020
Your code above doesn't reflect any such change so can't judge...in particular the issue regarding which points are part of the frequency spectrum to return and the scaling as shown in the example and discussed at another recent Q? I responded to <Answers/514367-fft-using-excel-data> talks about and show the particular point in the example that isn't included in your code above. As noted in this Q?, if the DC component is small (the signal is zero-mean), then it won't make much difference, but it still isn't precisely correct.
Your code above
time=a(:,1);
...
dt = .01;
...
reads a time vector as the first column but then sets a sample rate externally to 0.01. There's no way to know without the data if those two are commensurate with each other; ergo there's no way to know if you have the right frequency vector or not.
What is the difference between a(2,1)-a(1,1)? Does that match dt? Is your plotted maximum frequency the expected value?
BTW, it would be simpler to code if you would use the original array a and subscript it for the various columns instead of creating independent named variables for each that require duplicating the same code over and over...
Answers (2)
Daniel Frisch
on 31 Aug 2020
0 votes
You can use my little tool easyFFT. It calculates & returns the frequency vector along with the FFT.
Georges Theodosiou
on 13 Oct 2020
0 votes
Lady Eva,
With regards and friendship,
Georges Theodosiou
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!