|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
设矩形脉冲
是脉冲响应
的LTI系统的输入,求输出 y(n).8 Z. d8 p; R8 ]+ T ~$ S, @) H
* Q- f) Z9 ?# a% G7 }4 U
下面的脚本中用到了一个自定义的函数,也就是两个信号相加的函数:
4 Z5 C! u1 s1 B+ a# D& h& z7 L6 ~2 B2 C6 Y3 C' `
function [y,n] = sigadd(x1,n1,x2,n2)
0 X$ J6 ^0 b# p) q% implements y(n) = x1(n) + x2(n)
) ]2 ]5 j& J5 d8 h- [% [y,n] = sigadd(x1,n1,x2,n2)" u' q; n! t7 F9 j( r$ m8 ~# s
%——————————————————————————————2 }% j6 `, H( m/ S+ z% Y
% y = sum sequence over n, which includes n1 and n2
6 \* T8 K1 Y) g w' D0 [% D& N% x1 = first sequence over n1
! v- C/ q; h/ {6 p2 e" N7 m# g% x2 = second sequence over n2( n2 can be different from n1)
; ^3 W: u. j' N* {+ ?( }%
: {1 z( U+ Y+ Y0 Fn = min( min(n1), min(n2) ):max( max(n1), max(n2) ); %duration of y(n), M9 o. R, j6 W" W4 z" J: a
y1 = zeros(1,length(n)); y2 = y1; %initialization
6 V: @" V! G6 Y# ?y1( find( ( n >= min(n1) )&( n <= max(n1) ) == 1 ) ) = x1; %x1 with duration of y1
, S$ F+ T, F1 U- d8 k! Yy2( find( ( n >= min(n2) )&( n <= max(n2) ) == 1 ) ) = x1; %x2 with duration of y21 s# r8 v! @% T& X/ F, D. P- t
y = y1 + y2;
/ a$ `6 ?! t& K% A; U6 b8 I: U. A3 h8 A' C* _
0 t! a$ o! a$ h
直接给出MATLAB脚本:
$ T% f. L/ G% {& L/ p
; {! F, ]. e# Z. W5 h7 D& T7 oclc6 R" ~3 a( l$ J5 l4 ?
clear9 W. z; {; X+ e5 }9 L- X8 j, q
close all
2 y, |; G3 Y6 _) D- l# I' k2 G# Y" d) g; H0 O4 S
% help stepseq
+ w; g% _" V4 j+ J! l: ~% generate x(n) = u(n - n0); n1 <= n <= n2# M; i0 ?% _3 M8 l Q
% _____________________________________________- f6 H9 x' P+ K* q: V4 R
% [x,n] = stepseq(n0, n1, n2);
$ g3 D* Y! k2 K1 q( B[u1,n1] = stepseq(0,-5,45);8 Z5 X" Z; h' |6 D" I
[u2,n2] = stepseq(10,-5,45);, @' D" S! b& i7 z$ W, d4 z0 D
6 J7 J$ J; ^' a. ?& B5 a% generate signal x(n)( C7 v7 J6 N; Y9 [
[x,n] = sigadd(u1,n1,-u2,n2);
- t o- E5 U& B3 K0 O1 V6 E* b6 p
% generate signal h(n)
5 x: o. ^; p0 C' R9 V/ P6 A& g, a* |m = -5:45;
& l' n* v" }. @& ~4 {h = ( (0.9).^m ).* u1;
: N5 U% s1 D, o+ \( ]+ l9 u& l4 F: i% j! \
) ]! z, S3 M- U0 m! e) B; x; ~) r
% the convolution of x(h) and h(n)
8 ^% m6 q! N0 z: _ x- e: g% Zy = conv(x,h);
( G( V9 j0 H; i/ T% ensure the index& @4 k8 E" x0 m( ^5 ~3 R" q
nyb = n(1)+ m(1);" z$ d' u5 h! {9 W( j
nye = n(length(x)) +n(length(h));. B9 w- j7 W9 {; o
ny = nyb:nye;
9 l+ M/ g3 e, @+ i; d0 _6 P$ d. j+ B& w$ _+ h0 m& `
% z4 n3 I3 J+ N1 E
subplot(3,1,1);
- @- p) }1 u8 [) ?5 N8 Y4 ?* H/ pstem(n,x);
# L$ {/ D. [; t% S/ T! X: ltitle('x(n)');2 o4 h2 J' f# Z, j7 V6 R! T4 [
xlabel('n')
, k4 C4 H; U; n% g8 D5 S. r. `
/ m; D3 ]! K$ I, t5 u1 b! B! Rsubplot(3,1,2);
$ W7 S2 \" c4 V( |stem(m,h);5 {& G' R% l. p" W
title('h(n)');
1 \3 E$ `, L. d! y$ Axlabel('n')5 U0 k, P i* r: L: d7 Z1 ^( q
. X1 |8 U( |9 _ V6 ~3 P+ vsubplot(3,1,3);, i6 |/ E; T ~; r
stem(ny,y);2 T6 }# ]$ O q+ t0 @ e( v
title('the conv of x(n) and h(n)');+ l8 a% Z/ p3 R5 v' \' t
xlabel('n')2 r! z0 _- b2 s2 d4 S; D. m
xlim([-5,45]);
0 ~8 W1 z: t5 {8 ^7 y/ Z9 z, p& q& M
0 q- k6 E7 \; U9 t' E* t
: }1 ^& a, v( Q2 t e
- u6 p7 w1 |) B" |- E
( _! W2 F" L( [: d! d
. S, L& Y! T5 |4 f. k1 Y# J' t+ \5 Y! z/ b$ F
2 N) t: Q/ Q4 t( _) b
|
|