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)

채택된 답변

Star Strider
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
Onur Dikilitas
Onur Dikilitas 2021년 3월 26일
Okey clearly something is wrong because when I run the code with changes first I thought it works as expected. But when I add plot(Y) at the end I get this figure and it is not look like fft of sine signal.
Star Strider
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 CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by