Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical. Error
43 次查看(过去 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 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!