Plot magnitude of Fourier Tranform in MATLAB (for Continuous time signal)
Вставка
- Опубліковано 15 вер 2024
- Code:-
clc
clear all
close all
t=-2:0.001:2;
xct=cos(2*pi*2*t);
plot(t,xct);
figure;
w=-8*pi:0.01:8*pi;
for i=1:length(w)
xcw(i)=trapz(t,xct.*exp(-1i*w(i).*t));
end
plot(w,abs(xcw));
grid on;
hello, the spikes for cosine signal are not at -2 and 2 right ?
hi, I did the same thing for another function. Here is the code I used; but magnitudes are wrong if extend cont_time from 0:2 to 0:3 . For cont time is in the interval of 0:2, everything works well but cont_time is set as 0:0.001:3, magnitudes are wrong. Could you help ?
clc
clear all
close all
x0=5 ;
x1=20 ;
x2=10 ;
x3=50 ;
f1=5 ;
f2=10 ;
f3=50;
phi_1=0 ;
phi_2=0 ;
phi_3=0 ;
cont_time=0:0.001:2; % Continious Time
cont_signal=x0+x1*sin(2*pi*f1*cont_time+phi_1)+x2*sin(2*pi*f2*cont_time+phi_2)+x3*cos(2*pi*f3*cont_time+phi_3);
%%% Q2 - continuous fourier transform
w=0:0.01:300;
for i=1:length(w)
fourier_cont(i)=trapz(cont_time,cont_signal.*exp(-1i*2*pi*w(i).*cont_time)) ;
end
figure(2)
plot(w,abs(fourier_cont))
How to do it for Discrete time signals?