Error trying to implement a 1-D fast fourier Transform

1 vue (au cours des 30 derniers jours)
Prayash Thapa
Prayash Thapa le 12 Nov 2020
Commenté : Star Strider le 12 Nov 2020
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?

Réponses (1)

Star Strider
Star Strider le 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 commentaires
Prayash Thapa
Prayash Thapa le 12 Nov 2020
What does fix() do?
Star Strider
Star Strider le 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.)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by