信号与系统实验答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

信号与系统实验答案
% Q1_2
clear, % Clear all variables
close all, % Close all figure windows
dt = 0.01; % Specify the step of time variable t = 0:dt:2; % Specify the interval of time x = exp(-2*t); % Generate the signal
plot(t,x) % Open a figure window and draw the plot of x(t)
title('Sinusoidal signal x(t)')
xlabel('Time t (sec)')
axis([0,2,0,5])
grid on
>> % Q1_3
clear, % Clear all variables
close all, % Close all figure windows
dt = 0.01; % Specify the step of time variable
t = 0:dt:2; % Specify the interval of time
x = input('请输⼊任意信号x(t)'); % Generate the signal
grid on
plot(t,x) % Open a figure window and draw the plot of x(t)
title('Sinusoidal signal x(t)')
xlabel('Time t (sec)')
请输⼊任意信号x(t)exp(-2*t)
Q1-4抄写函数⽂件delta如下:function y = delta(t)
dt = 0.01;
y = (u(t)-u(t-dt))/dt;
抄写函数⽂件u如下:% Unit step function
function y = u(t)
y = (t>=0); % y = 1 for t > 0, else y = 0
%Q1_5
clear, % Clear all variables
close all, % Close all figure windows
n = -5:5; % Specify the interval of time
x = [zeros(1,4), 0.1, 1.1, -1.2, 0, 1.3, zeros(1,2)]; % Generate the sequence
stem (n,x,'.') % Open a figure window and draw the plot of x[n] grid on,
axis([-2,5,-1.5,1.5])
%Q1_6
clear, % Clear all variables
close all, % Close all figure windows
n = -5:5; % Specify the interval of time
x =0.5.^abs(n); % Generate the sequence
t=-2:0.01:5;
y=cos(2*pi*t).*[u(t)-u(t-3)];
subplot(2,1,1),stem (n,x,'.') ; % Open a figure window and draw the plot of x[n] grid on; title ('A discrete-time sequence x[n]')
xlabel ('Time index n')
subplot(2,1,2),plot (t,y) ;
% Q1_7
clear, % Clear all variables
close all, % Close all figure windows
dt = 0.01; % Specify the step of time variable
t = -5:dt:5; % Specify the interval of time
x = exp(-0.5*t).*u(t); % Generate the signal
y=exp(-0.75*t-1.5).*u(1.5*t+3);
subplot(2,1,1),plot(t,x); % Open a figure window and draw the plot of x(t) grid on;
title('Sinusoidal signal x(t)');
xlabel('Time t (sec)');
subplot(2,1,2),plot(t,y);
grid on;
title('Sinusoidal signal y(t)');
xlabel('Time t (sec)');
% Q1_8
clear,close all,
n = -20:20;
x = u(n)-u(n-8); % Generate the original signal x(t)
x1 = u(n+6)-u(n-2); % Shift x(t) to the left by 2 second to get x1(t)
x2 = u(n-6)-u(n-14); % Shift x(t) to the right by 2 second to get x2(t)
subplot(311),
stem(n,x); % Plot x(t)
grid on;
title ('Original signal x(n)');
subplot (312),
stem (n,x1); % Plot x1(t)
grid on;
title ('Left shifted version of x(n)');
subplot (313),
stem (n,x2); % Plot x2(t)
grid on;
title ('Right shifted version of x(n)');
xlabel ('Index n ');
% Q1_9
clear, close all;
dt=0.01;
t = -5:0.01:5;
x = input('Type in the expression of the input signal x(t):');
h = input('Type in the expression of the input signal h(t):');
r=dt*conv(x,h);
subplot(221), plot(t,x),title('x(t)');
subplot(223), plot(t,h),title('h(t)');
subplot(122),
t = -10:0.01:10;
plot(t,r); title('r(t)');
% Q1_10
clear;close all;
n0 = -2; n1 = 10;
n = n0:n1;
x = 0.5.^n.*[u(n)-u(n-8)];
h = u(n)-u(n-8);
y = conv(x,h); % Compute the convolution of x(t) and h(t) subplot(311)
stem(n,x), grid on, title('Signal x(n)'), axis([n0,n1,-0.2,1.2]) subplot(312)
stem(n,h), grid on, title('Signal h(n)'), axis([n0,n1,-0.2,1.2]) subplot(313)
n = 2*n0:2*n1; % Again specify the time range to be suitable to the % convolution of x and h.
stem(n,y), grid on, title('The convolution of x(n) and h(n)'),
xlabel('Index n')
编写的程序Q1_11如下:
clear, close all;
n = -20:20;
x=n.*[u(n)-u(n-4)];
N = 8; y = 0;
for k = -2:2;
y =y+(n-k*N).*[u(n-k*N)-u(n-k*N-4)];
end
subplot(211),stem(n,x); grid on, title('Signal x(n)'),
subplot(212),stem(n,y); grid on, title('Signal y(n)'),
% Q3_1
b = input('请输⼊右边向量系数'); % The coefficient vector of the right side of the differential equation
a = input('请输⼊左边向量系数'); % The coefficient vector of the left side of the differential equation
[H,w] = freqs(b,a); % Compute the frequency response H
Hm = abs(H); % Compute the magnitude response Hm
phai = angle(H); % Compute the phase response phai
Hr = real(H); % Compute the real part of the frequency response Hi = imag(H); % Compute the imaginary part of the frequency response
subplot(221)
plot(w,Hm), grid on, title('Magnitude response'), xlabel('Frequency in rad/sec')
subplot(223)
plot(w,phai), grid on, title('Phase response'), xlabel('Frequency in rad/sec')
subplot(222)
plot(w,Hr), grid on, title('Real part of frequency response'),
xlabel('Frequency in rad/sec')
subplot(224)
plot(w,Hi), grid on, title('Imaginary part of frequency response'), xlabel('Frequency in rad/sec')
% Q3_2
b = input('Type in the right coefficient vector of differential equation:'); % The coefficient vector of the right side of the differential equation
a = input('Type in the left coefficient vector of differential equation:'); % The coefficient vector of the left side of the differential equation
w=-10:0.01:10;
H= freqs(b,a,w); % Compute the frequency response H
Hm = abs(H); % Compute the magnitude response Hm
phai = angle(H); % Compute the phase response phai
Hr = real(H); % Compute the real part of the frequency response
Hi = imag(H); % Compute the imaginary part of the frequency response
subplot(221);
plot(w,Hm); grid on, title('Magnitude response'), xlabel('Frequency in rad/sec');
subplot(223);
plot(w,phai); grid on, title('Phase response'), xlabel('Frequency in rad/sec');
subplot(222);
plot(w,Hr); grid on, title('Real part of frequency response');
xlabel('Frequency in rad/sec');
subplot(224);
plot(w,Hi); grid on, title('Imaginary part of frequency response');
xlabel('Frequency in rad/sec');
% Q3_3
b1 = input('Type in the right coefficient vector of differential equation:'); % The coefficient vector of the right side of the differential equation
a1= input('Type in the left coefficient vector of differential equation:'); % The coefficient vector of the left side of the differential equation
b2 = input('Type in the right coefficient vector of differential equation:'); % The coefficient vector of the right side of the differential equation
a2= input('Type in the left coefficient vector of differential equation:'); % The coefficient vector of the left side of the differential equation
b3 = input('Type in the right coefficient vector of differential equation:'); % The coefficient vector of the right side of the differential equation
a3= input('Type in the left coefficient vector of differential equation:'); % The coefficient vector of the left side of the differential equation
w=-10:0.01:10;
H1 = freqs(b1,a1,w); % Compute the frequency response H
phi1 = angle(H1);
H2 = freqs(b2,a2,w); % Compute the frequency response H
phi2 = angle(H2);
H3 = freqs(b3,a3,w); % Compute the frequency response H
phi3 = angle(H3);
tao1= grpdelay(b1,a1,w);
tao2= grpdelay(b2,a2,w);
tao3= grpdelay(b3,a3,w);
subplot(321);
plot(w,phi1); grid on, title('Phase response of num1');
subplot(323);
plot(w,phi2); grid on, title('Phase response of num2');
subplot(325);
plot(w,phi3); grid on, title('Phase response of num3'), xlabel('Frequency in rad/sec'); subplot(322);
plot(w,tao1); grid on, title('Group delay of num1');
subplot(324);
plot(w,tao2); grid on, title('Group delay of num2');
subplot(326);
plot(w,tao3); grid on, title('Group delay of num3'); xlabel('Frequency in rad/sec');。

相关文档
最新文档