Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical. Error
43 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Onur Dikilitas
il 26 Mar 2021
Commentato: Star Strider
il 26 Mar 2021
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 Commenti
Risposta accettata
Star Strider
il 26 Mar 2021
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 Commenti
Star Strider
il 26 Mar 2021
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!