【信号与系统 x MATLAB】实验一
信号与系统实验(一)
clear
利用MATLAB实现下列信号,并绘出图形
f = @(t) stepfun(2*t,0)
fplot(@(t)f(t),[-10,10])
f = @(t) 4.*exp(-2.*t).*cos(pi.*t)
fplot(@(t)f(t),[0,10])
f3 = @(t) stepfun(t,-1) - stepfun(t,1) + stepfun(t,-3) - stepfun(t,3)
fplot(@(t)f3(t),[-10,10])
f = @(k) stepfun(k,-3) - stepfun(k,2)
stem(-10:10,f(-10:10))
f = @(k) 5.*(0.4).^k.*cos(1.2.*pi.*k)
stem(-10:10,f(-10:10))
f = @(t) 2.*sin(t./2)./t
fplot(@(t)f(t),[-10,10])
利用MATLAB实现以上信号的变化:
fplot(@(t)f3(0.5.*t),[-10,10]) %1
T = -10:0.1:10;
F = arrayfun(@(t)f3(2-2.*t),T);
plot(T,F) %2
df3 = diff(F);
plot(-10:0.1:10-0.1,df3) %3
傅里叶变换
T = 0:0.01:10;
plot(T,ff(T,1))
hold on
plot(T,ff(T,2))
plot(T,ff(T,200))
hold off
legend("n=1","n=2","n=200")
function s = ff(t,k)
s = zeros(1,length(t));
for i = 1:k
s = s + sin((2.*i-1).*t)./(2.*i-1);
end
end