?? 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 + -