Error trying to implement a 1-D fast fourier Transform

1 回表示 (過去 30 日間)
Prayash Thapa
Prayash Thapa 2020 年 11 月 12 日
コメント済み: Star Strider 2020 年 11 月 12 日
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
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
Prayash Thapa 2020 年 11 月 12 日
What does fix() do?
Star Strider
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 ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by