FFT on time series error message

1 view (last 30 days)
Jesse Dawson
Jesse Dawson on 20 Apr 2018
Answered: Walter Roberson on 20 Apr 2018
Im attempting to run a FFT for a time series I created, however I keep getting an error message saying invalid data type. What am I doing wrong? Thanks.
T=1 %delta t
L=64 %length of vector
t=0:T:L-1
for i=1:L
if t(i)==8
y(i)=1
else y(i)=0
end
end
plot(t,y)
Y = fft(y);

Answers (1)

Walter Roberson
Walter Roberson on 20 Apr 2018

? You do not show a timeseries ?

fft() cannot be done directly on a timeseries object.

If the times are regular intervals the extract the Data property from the timeseries and fft() that; if you end up plotting that then you can use the Time property of the timeseries to figure out delta-time to figure out sampling frequency.

If the times are not regular intervals then there are no Mathworks-provided routines to do the calculations, but you can see https://www.mathworks.com/matlabcentral/fileexchange/25135-nufft--nfft--usfft NUFFT from the File Exchange

Categories

Find more on Fourier Analysis and Filtering 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!