Error trying to implement a 1-D fast fourier Transform
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Star Strider
2020-11-12
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 个评论
Star Strider
2020-11-12
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.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!