📄 ctfs_tr.m
字号:
%========================================================================
clear,close all
t1=input('Type in the time range:');
p=0.01;
t=-t1:p:t1;
T=input('Type in the period T=:');
Nf=input('Type in the number of the harmonic components');
x=input('Type in the expression of the signal f(t):');
for r=1:Nf;
an(r)=(2/T)*x*cos((r*2*pi/T)*t')*p;
bn(r)=(2/T)*x*sin((r*2*pi/T)*t')*p;
end
a0=(1/T)*x*ones(1,length(t))'*p;
y=a0;
for q=1:Nf;
y=y+an(q)*cos(q*2*pi*t/T)+bn(q)*sin(q*2*pi*t/T);
end;
An=zeros(1,length(an)+1);
cn=sqrt(an.^2+bn.^2);
An=[a0 cn];
fi=-atan(bn./an);
fi=[0 fi];
clf
subplot(211)
plot(t,y,'r');hold on;
%plot(t,f);
title('Approximation of aperiodic signal')
subplot(212)
n=0:Nf;
stem(n,An,'k.');title('The amplitude spectrum of a periodic signal')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -