This action might not be possible to undo. Are you sure you want to continue?

**Digital Signal Processing
**

Part 3 Discrete-Time Signals & Systems Case Studies

S R Taghizadeh <srt@unl.ac.uk> January 2000

Introduction

Matlab and its applications in analysis of continuous-time signals and systems has been discussed in part 1 and 2 of this series of practical manuals. The purpose of part 3 is to discuss the way Matlab is used in analysis of discrete-time signals and systems. Each section provides a series of worked examples followed by a number of investigative problems. You are required to perform each of the worked examples in order to get familiar to the concept of Matlab environment and its important functions. In order to test your understanding of the concept of discrete-time signals & systems analysis, you are required to complete as many of the investigation / case study problems as possible. The areas covered are designed to enforce some of the topics covered in the formal lecture classes. These are:

q q q q q

Signal Generation and Presentation Discrete Fourier Transform Spectral analysis Autocorrelation and Cross correlation Time delay estimation

Digital Signal Processing Case Study Copyright-ãS.R.Taghizadeh

2

**Signal Generation and Manipulation
**

Sinusoidal Signal Generation Consider generating 64 samples of a sinusoidal signal of frequency 1KHz, with a sampling frequency of 8KHz. A sampled sinusoid may be written as:

x(n) = A sin( 2p f n + J) fs

where f is the signal frequency, fs is the sampling frequency, q is the phase and A is the amplitude of the signal. The program and its output is shown below: % Program: W2E1b.m % Generating 64 samples of x(t)=sin(2*pi*f*t) with a % Frequency of 1KHz, and sampling frequency of 8KHz. N=64; % Define Number of samples n=0:N-1; % Define vector n=0,1,2,3,...62,63 f=1000; % Define the frequency fs=8000; % Define the sampling frequency x=sin(2*pi*(f/fs)*n); % Generate x(t) plot(n,x); % Plot x(t) vs. t grid; title('Sinewave [f=1KHz, fs=8KHz]'); xlabel('Sample Number'); ylabel('Amplitude');

Sinewave [f=1KHz, fs=8KHz] 1 0.8 0.6 0.4 Am plitude 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 10 20 30 40 Sample Number 50 60 70

Digital Signal Processing Case Study Copyright-ãS.R.Taghizadeh

3

Note that there are 64 samples with sampling frequency of 8000Hz or sampling time of 0.125 mS (i.e. 1/8000). Hence the record length of the signal is 64x0.125=8mS. There are exactly 8 cycles of sinewave, indicating that the period of one cycle is 1mS which means that the signal frequency is 1KHz. Task: Generate the following signals (i) (ii) 64 Samples of a cosine wave of frequency 25Hz , sampling frequency 400Hz, amplitude of 1.5 volts and phase =0. The same signal as in (i) but with a phase angle of p/4 (i.e. 45o).

**Exercise 2: Exponential Signal Generation
**

Generating the signal x(t ) = e -0.1t for t = 0 to 40mS in steps of 0.1mS

% Program W2E2.m % Generating the signal x(t)=exp(-0.1t) t=0:0.1:40; x=exp(-0.1*t); plot(t,x); grid; title('Exponential Signal'); xlabel('Time [mS]'); ylabel('Amplitude'); And the output is:

Exponential Signal 1 0.9 0.8 0.7 A p d m litu e 0.6 0.5 0.4 0.3 0.2 0.1 0 0 5 10 15 20 Time [mS] 25 30 35 40

Digital Signal Processing Case Study Copyright-ãS.R.Taghizadeh

4

% Define the number of samples n=-(N/2):((N/2)-1).e.1 Sec Exercise 3: Unit Impulse Signal Generation An impulse is defined as follows: n=0 ì1 d ( n) = í î0 elsewhere 1 t The following Matlab program generates a unit impulse signal.4 0.8 0.2 0.7 A pt d m ue li 0.0.Task: Generate the signal: x(t ) = e -0. ylabel('Amplitude'). A Unit Impulse Signal 1 0.x). % Define a vector of sample numbers x=zeros(1.R.6 0.at t=0) plot(n. % Define a vector of zeros x((N/2)+1)=1. xlabel('Sample Number').Taghizadeh 5 .1t sin(0. % Program W2E3.1 0 -40 -30 -20 -10 0 10 Sample Number 20 30 40 Digital Signal Processing Case Study Copyright-ãS.6t ) for t = 0 to 40ms in steps of 0. title('A Unit Impulse Signal'). % Make the first sample to be 1 (i.5 0. % Plot the impulse grid.m % Generating 64 Samples of a unit impulse signal N=64.9 0.N).3 0.

(N/2)+1). % Plot the signal axis([-20.ones(1.5.-0.5]).5 -20 -15 -10 -5 0 5 Sample Number 10 15 20 Digital Signal Processing Case Study Copyright-ãS.R. % Define the number of samples n=-20:20.….u).Task: Generate 40 samples of the following signals: (for n=-20.19) (i) (ii) x(n)=2d(n-10) x(n)=5d(n-10)+2.+20. % Define a suitable discrete time axis u=[zeros(1.0. xlabel('Sample Number').-18.18.2.m % Generates 40 samples of a unit step signal. ylabel('Amplitude').…. u(n) N=40.5 0 -0.Taghizadeh 6 .5d(n-20) Exercise 4: Unit Step Signal Generation A step signal is defined as follows: n³0 ì1 u ( n) = í î0 otherwise The following Matlab Program generates and plots a unit step signal: % Program: W2E4.(N/2))]. % Generate the signal plot(n.1.3. % Scale axis grid.5 1 Am plitude 0. A Unit Step Signal 1. title('A Unit Step Signal').-19.1.

N]) are M-by-N matrices with random entries. Normally Distributed Random Numbers. randn(N) Is an N-by-N matrix with random entries. Random numbers are generated to represent the samples of some noise signal which is then added to the samples of some the wanted signal to create an overall noisy signal. s(n)=x(n)+w(n) Input. w(n) Matlab provides two commands. which may be applied to generate random numbers. y(n)@x(n) Noise. The situation is demonstrated by the following diagram. Digital Signal Processing Case Study Copyright-ãS. x(n) + S + Noise Cancellation algorithm Output. The input/ output spectrum may then be used to examine and measure the performance of noise canceller algorithm. randn(M. we need to create some signals which is contaminated by noise and then apply this signal to the algorithm and monitor its output. in order to simulate a particular noise cancellation algorithm (technique).R. chosen from a normal distribution with mean zero and variance one. For example. and randn([M.Taghizadeh 7 . Output.N).Task: Generate 40 samples of each of the following signals using an appropriate discrete time scale: (i) (ii) x(n)=u(n)-u(n-1) g(n)=u(n-1)-u(n-5) Exercise 5: Generating Random Signals Random number generators are useful in signal processing for testing and evaluating various signal processing algorithms.

subplot(2. xlabel('Sample Number'). grid. subplot(2. % Program: W2E5. ylabel('Amplitude'). rand(M. title('Histogram [Pdf] of a normal Random Signal'). Digital Signal Processing Case Study Copyright-ãS. rand(N) is an N-by-N matrix with random entries.2.1).N).2. title('Histogram [Pdf] of a uniformly Random Signal'). % Select the second qudrant hist(R1). hist(R2). % Select the figure subplot(2. xlabel('Sample Number'). ylabel('Amplitude').4). % Plot the histogram of R1 grid. % Subdivide the figure into 4 quadrants plot(R1). % Define Number of samples R1=randn(1.2.N]) are M-by-N matrices with random entries. subplot(2.m % Generates Uniformly and Normally Distributed random signals N=1024.1. xlabel('Sample Number'). % Plot R1 in the first quadrant grid. plot(R2). chosen from a uniform distribution on the interval (0.2.Taghizadeh 8 . xlabel('Sample Number'). % Generate Uniformly Random Numbers figure(1). grid. ylabel('Total').N).2). % Generate Normal Random Numbers R2=rand(1.3). The following Matlab program generates random signals using each distribution.0).R. title('Normal [Gaussian] Distributed Random Signal').Uniformly Distributed Random Numbers.0. ylabel('Total').N) and rand([M. title('Uniformly Distributed Random Signal').

5]. x(n) Z -D Here 'D' is the number of samples which the input signal must be delayed.5].Normal [Gaussian] Distributed Random Signal 4 2 Amplitude 200 0 -2 50 -4 0 200 400 600 800 Sample Number 1000 1200 0 -4 Total 150 100 300 250 Histogram [Pdf] of a normal Random Signal -2 0 Sample Number 2 4 Uniformly Distributed Random Signal 1 0. 2.R.2 0.3.0.8 Amplitude 0. 3. For example if x(n)=[1.Taghizadeh 9 .2 0 0 100 Total 50 0 200 400 600 800 Sample Number 1000 1200 150 Histogram [Pdf] of a uniformly Random Signal 0 0.0.6 Sample Number 0.1. then x(n-3)=[0.2. y(n)=x(n-D) Input. 4.4.6 0. Digital Signal Processing Case Study Copyright-ãS.4 0.8 1 Task: Generate 128 Uniformly random numbers between -p to +p Exercise 6: Signal Manipulation Some of the basic signal manipulation may be listed as follows: v Signal Shifting / Delay Output.4 0.

then the process is referred to as 'amplification' . If a>1.R. signals must have the same number of samples. If one signal has less than number of samples than the other. x1(n) Output. the process is referred to as 'attenuation'. y(n)=x1(n)+x2(n) Input. y ( n) = d x(t ) dt Input. x(t) d dt Differentiatin Output. x(t) ò Output. then this signal may be appended with zeros in order to make it equal length to the second signal before adding them. Integration y (n) = ò x(t )dt t1 t2 Digital Signal Processing Case Study Copyright-ãS.v Signal Addition / Subtraction Input. y(n)=ax(n) a 'a' is a numerical constant. v Signal Amplification / Attenuation Input. x1(n) + S + Output. v Signal Differentiation / Integration Input.Taghizadeh 10 . x2(n) When adding two signals together. if 0<a<1.

x2(n)'). y(n)=x1(n)*x2(n) Input. x3=sin(2*pi*(f3/fs)*n). plot(n. grid. f3=1500.20). title('Signal.2).v Signal Multiplication / Division Input. plot(n.1). subplot(2.3.x3). n=0:N-1.x1d).R. title('Signal. subplot(2. plot(n. f2=450. figure(1). grid. grid.1. x1(1:N-20)].3.3.1). Digital Signal Processing Case Study Copyright-ãS. x1=sin(2*pi*(f1/fs)*n). x1(n) + X + Output.Taghizadeh 11 . x2=(1/3)*sin(2*pi*(f2/fs)*n). x2(n) A Matlab program given below. title('Signal. plot(n.x2). provide an example of each of the above basic operations: % Program: W2E6.x1). fs=8000. x1(n)').3). % Signal Delay x1d=[zeros(1.4). x3(n)'). subplot(1. subplot(2. subplot(2. f1=150.3.m % Program demonstrating Basic Signal Manipulation N=128.

x1(n) 1 0. Signal. subplot(2.5 0 -0.5 -1 Signal.5 0 -0. grid.5 -1 1 0.5). [x1(n-20)]').5 -1 1 0. title('x1(n)+x2(n)').5 -1 0.2 -0.grid. % Signal Multiplication xmult=x1. plot(n.xadd).R. plot(xmult). title('Delayed x(n). x3(n) 0 100 200 0 100 x1(n)+x2(n) 200 0 100 x1*x3 200 Delayed x(n).5 -1 0 100 200 0 100 200 0 100 200 Digital Signal Processing Case Study Copyright-ãS. title('x1*x3').2 0 -0.Taghizadeh 12 .4 0.4 Signal.6).5 0 -0. subplot(2. grid. [x1(n-20)] 1 0.5 0 -0.3. x2(n) 1 0.3.*x3. % Signal Addition xadd=x1+x2.5 0 -0.

N-1 The magnitude of the X(k) [i.e. Use the above routine to determine and plot the DFT of the following signal: x( t ) = cos( 2pf 1t ) + cos( 2pf 2 t ) where f 1 = 1000 Hz and f 2 = 400 Hz . k=[0:1:N-1]. its Discrete Fourier Transform (DFT) is given by: N -1 n =0 X( k ) = å x( n )e .….Taghizadeh 13 .^ nk. Assuming x is the samples of the signal of length N.2. PhaseX=angle(Xk)*180/pi. WN=exp(-j*2*pi/N). Xk=x * WNnk.R. the absolute value] against k is called the spectrum of x(n). figure(1). and N = 128 Note: Plot the magnitude and phase of Xk as follows: MagX=abs(Xk). then a simple Matlab program to perform the above sum is shown below: n=[0:1:N-1]. Digital Signal Processing Case Study Copyright-ãS. with Fs = 8000 Hz . The values of k is proportional to the frequency of the signal according to: fk = kFs N Where Fs is the sampling frequency. nk=n'*k.1.j 2pnk / N k=0. WNnk=WN .Discrete Fourier Transform [1] Given a sampled signal x(n).

512)]. Append a further 512 zeros to x(n) as shown below: [Note the number of samples.1. subplot(2.1. 64 and 512.subplo(2.2.…. nk=n'*k. Comment on the results Set 128 and generate x(n) for n=0. WN=exp(-j*2*pi/N). WNnk=WN .R. [2] Inverse DFT is defined as: 1 N N -1 k =0 x ( n) = å X ( k )e j 2pnk / N for 0 £ n £ N . Investigate: (i) (ii) (iii) (iv) (v) At what value of the index k does the magnitude of the DFT of x has major peaks.MagX).^ (-nk). Perform the above for N=32. zeros(1. Explain the effect of zero padding a signal with zero before taking the discrete Fourier Transform. k=[0:1:N-1].2).1. Digital Signal Processing Case Study Copyright-ãS.1).1 A simple Matlab routine to perform the inverse DFT may be written as follows: n=[0:1:N-1].N-1. What is the corresponding frequency of the two peaks. x=(Xk * WNnk)/N.Taghizadeh 14 . plot(k.PhaseX). N=128+512=640]. Perform the DFT of the new sequence and plot its magnitude and phase. Xe=[x. plot(k. Compare with the previous result.

Spectral Analysis of a signal Let x( t ) = cos( 2pf 0 t ) where f 0 = 30 Hz . % windowing (i. assuming the sampling frequency f s = 128 Hz and N = 256 samples .* xh'. Digital Signal Processing Case Study Copyright-ãS. xlabel('Frequency.e. Which windowed signal shows the smaller peak sidelobe?. [dB]'). Use the IDFT to transfer the DFT results (i. A Matlab program implementing the spectrum is shown below: f1=30. XH=abs(fft(xw. % Sampling frequency N=256. plot(f(1:N1/2). Hz').20*log10(XR(1:N1/2)/max(XR))). subplot(2. Record the Magnitude and phase of the DFT.1.1}. Which windowed signal shows a narrower mainlobe?. % Number of samples N1=1024.1. % Generate the signal XR=abs(fft(x. % find the magnitude of the FFT using No xh=hamming(N).1). % Start plotting the signal subplot(2. title('Spectrum of x(t) using Hamming Windows'). determine the DFT.20*log10(XH(1:N1/2)/max(XH))). Hz').N1)). obtain the FFT of the windowed signal using rectangular and hamming windows. [dB]').Taghizadeh 15 . xlabel('Frequency. Rectangular window) % Define the hamming samples % Window the signal % find the magnitude of the FFT of the % windowed signal.2). % Signal frequency fs=128. grid. % Defining the frequency points [axis] x=cos(2*pi*f1*n/fs). ylabel('Normalised Magnitude. and N=4. Plot the normalised FFT magnitude of the windowed signals. % Number of FFT points n=0:N-1. zero padded to N1=1024. ylabel('Normalised Magnitude. grid.e.N1)).R.1.Use x(n)={1. title('Spectrum of x(t) using Rectangular Windows'). xw=x . plot(f(1:N1/2).1. Xk sequence) to its original sequence. % Index n f=(0:N1-1)*fs/N1.

returns the N-point Hanning window in a column vector. Hz Spectrum of x(t) using Hamming Windows 20 60 70 Normalised Magnitude.beta) triang(N) returns the N-point Bartlett window returns the N-point Blackman window returns the N-point rectangular window returns the N-point Hamming window. Hz 50 60 70 It can be seen from the spectrum plots that both the rectangular window and hamming window have their peak amplitude at f=30Hz corresponding to the signal frequency. [dB] 0 -100 -200 -300 -400 0 10 30 40 50 Frequency.And here is the output from the program: Spectrum of x(t) using Rectangular Windows Normalised Magnitude.Taghizadeh 16 . Further Spectral Analysis The spectrum of a signal is simply a plot of the magnitude of the components of a signal against their corresponding frequencies. returns the N-point triangular window. returns the BETA-valued N-point Kaiser window. hamming window provides less peak sidelobes than the rectangular window. There are many other types of windows which are available as Matlab functions and are listed below: bartlett(N) blackman(N) boxcar(N) hamming(N) hanning(N) kaiser(N. While the rectangular window has a narrower mainlobe.R. [dB] 0 -50 -100 -150 0 10 20 30 40 Frequency. For example if a signal consists of two Digital Signal Processing Case Study Copyright-ãS.

% Now scale it so that it represents frequencies in Hz figure(1). Digital Signal Processing Case Study Copyright-ãS. magX=abs(X).1.1.20*log10(magX(1:N/2))). % Estimate its spectrum using fft command X=fft(x). n=0:N-1. % Now generate the sinusoidal signal x=sin(2*pi*(f/fs)*n). plot(fx. % first make a vector for f=0. Here is the program: N=256. xlabel('Frequency (Hz)'). % Total Number of Samples fs=8000. title('Spectrum of a sinusoidal signal with f=1KHz').R. % Sampling frequency set at 1000Hz f=1000. Task 1: Generate 256 samples of a sinusoidal signal of frequency 1KHz with a sampling frequency of 8KHz.. we illustrate their use.2.(N/2)-1 fx=(fx*fs)/N. then ideally the spectrum would be a plot of magnitude vs.. grid..Taghizadeh 17 .1). frequency and would contain two peaks: one at 60 Hz and the other at 120 Hz illustrated in the next example. Plot the signal and its spectrum. The following Matlab commands are the basis of determining the spectrum of a signal: fft psd spectrum In the following examples. One of the most important aspects of spectral analysis is the interpretation of the spectrum and its relation to the signal under investigation. ylabel('Magnitude (dB)').sinusoidal at 120Hz and 60Hz. % Build up an appropriate frequency axis fx=0:(N/2)-1. subplot(1.

windowing effects.R. the notch filter in the previous section. The transfer function of the notch filter is repeated here for convenience: Digital Signal Processing Case Study Copyright-ãS. that the signal consists of a single sinusoidal components of frequency 1000Hz. Other artefacts in the figure are due to the limited number of samples.Taghizadeh 18 . and computation accuracy. Task 1: Consider.And the output: Spectrum of a sinusoidal signal with f=1KHz 50 0 -50 -100 -150 -200 -250 -300 -350 Magnitude (dB) 0 1000 2000 Frequency (Hz) 3000 4000 It is clear from the spectrum.

% Sampling frequency set at 1000Hz f1=120. x(n) 1 . figure(1). with f1=120 Hz .9937].m clear.Input. the fs fs sampling frequency at 1000Hz.fx]=psd(x.2*N. [pxx. Digital Signal Processing Case Study Copyright-ãS. xlabel('Frequency. b=k*b. ylabel('Magnitude.2 impulse response.Taghizadeh 19 . x=sin(2*pi*(f1/fs)*n)+sin(2*pi*(f2/fs)*n).9937 z . Hz'). Plot the followings: Input Spectrum Magnitude response of the filter Output Spectrum Here is the Matlab Program: % Program Name: Tut16.1.9969 1 . a=[1 -1. h(n) Output. f2=60 Hz and fs . y(n) Apply an input signal: x(n) = sin( 2pf1n 2pf n ) + sin( 2 ) .9969. n=0:N-1. subplot(1. subplot(1.1).1.20*log10(pxx)).R.1. b=[1 -1.fs). % Total Number of Samples fs=1000. sin(2*pi*(f2/fs)*n).8537 z -1 + 0. title('Magnitude Spectrum of x(n)').8596 1]. N=1024. f2=60.8537 0.8996 z -1 + z -2 H ( z ) = 0.3. grid. plot(fx. k=0. dB').1).

% Calculates the phase angle of the filter subplot(1. xlabel('Frequency.20*log10(pxx)).x). % of % the filter with coefficients 'b' % and 'a'. dB'). [pyy. Hz').fx]=psd(x. dB').2).3).Taghizadeh 20 . % Plot the output spectrum in dB grid. [h. ylabel('Magnitude. subplot(1. plot(fx. The function % returns the values of the transfer % function h.f]=freqz(b. for each frequency in % f in Hz.fs).2*N. % Divides the figure into two rows and one % column and makes the first row the active % one plot( f. xlabel('Frequency. % Add a grid % Determines the frequency response title('Magnitude Response of the Notch Filter'). ylabel('Magnitude. % plots the magnitude in dB against % frequency grid.2*N.20*log10(pyy)).3. figure % determine the Spectrum using 'psd' % Select the third column in the plot(fy.R.a.[pxx.fy]=psd(y.a. % Calculates the magnitude of the filter phaseH=angle(h).3.fs). magH=abs(h).1024. using 1024 points around % the unit circle with a sampling % frequency of fs. y=filter(b. Here is the output from the program: Digital Signal Processing Case Study Copyright-ãS. % Add a grid title('Magnitude Spectrum of y(n)'). xlabel('Frequency'). ylabel('Magnitude. grid. dB'). Hz'). 20*log10(magH)). title('Magnitude Spectrum of x(n)').fs).

The Matlab Program and its output is shown next: % Program Name: Tut17. N=1024. n=0:N-1.R. f3=1500. Therefore. dB 0 200 400 Frequency 600 Magnitude. that the input signal consists of two sinusoidal components at 60Hz and 120Hz. dB -20 -40 -40 -60 -60 0 200 400 Frequency. f2=1000. Hz 600 It can be seen from the plot. From the magnitude response of the filter. and f3=1500Hz. it is clear that the filter attenuates components whose frequencies are at 60 Hz. the output spectrum consists of the 120 Hz signal and attenuated (0 dB) signal at 60Hz. Task 3: Consider estimating the spectrum of a signal consisting of three sinusoidal signals at frequencies. % Sampling frequency set at 1000Hz f1=500.Taghizadeh 21 . Hz 600 -80 0 200 400 Frequency. % Generate the signal Digital Signal Processing Case Study Copyright-ãS. Assume a sampling frequency of 8KHz.m clear. f2=1000Hz. % Total Number of Samples fs=8000. A final example considers the use of the Matlab command 'spectrum' in order to estimate the spectrum of a given signal. dB -20 Magnitude. f1=500Hz.Magnitude Spectrum of x(n) 40 Magnitude Response of the Notch Filter Magnitude Spectrum of y(n) 2 40 0 20 -2 0 -4 -6 -8 -10 -12 -14 -80 -16 -100 -18 20 0 Magnitude.

% Plot the spectrum grid.Taghizadeh 22 .N).R. % Estimate the Spectrum specplot(pxx.fs). dB 10 -5 10 -10 10 -15 0 500 1000 1500 2000 2500 Frequency. And the output: 10 5 Power Spectrum of x(n) 10 0 Magnitude. Hz'). xlabel('Frequency. Hz 3000 3500 4000 Digital Signal Processing Case Study Copyright-ãS. title('Power Spectrum of x(n)'). ylabel('Magnitude. pxx=spectrum(x.x=sin(2*pi*(f1/fs)*n)+sin(2*pi*(f2/fs)*n)+sin(2*pi*(f3/fs)*n). dB').

its autocorrelation function is written as: R xx ( t ) = lim 1 T ® ¥ 2T ò-T x( t )x( t + t )dt T (1) Where T is the period of observation.Autocorrelation and Crosscorrelation in Matlab Both in signal and Systems analysis. R xx ( t ) is always real-valued and an even function with a maximum value at t = 0 . the autocorrelation is defined as either biased or unbiased defined as follows: : R xx ( m ) = 1 N-m 1 N N .R.m +1 n =1 å x( n )x( n + m . we present some simple examples of how these two functions may be estimated in Matlab.1 ) [Biased Autocorrelation] (2) R xx ( m ) = N . The final part of this section provides some applications of autocorrelation and crosscorrelation functions in signal detection and time-delay estimations.2. Consider a random process x(t) (i.m +1 n =1 å x( n )x( n + m . For sampled signal (i.1 ) [Uniased Autocorrelation] for m=1. the concept of autocorrelation and crosscorrelation play an important role.Taghizadeh 23 . continuous-time). In the following sections.e.…. The autocorrelation function of a random signal describes the general dependence of the values of the samples at one time on the values of the samples at another time. sampled signal).e.M+1 Digital Signal Processing Case Study Copyright-ãS.

1 ) (5) m=1.m +1 n =1 å y( n )x( n + m . The properties of cross correlation function are listed in table 1. Some of its properties are listed in table 1..R. it is defined as: R yx ( m ) = 1 N N ..2..Taghizadeh 24 .N+1 Where N is the record length (i.2.where M is the number of lags.e. number of samples). The cross correlation function however measures the dependence of the values of one signal on another signal. For two WSS (Wide Sense Stationary) processes x(t) and y(t) it is described by: R xy ( t ) = lim 1 T ®¥ T ò-T x( t ) y( t + t )dt T (3) or R yx ( t ) = lim 1 T ®¥ T ò-T y( t )x( t + t )dt T (4) where T is the observation time. Digital Signal Processing Case Study Copyright-ãS.1. For sampled signals.3.

x( n . Furthermore E [ x( n ) .Autocorrelation Properties [1] Maximum Value: The magnitude of the autocorrelation function of a wide sense stationary random process at lag m is upper bounded by its value at lag m=0: R xx ( 0 ) ³ R xx ( k ) for k ¹ 0 [2] Periodicity: If the autocorrelation function of a WSS random process is such that: R xx ( m 0 ) = R xx ( 0 ) for some m 0 . [3] The autocorrelation function of a periodic signal is also periodic: Example: if x( n ) = A sin( w 0 n + j ) . then R xx ( m ) is periodic with period m 0 .Taghizadeh 25 . the autocorrelation sunction is symmetric: R xx ( m ) = R xx ( -m ) [5] Mean Square Value: The autocorrelation function of a WSS process at lag. is equal to the meansquare value of the process: Digital Signal Processing Case Study Copyright-ãS. R xx ( m ) = Therefore if w 0 = square periodic. m=0.R. [4] Symmetry: The autocorrelation function of WSS process is a conjugate symmetric function of m: 2 A2 cos( w 0 m ) 2 2p . then. then R xx ( m ) is periodic with periodic N and x(n) is meanN R xx ( m ) = R * ( -m ) xx For a real process.m 0 ) ] = 0 and x(n) is said to be mean-square periodic.

[2] R xy ( m ) may not necessarily have a maximum at m=0 nor R xy ( m ) an even function.Taghizadeh 26 .) value of a WSS process is given by: mean . [3] R xy ( -m ) = R yx ( m ) [4] R xy ( m ) 2 £ R xx ( 0 )R yy ( 0 ) 1 R xx ( 0 ) + R yy ( 0 ) 2 [5] R xy ( m ) £ [ ] [6] When R xy ( m ) = 0 . x(n) and y(n) are Sid to be ‘uncorrelated’ or they are said to be statistically independent (assuming they have zeros mean. x = R xx ( ¥ ) Table 1.1 Properties of cross correlation function Digital Signal Processing Case Study Copyright-ãS.c.1 Properties of Autocorrelation function Properties of cross correlation function [1] R xy ( m ) is always a real valued function which may be positive or negative. then the autocorrelation of the sum x(n)=s(n)+w(n) is equal to the sum of the autocorrelations of s(n) and w(n): R xx ( m ) = R ss ( m ) + R ww ( m ) [7] The mean value: The mean or average value (or d.R.R xx ( 0 ) = E x( n ) { 2 }³ 0 [6] If two random processes x(n) and y(n) are uncorrelated.) Table 1.

An important point to remember when using the function xcorr is that the origin is in the middle of the figure (here it is at lag=1024). % Prepare a time axis subplot(2.1).x). ylabel('Amplitude'). it has double the number of samples as the signal x(n). % Generate the signal. % Sampling Frequency n=0:N-1. % Prepare the figure plot(Rxx).R. Its use is indicated in the following examples: Example 1: Autocorrelation of a sinewave Plot the autocorrelation sequence of a sinewave with frequency 1 Hz. Digital Signal Processing Case Study Copyright-ãS. [s]'). title('Autocorrelation function of the sinewave').1.2). Rxx=xcorr(x). The output of this program is shown next. % Frequency of the sinewave FS=200. xlable('lags'). ylabel('Autocorrelation'). % Plot the autocorrelation grid. grid.m which may be used to implement both auto and cross correlation function.1. The Matlab program is listed below: N=1024. % Prepare the figure plot(t. % Estimate its autocorrelation subplot(2.Taghizadeh 27 . Notice that when using the function xcorr. x(n) t=[1:N]*(1/FS). % Number of samples f1=1. to estimate the autocorrelation sequence .Matlab Implementation Matlab provides a function called xcorr. % Sample index numbers x=sin(2*pi*f1*n/FS). xlabel('Time. % Plot x(n) title('Sinwave of frequency 1000Hz [FS=8000Hz]'). sampling frequency of 200 Hz.

R.Digital Signal Processing Case Study Copyright-ãS.Taghizadeh 28 .

Rxx=zeros(1.Sinwave of frequency 1000Hz [FS=8000Hz] 1 0. Here is a how it may be written: function [Rxx]=autom(x) % [Rxx]=autom(x) % This function Estimates the autocorrelation of the sequence of % random variables given in x as: Rxx(1). end. [s] Autocorrelation function of the sinewave 2 5 6 1000 Autocorrelation 500 0 -500 0 500 1000 lags 1500 2000 2500 Note that if you want to write your own autocorrelation function. N=length(x).….N). for m=1: N+1 for n=1: N-m+1 Rxx(m)=Rxx(m)+x(n)*x(n+m-1). where N is % Number of samples in x. you may use equation (2) to do this. Digital Signal Processing Case Study Copyright-ãS.Taghizadeh 29 .R.5 -1 0 1 3 4 Time. end.5 Amplitude 0 -0. Rxx(2).Rxx(N).

title('Sinwave of frequency 1000Hz [FS=8000Hz]'). Note this version of estimating the autocorrelation function generates the same number of samples as the signal itself and that the maximum is now placed at the origin.To use the above function. x=sin(2*pi*f1*n/FS). n=0:N-1. xlabel('Time. ylabel('Autocorrelation').m and then it may be used as follows: N=1024. f1=1.1). subplot(2. grid. plot(Rxx).Taghizadeh 30 . title('Autocorrelation function of the sinewave').2). (Rxx(1) is the origin).x). Rxx=autom(x). grid. subplot(2. Digital Signal Processing Case Study Copyright-ãS. xlabel('lags'). ylabel('Amplitude').R.1.1. plot(t. [s]'). FS=200. you need to save this under autom. t=[1:N]*(1/FS).

5 -1 0 1 2 3 Time.1). grid. % Sampling index x=sin(2*pi*f1*n/FS). % Frequency of the sinewave FS=200. title('Pure Sinewave').Sinwave of frequency 1000Hz [FS=8000Hz] 1 0. % Generate y(n) subplot(3. subplot(3. N=1024. unit variance of Gaussina random process.N). % Number of samples to generate f=1. Digital Signal Processing Case Study Copyright-ãS. plot(x).Taghizadeh 31 .R. [s] 4 5 6 Autocorrelation function of the sinewave 600 400 Autocorrelation 200 0 -200 -400 -600 0 200 400 600 lags 800 1000 1200 Example 2: Crosscorrelation Plot the crosscorrelation of the following signal: x( n ) = sin( 2pf 1t ) y( n ) = x( n ) + w( n ) with f 1 = 1Hz where w(n) is a zeros mean. % Generate x(n) y=x+10*randn(1. % Sampling frequency n=0:N-1.5 Amplitude 0 -0.1.2).1.

5 -1 40 20 0 -20 -40 500 0 200 400 600 Cross correlation Rxy 800 1000 1200 0 200 400 600 800 y(n). title('y(n).5 0 -0.Taghizadeh 32 .1. title('Cross correlation Rxy'). grid.R. The output is: Pure Sinewave 1 0.plot(y).3). Rxy=xcorr(x. % Estimate the cross correlation subplot(3. Pure Sinewave + Noise 1000 1200 0 -500 0 500 1000 1500 2000 2500 Digital Signal Processing Case Study Copyright-ãS. grid. Pure Sinewave + Noise'). plot(Rxy).y).

Question [1] From the results shown for example 2. prove that its autocorrelation function is given by: A2 R xx ( t ) = cos( wt ) 2 Explain this result. Question [2] Given x( n ) = A sin( w 0 t + J ) .R. Digital Signal Processing Case Study Copyright-ãS.Taghizadeh 33 . what function cross correlation has performed.

D seconds) . The objective is to measure (estimate) the time delay between the transmitted and the returned signal.D ) + w( t ) A pulse x(t) is transmitted. noisy and attenuated.Case Study Time Delay Estimation Processing Radar Returned Signal Consider a simple radar illustration shown below: The Target Transmitted signal.D ) + w( t ) Digital Signal Processing Case Study Copyright-ãS.Taghizadeh 34 . r(t) Transmitting & Receiving Dish r( t ) = ax( t . the reflected signal from an object is returned to the receiver. x(t) Returned signal.e. The returned signal (r(t)) is delayed (i.R. Analysis: Let the transmitted signal be x(t). then the returned signal r(t) may be modelled as: r( t ) = ax( t .

where: w(t) is assumed to be the additive noise during the transmission. R wx ( t ) = 0 This is also stated in table 1. the cross correlation R rx ( t ) is equal to the sum of the scaled autocorrelation function of the transmitted signal (i. D is the delay which is the time taken for the signal to travel from the transmitter to the target and back to the receiver.D ) + R wx ( t ) (6) Note.e. A common method of estimating the time delay D is to compute the cross-correlation function of the received signal with the transmitted signal x(t). If we now assume that the noise signal w(t) and the transmitted signal x(t) are uncorrelated then. Hence the cross-correlation function between the transmitted signal and the received signal may be written as: R rx ( t ) = aR xx ( t .2 under the property number [6]. a is the attenuation factor (<1).D)x(t + t ) + w(t)x(t + t )} a Hence R rx ( t ) = aR xx ( t . R rx ( t ) = E{r( t )x( t + t )} = E{[ax(t .D ) (7) Digital Signal Processing Case Study Copyright-ãS. Therefore.e. ‘E’ is the expectation operator. aR xx ( t ) ) and the cross correlation function between x(t) and the contaminated noise signal w(t).D) + w(t)][x( t + t )]} = E{ x(t .Taghizadeh 35 . i.R.

Taghizadeh 36 . it will only have one peak value that will occur at t = D . A typical plot of R rx ( t ) is shown below: Crosscorrelation Rrx 350 300 250 200 150 100 50 0 -50 -100 0 50 100 150 200 250 300 Estimated Time Delay as number of samples Investigation [1] Generate a single pulse for the transmitted signal as shown below: x(n) 5 n N=256 0 n=4 Digital Signal Processing Case Study Copyright-ãS.R.Therefore if we plot R rx ( t ) .

call this xd(n) as shown below: xd(n) 5a n N=256 0 n=34 [3] [4] Generate N=256 samples of Gaussian random signal and call this w(n). .d ) + sigman ´ w( n ) Where sigman is the noise amplitude (initially set this to 1.x). Appropriately label and grid the each plot. r( n ) = ax( n . [5] using subplot(2. plot the signals x(n).[2] Delay the signal by say 32 samples and reduce its amplitude by an attenuation factor of say a = 0. Generate the simulated received signal by adding the transmitted signal x(n) and the noise signal w(n). . R=Y(1:N). This can be done as follows: % Assuming there are N samples of x Y=xcorr(r. plot only half the samples of the cross correlation sequence returned by the function xcorr. Rrx=fliplr(R). xd(n).Taghizadeh 37 . [6] Estimate the cross-correlation sequence Rrx ( m ) and plot in the fourth quadrant of the figure. i. Note .2.7 .1). and r(n). Digital Signal Processing Case Study Copyright-ãS.e.R.

jwD Therefore by having an estimate of the cross spectral function of the transmitted and the received signal.[7] From the plot estimate the delay. Does it agree with the theoretical delay value? [8] [9] Repeat the simulation for some values of a .Taghizadeh 38 .R. and N? Comment on your findings? Time delay Estimation in Frequency Domain Consider the returned signal once again: r( t ) = ax( t . sigman.jwD + W ( w ) Or taking the Fourier Transform of the cross correlation of r(t) and x(t) gives: Prx ( w ) = aPxx ( w )e . we can estimate the time delay from its phase: Phase = wD = 2pfD Digital Signal Processing Case Study Copyright-ãS. we get: Pxr ( w ) = aPxx ( w )e .D ) + w( t ) Taking the Fourier transform of both sides yields: Pr ( w ) = aX ( w )e .jwD + Pwx ( w ) Assuming that the transmitted signal and the contaminated noise are uncorrelated.

f 1 =1Hz.5 )) + w( t ) ) Plot x(t) and y(t). % Estimation of time delay using the phase of the Cross Spectrum Prx=csd(x. % Unwrap the phase plot(phase). x( t ) = sin( 2pf 1t ) ) Generate a received signal r(t) as follows: r(t) is also a sinusoidal of the same frequency whose amplitude has been attenuated by 0. Use a sampling frequency.R.Hence by taking the slope of the phase (i. we have the slope of the d( f ) Slope = 2pD Or D= Slope 2p Here is how you may estimate the cross spectrum between the transmitted signal and the received signal and to obtain the phase plot.(i.01. Fs =200Hz. % Get the phase phase=unwrap(pha). r( t ) = 0. % Estimate the Cross Spectrum pha=angle(Prx). x(t).5 sin( 2pf 1 ( t . Add white noise with zero mean and a variance of 0. and call this signal the transmitted signal.5 and delayed by 2. phase which may be written as: d Phase ). Digital Signal Processing Case Study Copyright-ãS.e. % Plot the phase Investigation Generate N=256 samples of a sinusoidal signal of amplitude 1 volts. frequency.r). (i.e.5 Seconds.Taghizadeh 39 .e.2.

R. The autocorrelation of x(t) and r(t). From this plot estimate the delay time (Time where it peaks) and compare to the theoretical value of 2. Repeat the experiment for the noise variance of 0.Taghizadeh 40 . From the phase plot. Estimate the attenuation factor using: q q q a= R xr ( D ) Value of the peak at t = D = R xx ( 1 ) The peak value of the Autocorrelation of x(t) Compare this value to the theoretical value of 0.1. and 0.5.0.8.5s. The cross correlation between x(t) and r(t). This method is described in the appendix for those interested.] Slope q q q Digital Signal Processing Case Study Copyright-ãS. estimate the slope of the plot in the following table: N 128 256 512 1024 What is the relationship between the time delay and the slope of the phase? [Note: That yet another method of estimating the time delay is via a system identification approach. 0.4.Estimate and plot: The spectrum of the transmitted signal and the received signal. Estimate the error in each case. The cross spectral density and phase between x(t) and r(t).

m0=[1 1 1 0 0 0].y(n) and the input. Digital Signal Processing Case Study Copyright-ãS.zeros(1.e.a]=yulewalk(4. delta=[1. [h.N)].Taghizadeh 41 . y(n) “The cross correlation of the output . % Now find the impulse response N=32. % apply the impulse as input subplot(2.1024). % Plot the normalize impulse response title('True impulse response').e.FH.f]=freqz(b.R. Here is a Matlab program which performs the above simulation: % M_ex4 % By: saeed Reza Taghizadeh [January 2000] % Application of cross correlation in System Analysis % Defining a simple low pass filter FS=2500.1. x(n) Input. plot(h/max(h)).Application of Correlation Functions in System Analysis Theorem: For a linear time-invariant system: Linear Time Invariant System h(n) Input.delta). FH=fHz/(FS/2). R yx ( m ) ] is equal to its impulse response when the input is white noise”. [b. i.a. R yx ( m ) = h( n ) when x(n) is zero mean unit variance white Gaussian Noise The objective of this part of the case study is to illustrate this property.1). fHz=[0 250 500 750 1000 1250].m0). % define an impulse h=filter(b.a. x(n) [i.

grid.4 0 5 10 15 20 25 30 35 Digital Signal Processing Case Study Copyright-ãS. plot(Ryx/max(Ryx)).x).a.x).R. % Now use the cross correlation % Define the input for i=1: 128 % Performs the experiment 128 times x=randn(1.4 0. % Plot the estimated impulse response title('Estimated Impulse Response'). Which produces the following output: True impulse response 1 0. % Get the appropriate portion PA(:.i)=Ryx'. % Average over all the runs subplot(2.8 0. % Clear the variable Ryx Ryx=sum(PA')/128. % Apply it to the filter to find the output ryx=xcorr(y.Taghizadeh 42 .6 0.2 0 -0.2 0 -0.N). % Generate white noise y=filter(b.8 0.2).2 -0. clear Ryx. % Save the results end.4 0.grid.2 -0. % Estimate the cross correlation Ryx=fliplr(ryx(1:N)).4 0 5 10 15 20 25 30 35 Estimated Impulse Response 1 0.1.6 0.

1/5. b=[1/5.Taghizadeh 43 . you must perform a simulation over a number of runs and average the results for the final outcome. plot(f. the experiment will not be valid for simply one run.1 ) + x( n .256).H). 1/5.4 )] 5 For this system: Draw the filter structure.R. H=abs(h).2 ) + x( n . hence as shown in the program. Use: q q q Digital Signal Processing Case Study Copyright-ãS. Investigation A digital filter is described by the following transfer function: One of the most simplest and yet effective digital filters are ‘avergers’. 1/5]. For example a 5-point averager is defined as: y( n ) = 1 [x( n ) + x( n . the simulation is carried out for 128 times and the final result is the average of the all the runs.Note that the cross correlation technique produces a good estimate of the impulse response of the system. Use: a=1. 1/5.f]=freqz(b. Plot its impulse response. This is a system which computes the average of previous q-samples of its input.3 ) + x( n . When simulating with random processes.a. Note also that since the input is white noise and being random. [h. Use Matlab to plot its frequency response. f=f/(2*pi).

N-1)]. q q q q Determine the poles and zeros diagram. zeros(1. he). [Use Matlab to confirm] Digital Signal Processing Case Study Copyright-ãS.delta). Investigation For each of the following systems.Taghizadeh 44 . Digital filters play an important role in every digital audio or video equipment. plot the frequency and phase response using Matlab.a.e. plot(ht).: Determine the difference equation Determine the transfer function H ( z ) of the system. Some simple digital filters are to be examined in this section both analytically and via simulation. q q q Comment on your results.N=128.R.e ht) – The estimated impulse response (i. Use the cross correlation procedure illustrated above to estimate its impulse response by applying white noise with zero mean and unit variance and plot its response (call this the estimated response. delta=[1. he). Plot the error as E= The true response (i. ht=filter(b. [Use Matlab to confirm] Determine the impulse response of the system.

+ S + Z -1 2 -6 + input x(n) + S Output y(n) [Case Number 1] Z -k x(n) K=4. 5. 5.R. 6 + + S y(n) [Case Number 3] Digital Signal Processing Case Study Copyright-ãS.Taghizadeh 45 . 6 + + S y(n) [Case Number 2] Z -k -1 x(n) K=4.

r(t) From the theory of cross correlation.e. D) may be extracted from its transfer function. Pxr ( w ) is equal to the transfer function H ( w ) times the power spectrum of the input signal.” We therefore have: H(w ) = Pxr ( w ) Pxx ( w ) Having obtained the transfer function of the model. the information concerning the estimation of delay (i.R. x(t) Input.Taghizadeh 46 . we assume that the transmitted signal r(t) is the output of a linear time-invariant system whose input is the transmitted signal x(t). we model a system whose transfer function characteristic processes x(t) in a way as to produce the transmitted signal r(t) in its output.Appendix A System Identification approach in Time Delay estimation Here. Linear Time Invariant System H(w) Input.Pxx ( w ) Which states that “The cross spectrum of the input-output. we have: Pxr ( w ) = H ( w ). Pxx ( w ) . Another word. the followings may be obtained: Digital Signal Processing Case Study Copyright-ãS. Once this is done. Here is the mathematical analysis of the above procedure.

e.Taghizadeh 47 . Digital Signal Processing Case Study Copyright-ãS.R. .a = H(w ) f ( w ) = ÐH ( w ) = ÐPxr ( w ) The time delay (i.D) may be obtained from the slope of the phase angle f ( w ) as before.

R.Taghizadeh 48 .Digital Signal Processing Case Study Copyright-ãS.

Sign up to vote on this title

UsefulNot useful- Matlab Signal Representation Examples
- Signals Matlab
- Matlab Signal Processing
- signals and systems using matlab
- Signal Processing in MATLAB
- 05 CM0340Tut MATLAB Synthesis
- DSP for MATLAB™ and LabVIEW™ I Fundamentals of Discrete Signal Processing
- Matlab in signal processing
- Temel Elektronik Devreler Ders Notu
- Matlab Manual
- mr book
- Digital Signal Processing Using Matlab Solution Manual PDF
- Digital Signal Processing Using MATLAB
- DSP Using Matlab v.4 Solution
- Signal System Objective
- Elektromanyetik Alan Teorisi - Gebze Teknik Üniversitesi Doç. Dr. Gökhan ÇINAR Ders Notları
- Real-Time Digital Signal Processing
- Dsp Using Matlab® - 4
- Digital Signal Processing Using Matlab
- Elektromanyetik Alan Teorisi - Aslan INAN [2010-2011 Defter Notu]
- 7043378 Matlab Programs
- Digital Signal Processing Lab Manual
- VHDL Programs
- Digital Signal Processing Lab Mannual
- Matlab
- Lecture 1
- Digital Signal Processing
- Matlab Signal

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.