|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
设矩形脉冲
是脉冲响应
的LTI系统的输入,求输出 y(n).* y) `& p; i2 y
5 f( T+ _" R+ ~5 O+ p; a
下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:. r1 F( {1 q+ D
6 g" @* G# ], N* t' b
function [y,n] = sigadd(x1,n1,x2,n2)
7 o; { i4 A4 w; s) x; Q% implements y(n) = x1(n) + x2(n)
: D8 u) p- o& S0 r) g& c% [y,n] = sigadd(x1,n1,x2,n2)
8 `0 L) f( l9 U& {* \8 B. G8 A%——————————————————————————————
3 b% P9 W$ G0 Q4 B' a# R) Z% y = sum sequence over n, which includes n1 and n28 Z; a1 L3 @: K% J: U
% x1 = first sequence over n1
9 t) b+ ?3 W) o5 S. V8 \$ L3 N% x2 = second sequence over n2( n2 can be different from n1)' Y# y) `* j& c4 a1 G
%. t) l; ]* X% Y, H4 {; k4 |5 ]( l
n = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n)
2 {5 y. B; Q8 t! {5 q& Yy1 = zeros(1,length(n)); y2 = y1; %initialization
! W2 Z% e- O& C! r$ _- ]y1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1 C* f8 o. ^9 L$ c& o/ |
y2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y24 _. f; J$ b& Y, y# w( s
y = y1 + y2;
9 x. y9 \1 O" L# ^2 \
4 X( @9 [ w+ b# H$ G- S4 q5 o- T" a, x( T* E' t! O* Y+ i
直接给出MATLAB脚本:0 C0 }1 {% h+ s1 Y7 k( e6 O( N a
# _' {! o! I7 a( xclc4 K9 G1 ~ q) w6 B( O) t
clear
5 q1 s% u6 A C% L8 \2 @& q6 Q% }close all. A& m+ N' f( o/ O
$ r' {( h1 s- n6 a, ?1 G
% help stepseq% {1 t4 Z" A; e- h. F% p9 g
% generate x(n) = u(n - n0); n1 <= n <= n2; A, W" d+ N9 @1 h4 n& Z1 e& J
% _____________________________________________
5 N2 T1 D+ H. r; P( \% [x,n] = stepseq(n0, n1, n2);* X- K8 q$ h7 A/ e0 a$ x* K
[u1,n1] = stepseq(0,-5,45);% a( F ]6 R1 \! ?# X- s7 j
[u2,n2] = stepseq(10,-5,45);
, g( i* h! J# }! Z
; W- m1 t. A+ u' G% ~2 ?# Z% generate signal x(n)
1 k: G+ B7 F3 z7 w[x,n] = sigadd(u1,n1,-u2,n2); n* Q. g6 ]; @. y, a2 b
: s5 p7 [) ?/ v7 E3 P- O
% generate signal h(n)0 \$ ^; t0 O: v0 x" i5 r
m = -5:45;
6 x7 A+ q4 `* K Z# N$ eh = ( (0.9).^m ).* u1;! l7 C( v% m' Z+ Z6 o! C) }2 t* H
# p) z/ a8 B% h q7 I U. w; Y/ w
/ B2 \5 C8 d* @ h) c
% the convolution of x(h) and h(n)
1 q6 _5 e8 ~( F2 ]1 Ky = conv(x,h);
9 f/ ^# q. Z" [3 J/ m4 N% ensure the index- K) i1 B( G3 K# H
nyb = n(1)+ m(1);- t( L3 |* J$ N9 p# ^# l
nye = n(length(x)) +n(length(h));5 P" j+ T: ]- P' {, r
ny = nyb:nye;
* x' V0 i7 @' L. s6 L* a% v: t+ \( h _# A
3 l9 e; E1 T" |# H& ksubplot(3,1,1);
" J( r: Y/ w" l Z$ Tstem(n,x);
& [+ a1 r+ T) z& ktitle('x(n)');5 B; @ U) l8 G! \
xlabel('n')0 w7 ]; ^/ O3 W, G( `- m+ ?
4 g! f# o% ]- X3 Y9 C/ V4 w8 S4 csubplot(3,1,2);) @, l/ ]( p* f
stem(m,h);6 E' |8 K" G* e: G. Q2 H# Q
title('h(n)');
/ a* L1 @- o" e3 M# Txlabel('n')" I# f0 w9 B. ]# j( c: j
; D. r. Y- @2 V# u+ Fsubplot(3,1,3);; D9 u3 d2 \0 W( I
stem(ny,y);
' R; U, D: ~' ]! rtitle('the conv of x(n) and h(n)');+ K6 V/ H$ n. d5 D6 a
xlabel('n')6 \! z; ^) \# {0 ~
xlim([-5,45]);" Q) [! c6 d8 p6 S$ S2 O
% k4 _2 P4 X" N9 f- e& O. V! `, ~4 h6 m! e& w/ f. L/ M
( E% _* X& p: V3 h6 X/ q6 U$ q
6 ]4 L1 C* O( r' `
- m- K$ v4 M# K& C& o; l4 X: x& n! }& \' L5 P! P ]" {% z
3 J4 d! j4 z+ G0 E3 |! b
& f# Q( z/ {: S' v |
|