第 1 章 信号变换与运算1.1 常用信号1.2 信号变换1.3 信号分解第 2 章 连续时域分析2.1 系统响应2.2 函数卷积第 3 章 连续频域分析3.1 周期信号的频谱3.2 非周期信号的频谱3.3 傅里叶变换的性质3.4 信号的采样过程3.5 系统的频率特性第 4 章 连续复频域分析4.0 复频域常用函数4.1 拉普拉斯变换4.2 与傅氏变换关系4.3 拉普拉斯逆变换4.4 系统函数零极点图4.5 系统的复频域分析4.6 系统的频率响应图第 5 章 离散时域分析5.1 离散时间信号的图像5.2 离散时间信号的运算5.3 系统的单位样值响应5.4 离散时间序列的卷积5.5 离散时间系统的响应
x1% 几种典型信号2% matlab 相比于 "傻瓜绘图软件",3% 优点: 代码可以复用, 函数种类众多.4% 缺点: 软件启动较慢, 操作相对繁琐.5
6% 1 指数7% 1.1 指数信号8t = -2 : 0.1 : 10;9ft = 2 * exp(-0.4*t);10plot(t, ft)11title('1.1 指数信号')12
13% 1.2 单边指数信号14t = -2 : 0.1 : 10;15ft = 2 * exp(-0.4*t) .* heaviside(t);16% 注意是点乘; heaviside(t) 是单位阶跃函数 (也可以当成示性函数使用)17% heaviside(t) 即 (t>0)18plot(t, ft)19title('1.2 单边指数信号')20
21% 1.3 复指数信号22t = 0 : 0.01 : 3;23z = exp((-1+10j)*t);24% 无定义时, i 和 j 都表示虚数单位, 并且与实数相乘无需写乘号25subplot 221, plot(t, real(z)), title('实部')26subplot 223, plot(t, imag(z)), title('虚部')27subplot 222, plot(t, abs(z)), title('模')28subplot 224, plot(t, angle(z)), title('相角')29% 第一次知道 subplot、plot 和 title 可以写在一行30
31
32
33% 2 正弦34% 2.1 正弦信号35t = 0 : 0.01 : 8;36ft = 1 * sin(2*pi*t + pi/6);37plot(t, ft)38title('2.1 正弦信号')39
40% 2.2 衰减正弦信号41t = 0 : 0.01 : 8;42ft = exp(-0.5*t) .* sin(2*pi*t + pi/6);43plot(t, ft)44title('2.2 衰减正弦信号')45
46% 2.3 抽样信号47t = -32 : 0.1 : 32;48ft = sin(t) ./ t;49plot(t, ft)50title('2.3 抽样信号')51
52% 2.4 辛格函数53t = -10 : 0.1 : 10;54ft = sin(pi*t) ./ (pi*t);55plot(t, ft)56title('2.4 辛格函数')57
58
59
60% 3 钟形信号61t = -5 : 0.1 : 5;62sigma = 1;63ft = exp(-t.^2 / (2*sigma^2)) / (sqrt(2*pi) * sigma);64plot(t, ft)65title('3 钟形信号')66
67
68
69% 4 奇异信号70% 4.1 单位斜边信号71t = -1 : 0.1 : 5;72ft = t .* heaviside(t);73plot(t, ft)74title('4.1 单位斜变信号')75
76% 4.2 单位阶跃信号77t = -1 : 0.001 : 3; % 间隔小了, 精度会低78ft = heaviside(t);79plot(t, ft)80axis([-1, 3, -0.1, 1.2])81title('4.2 单位阶跃信号')82
83% 4.3 单位冲激信号84t1 = -1; t2 = 5; % 信号起止时刻85t0 = 0; % 信号平移量86dt = 0.01; % 信号间隔时间87t = -1 : dt : 5;88x = zeros(1, length(t));89x(1, (-t0 - t1)/dt + 1) = 1 / dt;90stairs(t, x);91axis([t1, t2, 0, 1.2/dt])92title('4.3 单位冲激信号')93
94% 4.4 矩形脉冲信号95t = 0 : 0.001 : 4;96T = 1;97ft = rectpuls(t-2*T, 2*T);98% 其中 t-2*T 表示中心位置在 2*T99% 第二个参数表示矩形的宽度100plot(t, ft);101grid on102axis([0, 4, -0.5, 1.5])103
104% 4.5 周期性三角波脉冲信号105t = -5*pi : pi/10 : 5*pi;106ft = sawtooth(t, 0.3);107% 直译锯齿; 周期为 2*pi.108% 第二个参数 r 属于 [0, 1], 表示在 r * 2pi 处取得最大值.109plot(t, ft)110axis([-16, 16, -1.5, 1.5])111grid on
xxxxxxxxxx171% 信号的运算2% 时移、反褶、尺度变换,可通过 y = subs(f, t, a*t - t_0) 实现3% 不建议使用 ezplot, 可替换为 fplot4% 如果不能使用 sym(), 可以直接输入引号内的符号表达式5syms t;6f1 = (4-t) * (heaviside(t) - heaviside(t-4));7f2 = sin(2*pi*t);8f3 = subs(f1, t, -t) + f1;9f4 = -f3;10f5 = f2 * f3;11f6 = f1 * f2;12subplot 321, fplot(f1), title('f1(t)')13subplot 322, fplot(f2), title('f2(t)')14subplot 323, fplot(f3), title('f1(-t) + f1(t)')15subplot 324, fplot(f4), title('-f1(-t) - f1(t)')16subplot 325, fplot(f5), title('f2(t) * f3(t)')17subplot 326, fplot(f6), title('f1(t) * f2(t)')
xxxxxxxxxx401% 连续信号的分解2% 1 分解为直流分量和交流分量3% 符号函数不便于求均值4t = -2*pi : 0.01 : 2*pi;5ft = 1 + sin(t);6fd = mean(ft) * ones(1, length(t));7fa = ft - fd;8subplot 221, plot(t, ft), title('f(t)')9subplot 223, plot(t, fd), title('fd(t)')10subplot 224, plot(t, fa), title('fa(t)')11sgtitle('分解为直流分量和交流分量')12
13% 2 分解为奇分量和偶分量14syms t15ft = real((1 - (t - 1).^2) .^ 0.5);16fodd = real((ft - subs(ft, t, -t)) / 2);17feven = real((ft + subs(ft, t, -t)) / 2);18% 上述 real() 是必要的19subplot 221, fplot(ft), title('f(t)')20axis equal21axis([-2, 2, -1, 2])22subplot 223, fplot(fodd), title('fodd(t)')23axis equal24axis([-2, 2, -1, 2])25subplot 224, fplot(feven), title('feven(t)')26axis equal27axis([-2, 2, -1, 2])28% 受不了, 每次都要重新设置, 这么写代码太笨了29sgtitle('分解为奇分量和偶分量')30
31% 3 分解为脉冲分量32% 3.1 冲激信号33% 3.2 阶跃信号34% 这两个其实是把信号用积分的形式写了出来, 图像上没有差异35
36% 4 分解为实分量与虚分量37% 见 c1_signal.m 中的复指数信号部分, 那里已经画过了38
39% 5 分解为正交函数分量40% 由于会分解出无穷多个正交函数, 不方便全部展示, 也不画了
xxxxxxxxxx121% 连续时间系统的响应2% 以 2 y''(t) + y'(t) + 8 y(t) = f(t) 为例,3% 其中 f(t) 为冲激信号或阶跃信号.4% 只有单个元素的矩阵不建议使用方括号.5subplot 131, impulse(1, [2 1 8]), title('单位冲激信号')6subplot 132, step(1, [2 1 8]), title('单位阶跃信号')7
8% 对于 y''(t) + 2 y'(t) + y(t) = f'(t) + 2 f(t),9% 其中 f(t) = 5 e^(-2 t) u(t), 可以使用如下函数10t = 0 : 0.01 : 5;11f = 5 * exp(-2*t);12subplot 133, lsim([1 2], [1 2 1], f, t), title('一般信号')
同目录下 sconv.m 的内容:
xxxxxxxxxx181function [f, k] = sconv(f1, f2, k1, k2, p, isplot)2% 计算连续信号的卷积积分 f(t) = f1(t) * f2(t)3% k1 和 k2 分别是 f1 和 f2 的取样时刻4% p 为取样时间间隔5% plot 表示是否绘图6f = conv(f1, f2);7k0 = k1(1) + k2(1);8klen = length(k1) + length(k2) - 2;9k = k0 : p : (k0 + klen*p);10
11if nargin == 6 && isplot ~= 012 subplot 221, plot(k1, f1), title('f1(t)')13 subplot 222, plot(k2, f2), title('f2(t)')14 subplot 223, plot(k, f), title('f(t) = f1(t) * f2(t)')15 h = get(gca, 'position');16 h(3) = 2.32 * h(3);17 set(gca, 'position', h)18end具体的实例:
xxxxxxxxxx271% 连续时间信号的卷积积分2% 离散的可直接使用 conv(u, v)3% 连续的可取样后使用上述函数4
5% 例 2.16: t * I_{0 <= t <= 2} 与自身卷积6% 这里使用自己编写的 sconv 实现7p = 0.005;8k1 = 0 : p : 2;9f1 = 0.5 * k1;10[f, k] = sconv(f1, f1, k1, k1, p, true);11
12% 例 2.1713% 道理是一样的, 这里就不写了; 不过用 mathematica 写了.14
15% 例 2.18: I_{-1 <= t <= 1} 和 I_{0 <= t <= 1} 的卷积16% 这里不用 sconv, 而只使用其中部分代码17T = 0.01; % 采样周期18n1 = -100 : 100;19f1 = ones(1, length(n1));20n2 = 0 : 100;21f2 = ones(1, length(n2));22y = T * conv(f1, f2);23n3 = n1(1) + n2(1) : n1(end) + n2(end);24plot(n3*T, y);25grid on;26xlabel('t/s');27ylabel('y(t)');
xxxxxxxxxx341% 3.1 周期信号的频谱2
3% 例 3.13: 周期矩形脉冲信号的双边频谱4syms t n % T, A 和 tau 不需要用 syms 声明, 因为下面直接赋值了5T = 4; A = 1; tau = 1;6
7f = A * exp(-1j * 2*n*pi/T * t); % 计算傅里叶级数时乘的函数8fn = int(f, t, -tau/2, tau/2) / T; % 指数形式的傅里叶系数9% fn = simple(fn); % 书中说是用于化简10% 但是这个函数用不了, 甚至在官网都搜不到这个函数...不过也不需要用11
12n = [-20:-1, eps, 1:20];13evalfn = subs(fn, 'n', n); % 书中参数写反了...14
15subplot 211, stem(n, evalfn, 'filled'), title('周期矩形脉冲的频谱');16subplot 212, stem(n, abs(evalfn), 'filled'), title('幅度谱');17
18
19
20% 例 3.14: 周期三角波信号的双边频谱21N = 10;22n1 = -N : -1; % 小于 0 时的系数记为 c123c1 = -4j * sin(n1*pi/2) / pi^2 ./ n1.^2;24c0 = 0; % 等于 0 时的系数为 025n2 = 1 : N; % 大于 0 时的系数记为 c226c2 = -4j * sin(n2*pi/2) / pi^2 ./ n2.^2;27
28cn = [c1, c0, c2]; % 傅里叶余弦级数系数29n = -N : N;30subplot 211, stem(n, abs(cn));31xlabel('\omega/\omega_0'); ylabel('C_n 的幅度');32subplot 212, stem(n, angle(cn));33xlabel('\omega/\omega_0'); ylabel('C_n 的相位');34
xxxxxxxxxx251% 3.2 非周期信号的频谱2
3% 例 3.15: 单边指数信号的频谱 (符号计算)4syms t5f = exp(-2*t) * heaviside(t);6F = fourier(f);7subplot 211, fplot(abs(F)), grid on, title('幅频特性图')8subplot 212, fplot(angle(F)), grid on, title('相频特性图')9
10% 例 3.16: 门信号的频谱图 (数值计算)11R = 0.02; % 采样间隔12t = -2 : R : 2; % 采样时间点13N = 500; % 样本容量14w = (0 : N)/N * (10*pi); % 非负抽样点15W = [-fliplr(w), w(2:N+1)]; % 全部抽样点16
17f = heaviside(t+1) - heaviside(t-1); % 门函数18F = f * exp(-1j*t'*w) * R; % 非负抽样点19F = [fliplr(F), F(2:N+1)]; % 全部抽样点20
21subplot 211, plot(t, f, 'r');22xlabel('t'), ylabel('f(t)'), title('门函数 f(t)');23subplot 212, plot(W, real(F), 'b'); % 虽然 F 是实数, 但还是建议加上 real();24xlabel('w'), ylabel('F(w)'), title('傅里叶变换 F(w)');25
xxxxxxxxxx211% 3.4 信号的采样过程2% 例 3.19: 三角波的采样过程3syms t w f4f = (1 - 2*abs(t)) * exp(-1j * w * t); % 被积函数5F = int(f, t, -1/2, 1/2); % 指数形式的傅里叶系数6
7% 注意 fplot 第二个参数是二维向量, 而非采样点8subplot 311, fplot(abs(F), [-26*pi, 26*pi]), title('三角波的频谱');9axis([-26*pi, 26*pi, -0.1, 0.5]);10subplot 312, fplot(abs(F), [-4*pi, 4*pi]), title('低通滤波后的频谱');11axis([-26*pi, 26*pi, -0.1, 0.5]);12
13subplot 313, title('采样后的频谱'), hold on;14Ts = 0.2; % 采样信号的周期15w0 = 2*pi / Ts; % 频谱的周期延拓16for k = -2 : 217 ft = f * exp(-1j*w0*k*t);18 FT = int(ft, t, -1/2, 1/2);19 fplot(abs(FT)/Ts, [-4*pi-k*w0, 4*pi-k*w0]);20end21
xxxxxxxxxx241% 3.5 系统的频率特性2
3% 例 3.20: 低通滤波器的频率响应4b = [0, 0, 1];5a = [0.08, 0.4, 1];6[h, w] = freqs(b, a, 100);7% 第三个参数为频率向量的频率点数 (默认为 200)8h1 = abs(h);9h2 = angle(h);10subplot 211, plot(w, h1), grid on;11xlabel('角频率 \omega'), ylabel('幅度'), title('幅频特性');12subplot 212, plot(w, h2*180/pi), grid on;13xlabel('角频率 \omega'), ylabel('相位 / 度'), title('相频特性');14
15% 例 3.21: 某连续 LTI 系统的微分方程16w = -2*pi : 0.1 : 2*pi;17b = [10, 5];18a = [1, 10, 8, 5];19H = freqs(b, a, w);20subplot 211, plot(w, abs(H)), title('幅频特性'), grid on;21xlabel('\omega(rad/s)'), ylabel('|H(j\omega)|');22subplot 212, plot(w, angle(H)), title('相频特性'), grid on;23xlabel('\omega(rad/s)'), ylabel('\phi(\omega)');24
| 函数 | 功能 | 函数 | 功能 |
|---|---|---|---|
| laplace | 拉氏变换 | ilaplace | 拉氏逆变换 |
| residue | 部分分式展开法 | zero | 计算系统的零点 |
| pole | 计算系统的极点 | pzmap | 绘制零极点图 |
| zp2tf | 零极点 -> 系统函数 | tf2zp | 系统函数 -> 零、极点 |
| freqs | 计算频率响应特性 | pause | 暂停运行 |
xxxxxxxxxx391% 4.1 拉普拉斯变换2% 例 4.27:两个信号的拉普拉斯变换3syms t w4% (1)5f1 = exp(-t) * cos(w*t);6F1 = laplace(f1);7% (2)8f2 = 3 * exp(-2*t);9F2 = laplace(f2);10
11
12
13% 例 4.28:绘制拉普拉斯变换的图形14syms t s15f = sin(t) * heaviside(t);16F = laplace(f);17% 得出 F = 1 / (s^2 + 1)18
19% 以下绘图代码可单独运行20% 绘制方法一:符号数学方法绘图21syms s x y22s = x + 1i*y; % 虚数单位建议写为 1i 而非 i23Fs = 1 / (s^2+1); % 注意这里要重新赋值为复变函数,因为要令 s = x + 1i * y24subplot 121, fmesh(abs(Fs)); % 网格曲面图;不建议使用 ezmesh()25subplot 122, fsurf(abs(Fs)); % 三维曲面图;不建议使用 ezsurf()26colormap(hsv); % 设置图形中多条曲线的颜色顺序27
28% 绘制方法二:数值方法绘图29figure(2)30x1 = -5 : 0.1 : 5;31y1 = -5 : 0.1 : 5;32[x, y] = meshgrid(x1, y1); % 产生网格矩阵 x, y33s = x + 1i*y;34Fs = 1 ./ (s.*s + 1);35subplot 121, mesh(x, y, abs(Fs));36subplot 122, surf(x, y, abs(Fs));37axis([-5, 5, -5, 5, 0, 8]);38colormap(hsv);39
xxxxxxxxxx501% 4.2 傅氏变换与拉氏变换的关系2% 例 4.29 法一:符号绘图3clf; % clear figure4syms x y s5s = x + 1i*y;6Fs = 1 ./ ((s+1)^2 + 1);7
8subplot 231, fmesh(abs(Fs));9view(-60, 20); % 调整观察视角10axis([0, 5, -20, 20, 0, 0.5]);11title('拉氏变换网格图')12
13subplot 232, fsurf(abs(Fs));14view(-60, 20); % 调整观察视角15axis([0, 5, -20, 20, 0, 0.5]);16title('拉氏变换曲面图')17colormap(hsv);18
19syms w20Fw = 1 ./ ((1i*w + 1)^2 + 1);21subplot 233, fplot(abs(Fw), [-20, 20]);22xlabel('频率 w')23title('傅氏变换幅频曲线')24
25
26
27% 例 4.29 法二:数值绘图28x1 = 0 : 0.1 : 5;29y1 = -20 : 0.1 : 20;30[x, y] = meshgrid(x1, y1);31s = x + 1i*y;32Fs = 1 ./ ((s+1).^2 + 1);33
34subplot 234, mesh(x, y, abs(Fs));35view(-60, 20); % 调整观察视角36axis([0, 5, -20, 20, 0, 0.5]);37title('拉氏变换网格图')38
39subplot 235, surf(x, y, abs(Fs));40view(-60, 20); % 调整观察视角41axis([0, 5, -20, 20, 0, 0.5]);42title('拉氏变换曲面图')43colormap(hsv);44
45w = -20 : 0.1 : 20;46Fw = 1 ./ ((1i*w + 1).^2 + 1);47subplot 236, plot(w, abs(Fw));48xlabel('频率 w')49title('傅氏变换幅频曲线')50
xxxxxxxxxx161% 4.3 拉普拉斯逆变换2% 例 4.30:利用部分分式法进行拉普拉斯逆变换3a = conv([1, 0], [1, 1]); % 分母的多项式系数4b = conv([1, 1], [1, 1]); % 分子的多项式系数5den = conv(a, b);6[r, p] = residue([1, -2], den);7
8% 例 4.31:利用内置函数直接求拉普拉斯逆变换9syms s10% (1)11F1 = (2*s + 1) / (s^2 + 7*s + 10);12f1 = ilaplace(F1);13% (2)14F2 = s^2 / (s^2 + 3*s + 2);15f2 = ilaplace(F2);16
xxxxxxxxxx351% 4.4 系统函数的零、极点图2% 例 4.32:绘制零、极点图3b = [1, -1];4a = [1, 2, 2];5zs = roots(b); % zeros6ps = roots(a); % poles7plot(real(zs), imag(zs), 'o'); hold on;8plot(real(ps), imag(ps), 'rx', 'markersize', 12);9axis([-2, 2, -2, 2]); grid on;10legend('零点', '极点')11
12% 第五次翻转课堂练习题 2.613z_real = [0, 1, 1];14z_imag = [0, -1, 1];15p_real = [-1, -1, 0, 0];16p_imag = [0, 0, -2, 2];17plot(z_real, z_imag, 'o'); hold on;18plot(p_real, p_imag, 'rx', 'markersize', 12);19axis([-3, 3, -3, 3]);20grid on;21legend('零点', '极点')22
23% 零极点的另一种画法:24H = tf([2 5 1], [1 3 5]);25pzmap(H)26grid on27
28pzmap(sys(:,:,1),'r',sys(:,:,2),'g',sys(:,:,3),'b')29sgrid30
31sys = tf([4.2,0.25,-0.004],[1,9.6,17]);32[p,z] = pzmap(sys);33plot(real(z), imag(z), 'o'); hold on;34plot(real(p), imag(p), 'rx', 'markersize', 12);35
xxxxxxxxxx381% 4.5 复频域分析2% 例 4.33:冲激响应的时域波形3% 备注:与微分算子、傅里叶变换那里的冲激响应使用函数相同4a = [1, 1, 16.25];5b = 1; % 等价于 [1]6impulse(b, a, 5);7title('Impulse Response');8xlabel('Time');9ylabel('Amplitude');10
11
12
13% 例 4.34:零输入响应、零状态响应、全响应14% 首先对微分方程两端使用拉普拉斯变换,代入初值条件后化简,15syms t s16Yzi = (3*s + 13) / (s^2 + 3*s + 2); % 复频域 - 零输入响应17yzi = ilaplace(Yzi); % 时域 - 零输入响应18
19ft = 4 * exp(-2*t) * heaviside(t); % 时域 - 激励信号20Fs = laplace(ft); % 复频域 - 激励信号21
22Yzs = Fs / (s^2 + 3*s + 2); % 复频域 - 零状态响应23yzs = ilaplace(Yzs); % 时域 - 零状态响应24
25yt = simplify(yzi + yzs); % 时域 - 全响应26
27
28
29% 例 4.35:给定电路,用拉普拉斯变换求电流响应30sys = tf(1, [0.1, 0.1]); % 系统函数 H(s)31t = [0 : 0.01 : 10]'; % 抽样时间32e = sin(3*t); % 激励信号33i = lsim(sys, e, t); % 仿真电流信号34plot(t, e, '-.', t, i); % 绘制激励和电流35xlabel('Time (sec)');36axis([0, 10, -4, 6]);37legend('e(t)', 'i(t)');38
xxxxxxxxxx251% 4.6 频率响应2% 例 4.36:系统函数的幅频特性和相频特性3b = 1; % 分子系数4a = [1, 0.4, 0.08]; % 分母系数5w = linspace(-pi, pi); % 书中的 2*pi<512 疑似打错6h = freqs(b, a, w); % 频率响应7subplot 211, plot(w, abs(h)); % 幅频特性曲线8subplot 212, plot(w, angle(h)); % 相频特性曲线9
10% 例 4.37:根据零极点分布画出幅频特性曲线11data = struct(...12 'title', {'(a)', '(b)', '(c)', '(d)'}, ... % 四个系统13 'zeros', {[], [0; 0], [-0.5], [1.2j; -1.2j]}, ... % 零点坐标14 'poles', {[-2; -1], [-2, -1], [-2; -1], [-1+1j; -1-1j]}... % 极点坐标15); % 为绘图方便起见,使用结构体16omega = [0 : 0.01 : 6]; % 频率抽样点17
18for id = 1 : 419 [b, a] = zp2tf(data(id).zeros, data(id).poles, 1); % 零极点 -> 系统函数20 H = freqs(b, a, omega); % 指定频率点的响应21 subplot(2, 2, id), plot(omega, abs(H)), axis tight; % 绘制幅频特性曲线22 set(gca, 'YScale', 'log', 'FontSize', 16); % 设置纵轴对数刻度23 title(data(id).title), xlabel('\omega'), ylabel('H(\omega)');24end25
xxxxxxxxxx171% 5.1 离散时间信号的图像2% 例 5.11:单边指数序列的波形图3n = 0 : 10;4a1 = 1.3; x1 = a1.^n;5a2 = -1.3; x2 = a2.^n;6a3 = 0.7; x3 = a3.^n;7a4 = -0.7; x4 = a4.^n;8
9subplot 221, stem(n, x1, 'fill'), grid on;10xlabel('n'), title('x(n) = 1.3^n');11subplot 222, stem(n, x2, 'fill'), grid on;12xlabel('n'), title('x(n) = -1.3^n');13subplot 223, stem(n, x3, 'fill'), grid on;14xlabel('n'), title('x(n) = 0.7^n');15subplot 224, stem(n, x4, 'fill'), grid on;16xlabel('n'), title('x(n) = -0.7^n');17
xxxxxxxxxx241% 5.2 离散时间信号的运算2% 例 5.12:离散信号在基本运算后的波形图3% (1) x1(n) = a^n [u(n) - u(n-N)]4a = 0.9; N = 8; n = -12 : 12; n1 = n;5x1 = a.^n .* (n>=0 & n < N); % n < N 不能取等,书中有误.6% 这样写是非常方便的, 也可以用 heavisdie(n) 表示 u(n)7subplot 411, stem(n1, x1, 'fill'), grid on;8title('x1(n)'), axis([-15 15 0 1]);9
10% (2) x2(n) = x1(n + 3);11n2 = n1 - 3; x2 = x1; % 注意这里直接写为 n1 - 312subplot 412, stem(n2, x2, 'fill'), grid on;13title('x2(n)'), axis([-15 15 0 1]);14
15% (3) x3(n) = x1(n - 2);16n3 = n1 + 2; x3 = x1;17subplot 413, stem(n3, x3, 'fill'), grid on;18title('x3(n)'), axis([-15 15 0 1]);19
20% (4) x4(n) = x1(-n);21n4 = n1; x4 = fliplr(x1); % 这里书中有误, n4 与 x4 翻一次就可以了.22subplot 414, stem(n4, x4, 'fill'), grid on;23title('x4(n)'), axis([-15 15 0 1]);24
xxxxxxxxxx71% 5.3 系统的单位样值响应2% 例 5.13:差分方程的单位样值响应3a = [3 -4 2]; % Y(n) 的系数4b = [1 2]; % X(n) 的系数5n = 0 : 50; % 计算 51 个点6impz(b, a, 50); % 绘出单位样值响应7
xxxxxxxxxx281% 5.4 离散时间序列的卷积2% 例 5.14:离散序列的卷积和及其波形图3% x(n) = u(n) - u(n-10);4% h(n) = u(n) - u(n-5);5n = -10 : 10; % 无需使用中括号6x = zeros(1, length(n));7x(n>=0 & n<10) = 1; % 可以直接使用逻辑序列,而无需使用 find 函数8 % 即时使用 find 函数,也无需在两侧加中括号9h = zeros(1, length(n));10h(n>=0 & n<5) = 1;11
12n1 = fliplr(-n); h1 = fliplr(h); % 过程 113n2 = n1; h2 = [0, h1]; h2(length(h2)) = []; % 过程 214n3 = n2; h3 = [0, h2]; h3(length(h3)) = []; % 过程 315n4 = -n; nmin = min(n1) - max(n4);16nmax = max(n1) - min(n4); ny = nmin : nmax;17y = conv(x, h); % 卷积结果18
19subplot 321, stem(n, x, '*k'), title('x(n)');20subplot 322, stem(n, h, 'ok'), title('h(n)');21subplot 323, stem(n, x, '*k'), hold on;22 stem(n1, h1, 'k'), title('p1');23subplot 324, stem(n, x, '*k'), hold on;24 stem(n2, h2, 'k'), title('p2');25subplot 325, stem(n, x, '*k'), hold on;26 stem(n3, h3, 'k'), title('p3');27subplot 326, stem(ny, y, '.k'), title('y(n)');28
xxxxxxxxxx241% 5.5 离散时间系统的响应2% 例 5.15:输入序列的时域波形图与 LTI 系统的零状态响应3a = [3 -4 2]; % y(n-k) 的系数4b = [1 2]; % x(n-k) 的系数5n = 0 : 20;6x = 0.5 .^ n;7y = filter(b, a, x);8subplot 211, stem(n, x, 'fill'), title('Input Seqence');9xlabel('n'); ylabel('x(n)');10subplot 212, stem(n, y, 'fill'), title('Response Sequence');11xlabel('n'); ylabel('y(n)');12
13% 例 5.16:系统的零状态响应14k1 = 0 : 7; f1 = 0.8 .^ k1 .* ones(1, 8);15k2 = 0 : 3; f2 = ones(1, 4);16% [f, k] = dconv(f1, f2, k1, k2);17f = conv(f1, f2); % 教材中给的代码跑不了,换成这个了18
19% 教材中没有给出绘图代码. 这里的绘图功能是第一次遇到的20% 其中第三个图像, 可以省略横轴的 k3.21subplot 221, stem(k1, f1, '*b'), title('f1(n)');22subplot 222, stem(k2, f2, 'ob'), title('f2(n)');23subplot(2, 2, [3 4]), stem(f, 'ob'), title('f(n)');24
第 6 章 离散 z 域分析
6.1 离散系统零极点图
6.2 系统单位样值响应
6.3 离散系统差分方程
6.4 z 域部分分式展开
6.5 z 变换与 z 逆变换