📄 experiment_1_2.m
字号:
%====================================================================
% Program name: experiment_1_2.m for Digital Signal Processing
%====================================================================
clear,close all;
n0=0;n1=20;
n=n0:n1;
x=u(n)-u(n-5);
h=u(n)-u(n-5);%u(n)-u(n-1)+2.5*(u(n-1)-u(n-2))+2.5*(u(n-2)-u(n-3))+(u(n-3)-u(n-4));
%========================================================================
% Compute the convolution of x(n) and h(n)
%========================================================================
y=conv(x,h);
y=y([1:n1+1]);
%========================================================================
% Compute the DTFT of x(n),h(n) and y(n)
%========================================================================
w1=2*pi;
N=512;
k=-N:N;
w=k*w1/N;
X=x*exp(-j*(n)'*w);
X1=abs(X);
H=h*exp(-j*(n)'*w);
H1=abs(H);
Y=y*exp(-j*(n)'*w);
Y1=abs(Y);
%==========================================================================
% Plot the courves
%==========================================================================
subplot(231)
stem(n,x,'.')
axis([0,n1,min(x),max(x)])
title('The input x(n)')
subplot(232)
stem(n,h,'.')
axis([0,n1,min(h),max(h)])
title('The unit impulse response h(n)')
subplot(233)
stem(n,y,'.')
axis([0,n1,min(y),max(y)])
title('The output y(n)')
subplot(234)
plot(w/(2*pi),X1)
axis([-1,1,0,1.2*max(X1)]);
title('The DTFT of x(n)')
xlabel('Frequency/2pi')
grid on;
subplot(235)
plot(w/(2*pi),H1)
axis([-1,1,0,1.2*max(H1)])
title('The DTFT of h(n)')
xlabel('Frequency/2pi')
grid on;
subplot(236)
plot(w/(2*pi),Y1)
axis([-1,1,0,1.2*max(Y1)])
title('The DTFT of y(n)')
xlabel('Frequency/2pi')
grid on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -