Error trying to implement a 1-D fast fourier Transform

2 views (last 30 days)
Im trying to get a 1D fft from a signal and keep getting this error saying:
"Error using fft
Invalid data type. First argument must be double, single, int8, uint8, int16,
uint16, int32, uint32, or logical."
This is my script:
___________________________________
A = 7;
P = 100;
M = 15;
t = 0:1:sym(P); % Signal duration/length
fncT = (A.^t) - floor(A.^t/M)*M;
plot(t,fncT)
title('1')
xlabel('2')
ylabel('4')
Fs = 1000; % Sampling freq
Ts = 1/Fs; % Sampling period of time step
L = length(fncT); % The length of the domain signal
sig_FFT = fft(fncT,L)/L;
amplitude = 2*abs(sig_FFT(1:L/2+1));
frequency = Fs/2*2linspace(0,1,L/L2+1);
figure;
plot(Frequency,amplitude));
_________________________________________
How do I solve this issue?

Answers (1)

Star Strider
Star Strider on 12 Nov 2020
After a fair amount of editing (please proofread your code), this works:
A = 7;
P = 100;
M = 15;
t = 0:1:sym(P); % Signal duration/length
fncT = (A.^t) - floor(A.^t/M)*M;
plot(t,fncT)
title('1')
xlabel('2')
ylabel('4')
Fs = 1000; % Sampling freq
Ts = 1/Fs; % Sampling period of time step
L = length(fncT); % The length of the domain signal
sig_FFT = fft(double(fncT),L)/L;
amplitude = 2*abs(sig_FFT(1:fix(L/2)+1));
frequency = Fs/2*linspace(0,1,fix(L/2)+1);
figure;
plot(frequency,amplitude);
Note the changes required for it to run with out error.
  3 Comments
Star Strider
Star Strider on 12 Nov 2020
My pleasure!
The fix function rounds its arguments toward 0, producing integer outputs. (The floor function rounds them toward -Inf, the ceil function rounds them toward +Inf, both producing integer outputs, and the round function rounds to the nearest integer, unless other arguments are included. They are all linked to in the fix documentation, so I do not specfically link to the m here.)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!