|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
设矩形脉冲
是脉冲响应
的LTI系统的输入,求输出 y(n).
' B4 C# `9 P9 N5 \4 `) O* ^5 j
! K0 n, w. M: v% t- ]& @3 e( b下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:
& e9 O5 r' g9 j7 X$ i* w4 D3 v- u
5 ]$ I3 W; T0 Y) D4 zfunction [y,n] = sigadd(x1,n1,x2,n2)9 M9 _' O2 P; y6 t9 R& r0 o
% implements y(n) = x1(n) + x2(n)
4 L. A' t( W/ w% Z' ]) }' U, Q% [y,n] = sigadd(x1,n1,x2,n2)' F! @& ~# ~ ~0 z6 B* ^6 S
%——————————————————————————————# G' O; g$ S; n! F) a8 k. n$ t
% y = sum sequence over n, which includes n1 and n2. C( b- U, P# P4 z! ^4 u) {
% x1 = first sequence over n1: m3 ~/ W/ h: a7 X) x( r
% x2 = second sequence over n2( n2 can be different from n1)
; a6 T6 U h9 K( b& H' R%
* v& r# s& k' |8 r$ }+ An = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n)
( O' a( K, O" J6 m; H; e2 ?y1 = zeros(1,length(n)); y2 = y1; %initialization$ {9 T! R; m8 O4 e" ^
y1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1: Q9 ]7 W6 t( o! ^3 S
y2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y2
+ b) z( |1 W! ^; f+ vy = y1 + y2;
1 i9 h8 J) j8 A7 F/ d* R7 T
% ?9 B4 O! G) | y( e; I* u- K, ^4 \* Q
直接给出MATLAB脚本:6 B" T5 Y: Q' ^9 _+ ]
5 Y" l. L2 w# I. h5 B
clc. w$ U/ @9 Z- J1 e
clear
5 c# E0 Y, T5 F% W7 Hclose all2 P# P2 I% u ~' H. W; T; m
! ~/ N) }% U; `' Z
% help stepseq. c( k6 t1 }* ]4 g- d" m) i
% generate x(n) = u(n - n0); n1 <= n <= n2
- b7 l2 W( { @; j1 B3 j% _____________________________________________) W' l& i( H& ^5 R
% [x,n] = stepseq(n0, n1, n2);
; U9 s1 _. q: K5 n[u1,n1] = stepseq(0,-5,45);4 B1 M: _+ Y6 q) |$ Z0 J
[u2,n2] = stepseq(10,-5,45);$ s! ]; t/ i/ K; V4 ~, z! t T+ L* c; [
" l) |7 X5 H" d& s
% generate signal x(n)
* l4 Q& g$ P& P" F/ D[x,n] = sigadd(u1,n1,-u2,n2); J# y" X6 U" S6 U, t6 B3 {$ O X8 t
# A( k0 S* A8 n6 I% generate signal h(n)# B* ~4 @0 v5 N5 y3 e# {; k0 w4 I
m = -5:45;7 U8 U4 L4 c; m5 Y7 S( m
h = ( (0.9).^m ).* u1;
1 I7 z0 y' L3 _# D8 {
' K: p. {+ X7 v
5 c0 G& o! e8 I1 L7 t/ O% the convolution of x(h) and h(n)
) f7 m" d5 ]/ S& Q6 T0 jy = conv(x,h);
5 n3 j. l( X. T6 Q. b1 U: g( N% R% ensure the index
) y9 w+ @# B2 l& o0 m4 c/ w# {! vnyb = n(1)+ m(1);+ B5 M/ c% Y! V% d0 H+ e
nye = n(length(x)) +n(length(h));
1 T8 B0 \$ \$ ` o9 ]" {6 lny = nyb:nye;
+ t( U+ c9 c0 T3 W" {) T! ^' g8 |4 V) u
, D. |* ]1 b) W
subplot(3,1,1);& a$ h% I; Q B8 Y; G* o
stem(n,x);3 ^7 r- u; m5 B
title('x(n)');
4 M. L6 s! Y, `# F! c% _- p' txlabel('n')
7 L4 R9 i7 N$ O+ W$ c+ D" G* g: v" s$ P3 Y! U0 _$ t \! [
subplot(3,1,2);
7 h. ~% t3 k" s) u# [stem(m,h);
& ]& I1 e* L; G- Ititle('h(n)');2 }6 ^# T4 |' G- f `
xlabel('n')
# x: E) X; [" T& |3 b
4 Y& g5 r3 J) ?, m$ csubplot(3,1,3);# h( B& |; H7 S- [% [$ x( `
stem(ny,y);* F) X! v* @( v( }" O! I1 `1 J, a
title('the conv of x(n) and h(n)');
! }* p; z1 u6 s7 ]1 Z O; \8 kxlabel('n')
; ?1 u0 t! U) [; Vxlim([-5,45]);
( O7 [9 s* i7 g6 ~7 d, P; Z* j3 L) C9 B" c$ F
# J k5 E: t3 x* i
2 U, g/ R7 p9 z0 R8 w
! N B x$ A0 l$ l$ s9 L/ }/ v0 s
* P/ `8 G3 m4 J$ P. O$ P
0 A& k. X C/ q" V8 l, K
* b, @4 s q w4 g! ]7 t; u5 K$ H G- M. Y
|
|