|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
设矩形脉冲
是脉冲响应
的LTI系统的输入,求输出 y(n).* m& w0 V8 N: w: Z, {" ~! [1 D7 N" [
2 w, E* T$ X1 Q
下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:
9 k- |4 \+ F; j- e( W
6 ^# x1 V' r8 U4 I" O2 h6 Vfunction [y,n] = sigadd(x1,n1,x2,n2), P& R: O* `0 D' Z: B" D ^
% implements y(n) = x1(n) + x2(n)
2 P [& J8 E+ O$ |: E9 i% [y,n] = sigadd(x1,n1,x2,n2)
. a( _- D3 r# c. W6 C6 Q) B3 Y' _%——————————————————————————————2 z' s) M& V& l. Y: K
% y = sum sequence over n, which includes n1 and n2
- [8 `; {& {( O% x1 = first sequence over n1
$ N6 f- c @, M0 Z X% x2 = second sequence over n2( n2 can be different from n1) a! k( ]7 \: H% C5 g; Q5 k
%
( v- Z' ?. |5 ?" s) y, V5 E4 an = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n)
/ @4 H6 t1 g+ P8 p8 Sy1 = zeros(1,length(n)); y2 = y1; %initialization% t Z4 ]4 Q3 o: w
y1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1
- r' F3 ?' ^$ P. g, ry2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y2
) N0 X0 W9 W% r% zy = y1 + y2;. Q2 w' t0 I6 I- {/ w5 o) B
1 L4 J: y4 ]4 @. b$ u2 T: I
: x- k$ @& b6 I, \1 F( ]5 l5 M* z" l直接给出MATLAB脚本:/ q5 J4 U) }! N, Z
5 p' V% e( ~2 X( w, @clc# |1 L9 {! W1 w$ y9 q5 C" O7 X
clear( b. j, d1 x: M( I+ N/ y- P
close all
. b' h s$ |8 g# L. o. x+ x# n; Q* _% a7 q
% help stepseq, @+ [6 L3 P; G+ j* `9 B9 p
% generate x(n) = u(n - n0); n1 <= n <= n2
3 p. ]5 @: x; O3 C) t% o% _____________________________________________( d0 k& p I2 ?' o6 S* {) \
% [x,n] = stepseq(n0, n1, n2);8 R8 |9 c% u3 O" x# _8 j
[u1,n1] = stepseq(0,-5,45);/ b8 n* P H+ D# @" D) P( i" p' ~
[u2,n2] = stepseq(10,-5,45);
- T# |3 B. b$ y- l. z# u- n# a8 u4 Q: C" F
% generate signal x(n)
! G" Z! f" p* s a[x,n] = sigadd(u1,n1,-u2,n2);
6 z7 Z+ d ?8 B. _% s& r$ P; |5 ~* S4 {# }' w8 s
% generate signal h(n)
7 E, H+ `" v- dm = -5:45;' j1 u- F* H1 C) i, s& }
h = ( (0.9).^m ).* u1;
$ Q3 `* i6 K; ~+ g
- Z: U: g: A* y4 s5 s9 L) [4 Z( x
" ~# b+ B7 z, z! w; L4 S3 t% the convolution of x(h) and h(n)
, [0 T- m& M8 }& [y = conv(x,h);
' k6 h! W! E# [! g, M0 J% ensure the index
$ K) c* K8 M5 ^+ c$ z9 u+ jnyb = n(1)+ m(1);
. C/ E& _# }' {2 Pnye = n(length(x)) +n(length(h));1 ]" Q+ \; B$ M2 Y# C5 W1 ?
ny = nyb:nye;: ~, j6 `( _% p$ `! S
# C1 y6 Q( G6 d0 }) |) k4 R) M5 ~
; \/ ]9 z* k+ M5 [% Tsubplot(3,1,1); d+ d0 m4 Z9 T# K
stem(n,x);
" e. i6 G2 @7 J- o) m9 Ttitle('x(n)');, J" @ B( c# F' n3 N( E
xlabel('n')
0 b% ?4 h% o# e" }
" r! E* x3 m0 o! s6 w( L6 C/ rsubplot(3,1,2);
/ K6 v: O' o( K8 xstem(m,h);
, D3 M" X2 V1 @1 [. v, ytitle('h(n)');/ ?/ \5 c" B0 u+ X" R% u8 w) M
xlabel('n')' N6 B; f, e7 j4 G8 W) S
' ^2 M1 ~2 m1 M" O/ L/ Csubplot(3,1,3);
! X7 j7 J3 @" F) O" q* V2 i2 U+ Pstem(ny,y);# v* |2 ~! |, ^# K
title('the conv of x(n) and h(n)');" D- p1 X7 M# |3 M, O' Y1 p1 Z
xlabel('n')
! X3 _/ p4 y& j, i+ l+ V, mxlim([-5,45]);
& c2 Y3 Y6 o3 Z* z2 H0 z3 K2 z2 {# D! S
" F6 a+ K% u8 o% k& V
" d& o. }8 I$ f; `; X) S' n
. ~; ^" r% x6 @
# r: Q3 z. m& _# j
7 x b ~2 {! V8 \8 N
% O4 ~" l' F2 ~. @. f7 \) K: ~, V" w/ O8 {1 r5 L
|
|