Error trying to implement a 1-D fast fourier Transform
이전 댓글 표시
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?
답변 (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
Prayash Thapa
2020년 11월 12일
Prayash Thapa
2020년 11월 12일
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.)
카테고리
도움말 센터 및 File Exchange에서 Fast Fourier Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!