Sei sulla pagina 1di 40

Lecture 4: Discrete Signal Analysis

Prof. Dr. Salina A. Samad Mr. Iskandar Yahya

Sequence
!y"es of Sequences #nit Sam"le Sequence

eneration

$reate s single im"ulse %et&een a finite num%er of 'eros. (a)ing a function is useful* alternati)ely use +'eros, function [x,n] = impseq(n0,n1,n2) function. %generates x(n) = delta(n-n0); n1 = n = n2
%-------------------------------------------%[x,n] = impseq(n0,n1,n2) % n = [n1!n2]; x = [(n-n0) == 0]; %gi"ing "alues of n and x stem(n,x); %stem plot or impulse plotting function title(#$nit %ample %equence#) xla&el(#n#); 'la&el(#x(n)#);

Sequence
#nit Sam"le Sequence

2 1.8 1.6 1.4 1.2 x(n) 1 0.8 0.6 0.4 0.2 0 -5 -4 -3 -2 -1 0 n

eneration

!he resulting "lot looks like this


Unit Sample Sequence

Sequence
#nit Ste" Sequence

eneration

3e can ha)e another elegant &ay to "roduce a ste" function Alternati)ely* &e can use the +ones, function
function [x,n] = stepseq(n0,n1,n2) %generates x(n) = u(n-n0); n1 = n = n2 %-------------------------------------------%[x,n] = stepseq(n0,n1,n2) % n = [n1!n2]; x = [(n-n0) (= 0]; stem(n,x); title(#$nit %ample %equence#) xla&el(#n#); 'la&el(#x(n)#);

Sequence
#nit Ste" Sequence

2 1.8 1.6 1.4 1.2 x(n) 1 0.8 0.6 0.4 0.2 0 -5 -4 -3 -2 -1 0 n

eneration

!y"e +ste"seq./*01*12, &e get:


Unit Sample Sequence

Sequence

eneration

4eal0)alued e5"onential Sequence

!he o"erator +.6, is required to im"lement a real e5"onential sequence. 7or e5am"le* to generate 5.n2 8 ./.92n* /:8 n:8;/* &e &ill need the follo&ing scri"t:
(( n = [0!10]; x = (0)*))+n;

<5am"le tutorial: $reate a function .M0file2 to generate an e5"onential sequence. #se the "re)ious e5am"les as your guide.

Sequence

$om"le50)alued e5"onential Sequence

eneration

A matla% function +e5", is used to generate e5"onential sequences. 7or e5am"le* to generate 5.n2 8 e5"=.>?@A2nB* /:8 n:8;/* &e &ill need the follo&ing scri"t:
(( n = [0!10]; x = exp((2,-.)/n);

Cote that you need different "lot commands for "lotting real and imaginary com"onents.

Sinusoidal sequence

A matla% function +cos, .or sin2 is used to generate sinusoidal sequences. !o generate 5.n2 8 Acos./.;Dn ? DEA2 ? >sin./.1 Dn2* /:8 n:8;/* &e &ill need the follo&ing scri"t: (( n = [0!10]; x = -/cos(0)1/pi/n,pi0-) , 2/sin(0)1/pi/n);

Sequence
4andom Sequences

eneration

A random or stochastic sequences are characterised %y "arameters of the associated "ro%a%ility density functions or their statistical moments. In matla%* > ty"es of ."suedo 2 random sequences are a)ala%le: +rand.;*C2, generates a length C random sequence &hos elements are uniformly distri%uted %et&een / and ;. +randn.;*C2 generates a length C gaussian random sequence &ith mean / and )ariance ;.

-ther random sequences can %e generated suing transformation of the a%o)e functions. .$heck "re)ious lecture slides2

Sequence
Periodic sequence

eneration

A sequence is "eriodic if 5.n2 8 5.n ?C2. !o generate P "eriods of 5.n2 from one "eriod* &e can co"y 5.n2 P times:
(( xtilde = [x,x,x,x))),x];

An elegant a""roach is to use matla%Fs inde5ing ca"a%ilites: enerate a matri5 containing P ro&s of 5.n2 )alues. $oncatenate P ro&s into a long ro& )ector using the construct .:2. (a)e to use matri5 trans"osition o"erator .G2 to "ro)ide (( xtilde = x# / ones(1,2); %2 columns of x; x is a ro3 "ector the same effect on ro&s:
(( xtilde = xtilde(!); %long coloumn "ector (( xtilde = xtilde#; %long ro3 "ector

Sequence -"eration
Signal addition

!o add t&o sequences 5;.n2 and 5>.n2 requires the o"erator +?,. Hut the length of %oth sequences must %e equal and ha)e the same sam"le "osition 3e ha)e to first augment %oth 5;.n2 and 5>.n2 so that they ha)e the same "osition )ector and hence length. !his requires careful attention to matla%Fs inde5ing o"erations.

Sequence -"eration
Signal addition

!he follo&ing function* called +sigadd,* demonstrate this o"eration:

function [',n] = sigadd(x1,n1,x2,n2) %generates '(n) = x1(n) , x2(n) %-------------------------------------------%[',n] = sigadd(x1,n1,x2,n2) % ' = sum sequence o"er n, 34ic4 includes n1 and n2 % x1 = first sequence o"er n1 % x2 = second sequence o"er n2 (n2 can &e different from n1) % n = min(min(n1),min(n2))!max(max(n1),max(n2)); '1 = 5eros(1,lengt4(n)); '2 = '1; '1(find((n(=min(n1))7(n =max(n1))==1))=x1; '2(find((n(=min(n2))7(n =max(n2))==1))=x2; ' = '1,'2; % duration of '(n) % 6nitili5ation % x1 3it4 duration of ' % x2 3it4 duration of ' % sequence addition

Sequence -"eration
Signal Multi"lication

Sam"le0to0sam"le multi"lication .or +dot, multi"lication2 Im"lemented in matla% %y the array o"erator +.I, Again* same restriction as using +?, 3e can create a function called +sigmult,:

Sequence -"eration
function [y,n] = sigmult(x1,n1,x2,n2) %generates y(n) = x1(n)*x2(n) %-------------------------------------------%[y,n] = sigmult(x1,n1,x2,n2) % y = product sequence o er n, !"ic" includes n1 and n2 % x1 = first sequence o er n1 % x2 = second sequence o er n2 (n2 can #e different from n1) % n = min(min(n1),min(n2))$max(max(n1),max(n2))% y1 = &eros(1,lengt"(n))% y2 = y1% y1(find((n(=min(n1)))(n*=max(n1))==1))=x1% y2(find((n(=min(n2)))(n*=max(n2))==1))=x2% y = y1 +* y2% % % duration of y(n) % 'nitili&ation % x1 !it" duration of y % x2 !it" duration of y sequence ,ultiplication

Sequence -"eration
Signal Scaling

{ x( <ach sam"le is multi"lied %y a scalar . n )} = { x( n )} #se the command +I, for scaling.

Signal Shifting

<ach sam"le of 5.n2 is shifted %y an amount k to y( n ) = { x( n k )} o%tain a shifted sequence y.n2


% ,-./-0 function function [y,n] = sigs"ift(x,m,n1) % implements y(n) = x(n-n1) % ---------------------% [y,n] = sigs"ift(x,m,n1) % n = m2n1% y = x%

if let m = n k n = m+k then y( m + k ) = { x( m )}

Sequence -"eration
7olding

<ach sam"le is of 5.n2 is fli""ed around n8/ to o%tain a folded y.n2 y( sequence n ) = { x( n )} Im"lement +sigfold, %y +fli"lr.52, J +0fli"lr.52,.

% ,-./-0 function function [y,n] = sigfold(x,n) % implements y(n) = x(-n) % -------------------% [y,n] = sigfold(x,n) % y = fliplr(x)% n = -fliplr(n)%

Signal Summation

n2 x( n ) = n = n1

x( n1 ) + + x( n2 )

Adds all sam"le )alues of 5.n2 %et&een n; and n> Im"lement %y +sum.5.n;:n>22, function

Sequence -"eration
Sam"le Products

x( n ) = x( n1 ) x( n2 )
n1

n2

Multi"lies all sam"le )alues of 5.n2 %et&een n; and n>. Im"lement %y +"rod.5.n;:n>22, function..

Signal <nergy 2 x = x( n )x* ( n ) = x( n )

Su"erscri"t I denotes the o"eration of com"le5 con@ugation % ,-./-0 code Im"lemented 3x = sum(x +* con4(x)) % one approac" %y

3x = sum(a#s(x) +5 2)

% anot"er approac"

Sequence -"eration
Signal Po&er 1 N 1 2 Px = 0 x( n ) N

A)erage "o&er of a "eriodic sequence &ith fundamental "eriod C

Sequence -"eration
<5am"le ;:

Let x( n ) = { 1,2 ,3,4 ,5,6 ,7 ,6 ,5,4,3,2 ,1 }

Determine and "lot the follo&ing sequences a . x1( n ) = 2 x( n 5 ) 3 x( n + 4 ) b. x2 ( n ) = x( 3 n ) + x( n )x( n 2 )

Sequence -"eration
<5am"le ; coding:
% ,-./-0 code for part (a) n = [-2$11]% x = [1$6,7$-1$1]% [x11,n11] = sigs"ift(x,n,8)% [x12,n12] = sigs"ift(x,n,-9)% [x1,n1] = sigadd(2*x11,n11,-:*x12,n12)% % ,-./-0 code for part (#) n = [-2$11]% x = [1$6,7$-1$1]% [x21,n21] = sigfold(x,n)% [x21,n21] = sigs"ift(x21,n21,:)% [x22,n22] = sigs"ift(x,n,2)% [x22,n22] = sigmult(x,n,x22,n22)% [x2,n2] = sigadd(x21,n21,x22,n22)% % ;lotting coding su#plot(2,1,1)% stem(n1,x1)% title(<=equence in 3xample 1a<) xla#el(<n<)% yla#el(<x1(n)<)% su#plot(2,1,2)% stem(n2,x2)% title(<=equence in 3xample 1#<) xla#el(<n<)% yla#el(<x2(n)<)%

Sequence -"eration
<5am"le ; "lots:
20 10 x1(n) 0 -10 -20 -30 -10 -5 0 5 10 15 Sequence in Example 1a

40 30 x2(n) 20 10 0 -8

Sequence in Example 1b

-6

-4

-2

2 n

10

12

Sequence -"eration
<5am"le >:

enerate the com"le50)alued signal


x( n ) = e( 0.1+ j 0.3 )n , 10 n 10

and "lot its magnitude* "hase* the real "art* and the imaginary "art in four se"arate su%"lots

Sequence -"eration
<5am"le > coding:
% ,-./-0 code exmple2 n = [-11$1$11]% alp"a = -1+121+:4% x = exp(alp"a*n)% su#plot(2,2,1)% stem(n,real(x))% title(<real part<)%xla#el(<n<) su#plot(2,2,2)% stem(n,imag(x))% title(<imaginary part<)%xla#el(<n<) su#plot(2,2,:)% stem(n,a#s(x))% title(<magnitude part<)%xla#el(<n<) su#plot(2,2,9)% stem(n,(1>1?pi)*angle(x))% title(<p"ase part<)%xla#el(<n<)

Sequence -"eration
<5am"le > "lots:
2 1 0 -1 -2 -3 -10 3 -5 0 5 n magnitude part 10 -2 -10 200 100 0 1 -100 -5 0 n 5 10 -200 -10 -5 0 n 5 10 -5 0 n phase part 5 10 0 real part 1 imaginary part

-1

0 -10

Sequence Synthesis
#nit Sam"le Synthesis

x( n ) = k 2 x( k )( n k ) =n
n 1

Ar%itrary sequence 5.n2 can %e synthesi'ed as a &eighted sum of delayed and scaled unit sam"le sequences

<)en and odd synthesis x xo ( n ) = xo ( n ) if if e ( n ) = xe ( n ) x ( n ) is called even ( symmetric ) then e then xo ( n ) is called odd ( antisymmetric )

Any ar%itrary real0)alued sequence 5.n2 can %e decom"osed x( n ) = x ( n ) + x into ( n ) its e)en and odd com"onent
e o

xe ( n ) = 1 [ x( n ) + x( n )], xo ( n ) = 1 [ x( n ) x( n )] 2 2

Sequence Synthesis

Im"lement 8e)enodd9 function

function [xe, xo, m] = e enodd(x,n) % @eal signal decomposition into e en and odd parts % --------------------------------------------% [xe, xo, m] = e enodd(x,n) % if any(imag(x) A= 1) error(<x is not a real sequence<) end m = -fliplr(n)% m1 = min([m,n])% m2 = max([m,n])% m = m1$m2% nm = n(1)-m(1)% n1 = 1$lengt"(n)% x1 = &eros(1,lengt"(m))% x1(n12nm) = x% x = x1% xe = 1+8*(x 2 fliplr(x))% xo = 1+8*(x - fliplr(x))%

Sequence Synthesis

<5am"le >: <)en0-dd $om"onents:

% ,-./-0 code example 2 n = [1$11]% x = stepseq(1,1,11)-stepseq(11,1,11)% [xe,xo,m] = e enodd(x,n)% su#plot(1,1,1) su#plot(2,2,1)% stem(n,x)% title(<@ectangular pulse<) xla#el(<n<)% yla#el(<x(n)<)% axis([-11,11,1,1+2]) su#plot(2,2,2)% stem(m,xe)% title(<3 en ;art<) xla#el(<n<)% yla#el(<xe(n)<)% axis([-11,11,1,1+2]) su#plot(2,2,9)% stem(m,xo)% title(<Bdd ;art<) xla#el(<n<)% yla#el(<xo(n)<)% axis([-11,11,-1+7,1+7])

Sequence Synthesis

<5am"le >: !he "lots


Rectangular pulse 1 1 xe(n) 0.8 0.6 0.4 0.2 -5 0 n 5 10 0 -10 0.6 0.4 xo(n) 0.2 0 -0.2 -0.4 -10 -5 0 n 5 10 -5 0 n Odd Part 5 10 Even Part

x(n)

0.8 0.6 0.4 0.2 0 -10

Sequence Synthesis
!he

eometric Series

A one0sided e5"onential sequence of the form


{ n , n 0 }, is arbitrary cons tan t 1 , for < 1 1 1 N N 1 n n=0 1 , for

n =0 n

Sequence Synthesis
$orrelation of sequences

Measure of the degree to &hich t&o sequences are similar $rosscorrelation If2 5.n2* y.n2 is finite energy !hen2 crosscorrelation of 5.n2* y.n2
rx ,y ( l ) = n = x( n ) y( n l ), l " shift or lo!
n =

arameter

Autocorrelation S"ecial case of crosscorrelation &hen y.n285.n2


rx ,x ( l ) = n = x( n )x( n l )
n =

$on)olution
$on)olution can %e e)aluated in many different

&ays. If ar%itrary sequences are of infinite duration* then MA!LAH cannot %e used directly to com"ute the con)olution. As you already kno&* there are A conditions .cases2 for e)aluation:
Co o)erla" Partially o)erla" $om"lete o)erla"

A %uilt in function to com"ute con)olution of >

finite duration is called +con),. It assumes that the t&o sequences %egin at n 8 (( ' = con"(x,4) /:

$on)olution
x(n) = [-,11,:,0,-1,;,2] <5am"le of a sim"le con)olution: 4(n) = [2, -,0,-1,2,1]
((x = [:,11,6,1,-1,9,2]% (( " = [2,:,1,-8,2,1]% (( y = con (x,") y = 7 :1 96 7

-81

-8

91

1>

-22

-:

>

(( n = [1$lengt"(y)]% (( m = [1$lengt"(x)]% o = [1$lengt"(")]% (( figure(1)% clf (( su#plot(2,2,2)% stem(m,x) ((title(<=equence x(m)<) ((xla#el(<m<)% yla#el(<x(m)<)% (( su#plot(2,2,:)% stem(o,") (( title(<=equence y(o)<) ((xla#el(<o<)% yla#el(<y(o)<)% (( su#plot(2,2,1)% stem(n,y)% (( title(<Con ol ed sequence<) (( xla#el(<n<)% yla#el(<y(n)<)%

$on)olution
<5am"le of a sim"le con)olution:
50 0 -50 -100 Convolved sequence 15 10 x(m) 5 0 0 5 10 15 -5 0 2 4 m 6 8 Sequence x(m) y(n)

4 2 y(o) 0 -2 -4 -6 0

n Sequence y(o)

6s <4is =orrect>>>

$on)olution
Hased on the "lots* +con), function neither

"ro)ides nor acce"ts any timing information. 3e need the %eginning and the end "oint of y.n2. A sim"le e5tension of the +con), function* called +con)Km,* can %e &ritten to "erform the con)olution of ar%itrary su""ort sequences:
function [y,ny] = con Dm(x,nx,",n") % ,odified con olution routine for signal processing % ----------------------------------------------------% [y,ny] = con Dm(x,nx,",n") % [y,ny] = con olution result % [x,nx] = first signal % [",n"] = second signal % ny# = nx(1)2n"(1)% nye = nx(lengt"(x)) 2 n"(lengt"("))% ny = [ny#$nye]% y = con (x,")%

$on)olution
Lets do the con)olution again from the "re)ious

e5am"le:
(( x = [:,11,6,1,-1,9,2]% nx = [-:$:]% (( " = [2,:,1,-8,2,1]% n" = [-1$9]% (( [y,ny] = con Dm(x,nx,",n") y = 7 :1 96 7 -81 -8 91 1> -22 -: > 2

ny =

-9

-:

-2

-1

(ence &e get the correct con)olution:


?(n) = @A,-1,;:,A,-11,-1,;1,1B,-22,--,B,2C

More infoL (<LP con)olution .con)2

$on)olution
Lets "lot y.n2:
60 Convolved Signal y(n) 40

20

y(n)

-20

-40

-60 -4

-2

2 ny

$orrelations
!here is a close resem%lance in con)olution and

correlation. $rosscorrelation and autocorrelation can %e com"uted using the +con), function if sequences are of finite duration. <5am"le:

In this e5am"le let 5.n2 8 =A*;;*M* /*0;*4*>B %e a "rototy"e sequence* and let y(n) %e its noise corru"ted and shifted )ersion: y.n2 8 5.n0>2?&.n2 &here w(n) is aussian sequence &ith mean / and )ariance ;. LetFs com"ute the cross correlation %et&een y.n2

$orrelations
7rom the construction of y.n2* it follo&s that y.n2 is +similar, to 5.n0>2 (ence their strongest similarity is &hen l = 2. $om"ute the crosscorrelation using t&o different noise sequences in Matla%.

$orrelations

Matla% commands:

% Eoise sequence 1 x = [:,11,6,1,-1,9,2]% nx=[-:$:]% % gi en signal x(n) [y,ny] = sigs"ift(x,nx,2)% % B#tain x(n-2) ! = rand(1,lengt"(y))% n! = ny% % generate !(n) [y,ny] = sigadd(y,ny,!,n!)% % o#tain y(n) = x(n-2) 2 !(n) [x,nx] = sigfold(x,nx)% % o#tain x(-n) [rxy,nrxy] = con Dm(y,ny,x,nx)% % 1st crosscorrelation % % noise sequence 2 x = [:,11,6,1,-1,9,2]% nx=[-:$:]% % gi en signal x(n) [y,ny] = sigs"ift(x,nx,2)% % B#tain x(n-2) ! = rand(1,lengt"(y))% n! = ny% % generate !(n) [y,ny] = sigadd(y,ny,!,n!)% % o#tain y(n) = x(n-2) 2 !(n) [x,nx] = sigfold(x,nx)% % o#tain x(-n) [rxy2,nrxy2] = con Dm(y,ny,x,nx)% % 2nd crosscorrelation % figure(1)% clf % clear figure(1) su#plot(1,1,1), su#plot(2,1,1)% stem(nrxy,rxy) axis([-9,>,-81,281])% xla#el(<lag aria#le 1<) yla#el(<rxy<)%title(<Crosscorrelation$ noise sequence 1<) su#plot(2,1,2)% stem(nrxy2,rxy2) axis([-9,>,-81,281])% xla#el(<lag aria#le 1<) yla#el(<rxy<)%title(<Crosscorrelation$ noise sequence 2<)

$orrelations

!he "lots:

250 200 150 rxy 100 50 0 -50 -4 -2

Crosscorrelation: noise sequence 1

2 lag variable 1

250 200 150 rxy 100 50 0 -50 -4 -2

Crosscorrelation: noise sequence 2

2 lag variable 1

$orrelations
Hased on the "lots* the correlation is "ro)en to "eak at l 8 >. !his im"lies that y(n) is similar to x(n) shifted %y >.

3e can use the signal0"rocessing tool%o5 in

matla% for crosscorrelation: NN 5corr.5*y2 com"utes the crosscorrelation %et&een )ectors 5 and y* &hile* NN 5corr.52 com"utes the autocorrelation of )ector 5.
!his function does not "ro)ide timing

Potrebbero piacerti anche