|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
设矩形脉冲
是脉冲响应
的LTI系统的输入,求输出 y(n).
5 P& }' C c( R: q7 Z- N5 M
. x) \! Y- c9 A$ s下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:
& m* f: N% a4 ?
& a( Y7 z* o, Q; Zfunction [y,n] = sigadd(x1,n1,x2,n2)8 L2 P( d$ t- }! X$ L
% implements y(n) = x1(n) + x2(n)
3 Y& E& y/ _7 l G9 X* o3 h% [y,n] = sigadd(x1,n1,x2,n2)
- j$ t+ P" k! v5 f/ }%——————————————————————————————" u, f8 ^/ U, i$ Q6 S4 g9 E: O
% y = sum sequence over n, which includes n1 and n25 h9 R( J G+ ]* S
% x1 = first sequence over n19 T7 q6 _% H) l3 v: Y. l8 k- R1 N
% x2 = second sequence over n2( n2 can be different from n1)3 T0 K4 v1 ], J
%: T3 D9 Q+ A. j
n = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n)
9 v, C' W! ?) d+ Iy1 = zeros(1,length(n)); y2 = y1; %initialization! ]8 H0 C) E4 |# r) r! ]
y1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y16 ~/ S3 O4 Z8 J8 m( s
y2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y2
Y" R3 f a3 S" r2 N! Sy = y1 + y2;& r% p' Z2 d0 b" W
, p1 o! c: k' _2 F ?7 y9 [3 [: @' Y7 Y0 G$ R4 e. I
直接给出MATLAB脚本:3 M' D! v" v1 x5 {3 A! Q
d5 K& r1 z( a% M2 Q Qclc7 `$ ]0 \7 Z+ I* \0 [" U- g2 Z
clear
$ T6 Z7 o, }- W5 ?- k/ Zclose all/ B! t% @; ]! @. n
Z& {6 v& U. \0 q% help stepseq4 p+ }8 K5 O5 e4 U8 |
% generate x(n) = u(n - n0); n1 <= n <= n2: {. q$ [# J9 @# g
% _____________________________________________7 T5 P# r- v4 K+ a
% [x,n] = stepseq(n0, n1, n2);
! [& s) C# _: ]' }9 R* g, L$ e5 S[u1,n1] = stepseq(0,-5,45);+ @& V& l' f# B+ g
[u2,n2] = stepseq(10,-5,45);- S2 v- M: w# o& |) e
$ v. Q) X6 G* w1 M$ [) S3 B
% generate signal x(n)
7 |3 r$ R/ {% x[x,n] = sigadd(u1,n1,-u2,n2);& y! Z. M4 m2 V3 E% X E
4 @, N. H9 b. ~- N" G% generate signal h(n)
) y/ W6 C# W3 g, g# Lm = -5:45;
6 `) D; G8 N) W _h = ( (0.9).^m ).* u1;8 E* T- v- J1 Y: z; T
2 R# O+ c n6 J" I
& U/ f# K0 n5 F& w$ P3 l+ S1 n% the convolution of x(h) and h(n)
$ g! X7 \; B& X* V# ]# @y = conv(x,h);
: x, L! P6 }4 B- m9 x) S9 {% ensure the index
+ R+ L. K: B: g2 J5 V$ fnyb = n(1)+ m(1);
& e+ M) a2 D5 v* J$ ]nye = n(length(x)) +n(length(h));9 m* P, W) Y3 K9 O7 U2 s; S) ?. y8 m
ny = nyb:nye;+ O( ]1 k, m- _$ |* t1 t
- H$ m7 ~# a6 a7 a& N8 E$ v
, O- P% W- s% @8 M, X" ^' w: `. tsubplot(3,1,1);
_" W$ }- f% j" Gstem(n,x);
( o0 L+ [7 ?9 }- ititle('x(n)');
" z9 y* _) F o' Q1 S zxlabel('n')
# w3 r: |( b2 R6 a/ o( k. E9 b& N5 Z8 b9 t9 J( t5 j) \7 d9 _
subplot(3,1,2);
# _9 H( d& u9 Y; E# V$ Fstem(m,h);
# G' `' e3 l0 e2 E9 c0 }title('h(n)');5 o% e5 e& ^0 m& E, F
xlabel('n')
, l8 U8 E, [" x9 M$ x6 |: q k$ V: u/ M( J- x" \6 m6 R
subplot(3,1,3);1 U9 r4 E7 s+ S+ z( K5 a" A' W
stem(ny,y);9 v$ p0 a2 E6 c
title('the conv of x(n) and h(n)');! a) m' X! J7 C2 z' t& ^5 F
xlabel('n')( Y# K, `: [ s- n& C
xlim([-5,45]);
* ^ K/ c8 U# o: t+ t$ K0 [9 W& r( l
* j2 N# m6 [( h$ \/ S; B
, q1 j2 F, o+ G5 R
' T4 x+ I# g% B: k3 s4 ~" a9 ]
2 d& I* ^% F2 {5 P! }# X
! f" t/ N5 a5 N( O7 u6 \7 a% s# {! C1 W+ B/ A4 T3 Z- Z3 n- I3 t
# W8 e( G+ Q7 \- B4 [+ \+ ?
|
|