Simulatio Techiques Refereces: Chapter 2 S.M.Kay, Fudametals of Statistical Sigal Processig: Estimatio Theory, Pretice Hall, 993 C.L.Nikias ad M.Shao, Sigal Processig with Alpha-Stable Distributio ad Applicatios, Joh Wiley & Sos, 995 V.K.Igle ad J.G.Proakis, Digital Sigal Processig Usig MATLAB V.4, PWS Publishig Compay, 997 E.Part-Eader, A.Sjoberg, B.Meli ad P.Isaksso, The MATLAB Hadbook, Addiso-Wesley, 996 S.K.Park ad K.W.Miller, Radom umber geerators: good oes are hard to fid, Commuicatios of the ACM, vol.3, o.0, Oct. 988
Simulatio Techiques Sigal Geeratio. Determiistic Sigals It is trivial to geerate determiistic sigals give the sythesis formula, e.g., for a sigle real toe, it is geerated by MATLAB code: x( Acos( ω + θ, 0,, L, N N0; % umber of samples is 0 A; % toe amplitude is w0.2; % frequecy is 0.2 p; % phase is for :N x(a*cos(w*(-+p; % ote that idex should be > 0 ed 2
A alterative approach is 0:N-; % defie a vector of size N x A.*cos(w.*+p; % the first time idex is also %.* is used i vector multiplicatio Both give x Colums through 7 0.5403 0.3624 0.700-0.0292-0.2272-0.46-0.5885 Colums 8 through 0-0.7374-0.8569-0.9422 Q.: Which approach is better? Why? 3
Example 2. Recall the simple mathematical model of a musical sigal: x( t a( t cm cos(2πmf0t m + φ m A further simplified form is x ( t cos(2 πf 0 t where each music ote has a distict f 0. Let's the followig piece of music: A A E E F# F# E E D D C#C# B B A A E E D D C# C# B B (repeat oce (repeat first two lies oce 4
The America Stadard pitch for each of these otes is: A: 440.00 Hz B: 493.88 Hz C#: 554.37 Hz D: 587.33 Hz E: 659.26 Hz F#: 739.99 Hz Assumig that each ote lasts for 0.5 secod ad a samplig frequecy of 8000 Hz, the MATLAB code for producig this piece of music is: asi(2*pi*440*(0:0.00025:0.5; % frequecy for A bsi(2*pi*493.88*(0:0.00025:0.5; % frequecy for B cssi(2*pi*554.37*(0:0.00025:0.5; % frequecy for C# dsi(2*pi*587.33*(0:0.00025:0.5; % frequecy for D esi(2*pi*659.26*(0:0.00025:0.5; % frequecy for E fssi(2*pi*739.99*(0:0.00025:0.5; % frequecy for F# 5
lie[a,a,e,e,fs,fs,e,e]; % first lie of sog lie2[d,d,cs,cs,b,b,a,a]; % secod lie of sog lie3[e,e,d,d,cs,cs,b,b]; % third lie of sog sog[lie,lie2,lie3,lie3,lie,lie2]; % composite sog soud(sog,8000; % play soud with 8kHz samplig frequecy wavwrite(sog,'sog.wav'; % save sog as a wav file Note that i order to attai better music quality (e.g., flute, violi, we should use the more geeral model: x( t a( t cm cos(2πmf0t m + φ m Q.: How may discrete-time samples i the 0.5 secod ote with 8000 Hz samplig frequecy? Q.: How to chage the samplig frequecy to 6000 Hz? 6
2. Radom Sigals Uiform Variable A uiform radom sequece ca be geerated by x( seed ( a seed mod( m,,2,l where seed 0, a ad m are positive itegers. The umbers geerated should be (approximately uiformly distributed betwee 0 ad ( m. A set of choice for a ad m which geerates good uiform variables is a 6807 ad m 247483647 This uiform PDF ca be chaged easily by scalig ad shiftig the geeratio formula. For example, a radom umber which is uiformly betwee 0.5 ad 0.5 is give by seed x( ( a seed mod( m seed m 0.5 7
The power of x( is var( x 0.5 0.5 x 2 p( x dx 0.5 0.5 2 Note that x( is idepedet (white. x 2 dx To geerate a white uiform umber with variace σ 2 x : seed a seed ( mod( m seed x( 0.5 2 σ x m MATLAB code for geeratig zero-mea uiform umbers with power 2: N5000; % umber of samples is 5000 power 2; % sigal power is 2 u (rad([,n]-0.5.*sqrt(2*power; % rad give a uiform umber % i [0,] 8
Evaluatio of MATLAB uiform radom umbers: m mea(u % * mea computes the time average m 0.072 p mea(u.*u % compute power p 2.0225 y mea((u-m.*(u-m % compute variace v 2.0222 9
plot(u; % plot the sigal 2.5 2.5 0.5 0-0.5 - -.5-2 -2.5 0 500 000 500 2000 2500 3000 3500 4000 4500 5000 0
hist(u,20 % plot the histogram for u % with 20 bars 300 250 200 50 00 50 0-2.5-2 -.5 - -0.5 0 0.5.5 2 2.5 Q.: Is the radom geerator acceptable? Does ergodicity hold?
a xcorr(u; % compute the autocorrelatio plot(a % plot the autocorrelatio 2000 0000 8000 6000 4000 2000 0-2000 0 000 2000 3000 4000 5000 6000 7000 8000 9000 0000 2
axis([4990, 500, -500, 2000] % chage the axis 2000 0000 8000 6000 4000 2000 0 4990 4992 4994 4996 4998 5000 5002 5004 5006 5008 500 The time idex at 5000 correspods to R uu (0 white 3
Gaussia Variable Give a pair of idepedet uiform umbers which are uiformly distributed betwee [0,], say, ( u, u2, a pair of idepedet Gaussia umbers, which have zero-mea ad uity variace, ca be geerated from: w 2l( u cos(2πu 2 w 2 2l( u si(2πu This is kow as the Box-Mueller trasformatio. Note that the Gaussia umbers are white. MATLAB code for geeratig zero-mea Gaussia umbers with power 2: N5000; % umber of samples is 5000 power 2; % sigal power is 2 w rad([,n].*sqrt(power; % rad give Gaussia umber 2 4
% with mea 0 ad variace Evaluatio of MATLAB Gaussia radom umbers: m mea(w % * mea computes the time average m 0.023 p mea(w.*w % compute power p 2.058 y mea((w-m.*(w-m % compute variace v 2.057 5
plot(w; % plot the sigal 6 4 2 0-2 -4-6 0 500 000 500 2000 2500 3000 3500 4000 4500 5000 6
hist(w,20 % plot the histogram for w % with 20 bars 800 700 600 500 400 300 200 00 0-6 -4-2 0 2 4 6 7
a xcorr(w; % compute the autocorrelatio plot(a % plot the autocorrelatio 2000 0000 8000 6000 4000 2000 0-2000 0 000 2000 3000 4000 5000 6000 7000 8000 9000 0000 8
axis([4990, 500, -500, 2000] % chage the axis 2000 0000 8000 6000 4000 2000 0 4990 4992 4994 4996 4998 5000 5002 5004 5006 5008 500 The time idex at 5000 correspods to R ww (0 9
Impulsive Variable The mai feature of impulsive or impulse process is that its value ca be very large. A mathematical model for impulsive oise is called α-stable process, where 0 < α 2. α -stable process is a geeralizatio of Gaussia process ( α 2 ad Cauchy process ( α The variable is more impulsive for a smaller α A α -stable variable is geerated usig two idepedet variables: Φ which is uiform o ( 0.5π,0. 5π, ad W which is expoetially distributed with uity mea, where W is produced from W l(u where u is a uiform variable distributed o [0,] 20
MATLAB code for 0 < α < 2 ad α alpha.8; % alpha is set to.8 beta 0; % beta is a symmetric parameter N5000; phi (rad(,n-0.5*pi; w -log(rad(,n; k_alpha - abs(-alpha; beta_a 2*ata(beta*ta(pi*alpha/2.0/(pi*k_alpha; phi_0-0.5*pi*beta_a*k_alpha/alpha; epsilo - alpha; tau -epsilo*ta(alpha*phi_0; a ta(0.5.*phi; B ta(0.5.*epsilo.*phi./(0.5.*epsilo.*phi; b ta(0.5.*epsilo.*phi; z (cos(epsilo.*phi-ta(alpha.*phi_0.*si(epsilo.*phi./(w.*cos(phi; d (z.^(epsilo./alpha -./epsilo; i (2.*(a-b.*(+a.*b - phi.*tau.*b.*(b.*(-a.^2-2.*a.*(+epsilo.*d./((-a.^2.*(+b.^2+tau.*d; 2
plot(i; 40 20 0-20 -40-60 -80-00 -20-40 0 500 000 500 2000 2500 3000 3500 4000 4500 5000 22
MATLAB code for α N5000; phi (rad(,n-0.5*pi; a ta((0.5.*phi; i 2.*a./(-a.^2; plot(i 2000 500 000 500 0-500 -000 0 500 000 500 2000 2500 3000 3500 4000 4500 5000 23
PDF for differet α 24
The impulsiveess is due to the heavier tails, i.e., PDF go to zero slowly 25
AR, MA ad ARMA Processes MA process is geerated from x b w( + b w( + L + bn w( ( 0 N where { w( } is a white oise sequece. Oly the trasiet sigal is eeded to remove. e.g., for a secod-order MA process Q w ( 0, < 0 x ( b0w( + b w( x ( 0 b0w(0 + bw( b0w(0 x ( b0w( + bw(0 x ( 2 b0w(2 + bw(... The trasiet sigal is x(0. We should choose { x (, x(2, L} 26
MATLAB code for geeratig 50 samples of MA process with b, b 2: 0 b0; b2; N50; wrad(,n+; % geerate N+ white oise samples for :N x( b0*w(++b*w(; % shift w by oe sample ed Alteratively, we ca use the covolutio fuctio i MATLAB: b0; b2; N50; wrad(,n+; % geerate N+ white oise samples b [b0 b]; % b is a vector ycov(b,w; % sigal legth is N+ + 2 - xy(2:n+; % remove the trasiet sigals 27
From (.44, the PSD for MA process is Φ xx ( ω + 2e jω 2 σ 2 w + 2e jω 2 It ca be plotted usig the freqz commad i MATLAB: b0; b2; b [b0 b]; a; [H,W] freqz(b,a; % H is complex frequecy respose PSD abs(h.*h; plot(w/pi,psd; 28
9 8 7 6 5 4 3 2 0 0. 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 29
To evaluate the MA process geerated by MATLAB, we use (.38: 2 N jω Φ xx ( ω lim E x( e N N 0 N N 00 E {} average of 00 idepedet simulatios MATLAB code: N00; b [ 2]; % b is a vector for m:00 % perform 00 idepedet rus wrad(,n+; % geerate N+ white oise samples ycov(b,w; % sigal legth is N+ + 2 - xy(2:n+; % remove the trasiet sigals p(m,: abs(fft(x.*fft(x; ed psd mea(p./00; idex /50:/50:2; plot(idex,psd; axis([0,, 0 0]; 30
3
N N 0000 E {} average of 0000 idepedet simulatios 0 9 8 7 6 5 4 3 2 0 0 500 000 500 2000 2500 3000 3500 4000 4500 5000 32
Trasiet sigals are also eeded to remove i AR & ARMA processes because of o-statioarity due to the poles: x( ax( + a2 x( 2 + L + am x( M + w( x( a x( + b + 0 a w( 2 x( + b w( 2 + L + a M + L + b x( N w( e.g., for a first order AR process: x ( ax( + w( 2( m + a 2 Rxx (, m a + σ 2 w a ostatioary because R xx (, + m depeds o 2( + M N for sufficietly large, say, a <<, we ca cosider it statioary. sice a is the pole, extesio to geeral AR ad ARMA processes: 2( + i p <<, for all poles { } p i 33
2( + Suppose a 0. 000 is required ad the AR parameter is a 0. 9. The required is calculated as ( 0.9 2( + 0.9 2( + 0.000 43 MATLAB code for geeratig 50 samples of the AR process: M 43; N 50; a -0.9; y( 0; for 2:M+N y( a*y(-+rad; ed xy(m+:m+n; plot(x; 34
8 6 4 2 0-2 -4-6 0 5 0 5 20 25 30 35 40 45 50 35
Digital Filterig Give a iput sigal x ( ad the trasfer fuctio H (z, it is easy to geerate the correspodig output sigal, say, y ( For FIR system, we ca follow the MA process, while for IIR system, we ca follow the ARMA process. The trasiet sigals ca be removed if ecessary as i the MA, AR ad/or ARMA processes. Give H (z, the impulse respose ca be computed via iverse DTFT: h ( 2π π π H ( ω e jω d ω Frequecy spectrum for H (z impulse respose { h( } y( h( x( h( k x( k x( k h( k k k 36
Example 2.2 Compute the impulse respose for H d (z with the followig DTFT spectrum, ad ω 0. 2π ad ω 0. 4π. o c Η (ω d 0.5 π ω c ω o 0 ω o ω c π h d ( 2π 2π π π ω H c d ( ω e jω jω dω 0.5 e dω + ω c 2π ω o jω 0.5 e dω ω o si( ω c 2π + si( ω o 2π 37
si(0.2π + si(0.4π h d (, L,,0,, L 2π Note that h d (0 ca be obtaied by usig L Hospital s rule or: h d (0 Combiig the results: h d 2π 2π π H ( ω e dω π ω c 0.5dω + ω c d jω 0 2π ω o 2π 0.5dω ω o π π 0.3, ( si(0.2π + si(0.4π, 2π H ω d c ( ω dω + ω 2π o 0 otherwise 0.3 y( h ( x( x( k h ( k x( k h ( k d k d M k M d 38
Example 2.3 Compute the impulse respose of a time-shift fuctio which time-shifts a sigal by a o-iteger delay D. ( ( D x y exp( (, ( ( D j H X e Y D j ω ω ω ω ω sic( 2 2 ( 2 ( ( D d e d e e d e H h D j j D j j ω π ω π ω ω π π π ω π π ω ω π π ω where x x x π π si( sic( sic( ( sic( ( sic( ( ( D k k x D k k x D x y M M k k 39
Questios for Discussio. Observe that the followig sigal: y( 0 k 0 x( ksic( k D x( which depeds o future data { x( +, x( + 2, L, x( + 0}. This is referred to as a o-causal system. How to geerate the output of the o-causal system i practice? 2. The spectrum for the Hilbert trasform is D H ( ω j, j, 0 < ω π π ω < 0 Use a FIR filter with 5 coefficiets to perform the Hilbert trasform of a discrete-time sigal x []. Let the resultat sigal be y []. 40