Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical. Error
조회 수: 96 (최근 30일)
이전 댓글 표시
So I am trying to understand fast fourier transformation on matlab but when I use Y=fft(y) comand I take the invalid data type error and I have no idea neither why I am taking that error or how do solve it?
syms t
A = 2;
w = 2*pi;
phi = 5;
T = (2*pi)/w % fundamental period
y = A*sin(w*t + phi)
fplot(y, [0 3]);
title('Simulation of harmonic function');
xlabel('t[s]');
ylabel('U[mV]');
%mean value
mean_value = (1/T)*int(y,t,0,T)
%power
syms T
temp = 1/(2*T)*int(y^2,-T,T);
power = limit(temp,T, inf)
%energy
temp = int(y^2,-T,T);
energy = limit(temp,T, inf)
%Fast Fourier Tranform
Y = fft(y)
댓글 수: 0
채택된 답변
Star Strider
2021년 3월 26일
Since ‘y’ is a symbolic expression, it is not an appropirate argument for fft.
However, all is not lost! First, get the ‘x’ and ‘y’ data from the fplot call:
hfp = fplot(y, [0 3]);
xv = hfp.XData;
yv = hfp.YData;
then call fft with ‘yv’:
Y = fft(yv);
and the code runs as expected.
댓글 수: 4
Star Strider
2021년 3월 26일
The output of fft is a symmetrical complex vector.
Try this:
%Fast Fourier Tranform
Ts = 1/mean(diff(xv)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(xv); % Signal Length
Y = fft(yv)/L; % Fouriet Transform (Normalised)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(Y(Iv))*2)
grid
xlabel('Frequency')
ylabel('Amplitude')
xlim([0 1.5]*1E-3) % Optional
That should do what you want.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!