Top Banner
MULTIMEDIA UNIVERSITY OF KENYA FACULTY OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ELECTRICAL AND COMMUNICATION ENGINEERING (ECE) BSC. TELECOMMUNICATION AND INFORMATION ENGINEERING NAME: MARTIN WACHIYE WAFULA REG. NO: ENG-211-075/2012 UNIT CODE: ETI 2505 UNIT NAME: DIGITAL SIGNAL PROCESSING (DSP) LECTURER: MR. JOSIAH MAKICHE Date of Submission: 5 th October,2016 TITLE: MATLAB ASSIGNMENT 1 - SAMPLING AND RECONSTRUCTION OF ANALOG SIGNALS
12

DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

Jan 23, 2018

Download

Engineering

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

MULTIMEDIA UNIVERSITY OF KENYA

FACULTY OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF ELECTRICAL AND COMMUNICATION ENGINEERING

(ECE)

BSC. TELECOMMUNICATION AND INFORMATION ENGINEERING

NAME: MARTIN WACHIYE WAFULA

REG. NO: ENG-211-075/2012

UNIT CODE: ETI 2505

UNIT NAME: DIGITAL SIGNAL PROCESSING (DSP)

LECTURER: MR. JOSIAH MAKICHE

Date of Submission: 5th October,2016

TITLE: MATLAB ASSIGNMENT 1 - SAMPLING AND

RECONSTRUCTION OF ANALOG SIGNALS

Page 2: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

Objectives

1. To study the sampling principle and the effect of sampling on the frequency-domain

quantities

2. To study several approaches of reconstruction

Introduction

DSP provides alternative method for processing analog signals. In DSP applications, real world

analog signals are converted into discrete signals using sampling and quantization operations

called analog-to-digital conversion or ADC. These discrete signals are processed by the digital

signal processors, and the processed output signals are converted into analog signal using a

reconstruction operation called digital-to-analog conversion or DAC.

Fig1: Block diagram of a digital signal processing system

The relationship between an analog signal and its discrete time sampled version is necessary to

understand the operation of DSP system. This relationship in time domain is given by:

x(n) = xa (nTs)

where Ts is the sampling interval. This relation can also be shown in the frequency domain using

the Fourier analysis.

The continuous time Fourier transform is given by

dtetxFX Ftj

aa

2)()( .

The inverse continuous time Fourier transform is given by

dFeFXtx Ftj

aa

2)()( .

The discrete time Fourier transform is given by

n

fnjenxfX 2)()( .

The inverse discrete time Fourier transform is given by

dFeFXtx Ftj

aa

2)()( .

The relation between Xa(F) and X(f) is given by

k

sas FkfXFfX ))(()( .

Page 3: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

where Fs is a sampling frequency = 1/Ts. In other words, X(f) consists of infinite numbers of

copies of scaled Xa(F) separated by frequency interval f = 1. From the relation between discrete

time and analog frequencies

sF

Ff

we get

k

sas

s

kFFXFF

FX )()(

in which )(sF

FX consists of infinite numbers of copies of scaled Xa(F) separated by interval F =

Fs.

Sampling Principle

To avoid aliasing, a band-limited signal xa(t) with bandwidth B can be reconstructed from

its sample values x(n) = xa(nTs) if the sampling frequency Fs = 1/Ts is greater than twice the

bandwidth B of xa(t).

BFs 2

Otherwise aliasing would result in x(n). The sampling rate of 2B for an analog band-limited

signal is called the Nyquist rate.

Reconstruction

From the sampling theorem and the above examples it is clear that if we sample band-

limited xa(t) above its Nyquist rate, then we can reconstruct xa(t) from its samples

x(n). Using an interpolation formula:

))((sinc)()( ss

n

a nTtFnxtx

where x

xx

)sin()(sinc is an interpolating function derived from an ideal low pass

reconstruction filter. However, since an ideal low pass reconstruction filter cannot be

implemented, we usually estimated the ideal low pass filter by the following methods:

Zero-order-hold (ZOH) interpolation: In this interpolation a given sample value is held for the sample interval until the next sample is received.

( ) ( ), ( 1)a s sx t x n nT t n T

which can be obtained by filtering the impulse train through an interpolating filter of the

form

Page 4: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

s

0

1 0 t<T( )

0 otherwiseh t

which is a rectangular pulse. The resulting signal is a piecewise-constant (staircase)

waveform which requires an appropriately designed analog post-filter for accurate

waveform reconstruction.

x(n) xa(t) xa(t)

First-order-hold (FOH) interpolation: In this case the adjacent samples are joined by straight lines. This can be obtained by filtering the impulse train through

s

1

1 0

( )1 2

0 otherwise

s

s s

s

tt T

T

h t tT t T

T

Procedure

1. Sampling xa (t) at Fs = 50 samples/sec

ZOH Post-Filter

Page 5: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

1. %xa(t)= exp(-10|t|) 2. %CTFT is given by Xa(F) =

[(2*10)/(10^2 + (2*pi*F)^2)]

3. %sampling xa(t) at Fs = 50 samples/sec

4. clear all 5. tmin = -1; 6. tmax = 1; 7. %Analog signal 8. t = tmin: 0.001: tmax; 9. xa = exp(-10*abs(t)); 10. %Sampling

rate(sample/second)

11. Fs = 50;

12. %Sample period

13. Ts = 1/Fs;

14. %Discrete time signal

15. n = tmin/Ts:tmax/Ts;

16. x = exp(-10*abs(n*Ts));

17. %Display signal in time

domain

18. figure(1)

19. subplot(211)

20. plot(t,xa)

21. title('Analog and

Discrete Time Signals')

22. xlabel('time(sec)')

23. ylabel('Analog Signal

x(t)')

24. subplot(212)

25. stem(n,x)

26. xlabel('n')

27. ylabel('Discrete time

signal x(n)')

28. %Computing FT

29. %Analog frequency (Hz)

30. F = -100:0.1:100;

31. W = (2*pi*F);

32. %DT Frequency

(circles/sample)

33. f = F/Fs;

34. w = 2*pi*f;

35. %Analog spectrum for

CTFT

36. XaF = 2.*(10./(10^2+

W.^2));

37. %DTFT

38. XF = x * exp(-1i*n'*w);

39. %Display spectra in

frequency domain

40. figure(2)

41. subplot(311)

42. plot(F,abs(XaF))

43. title('spectra of

signals')

44. xlabel('Freq(circle/sec

)')

45. ylabel('Original

Xa(F)')

46. subplot(312)

47. plot(F,abs(XF))

48. xlabel('Freq(circle/sec

)')

49. ylabel('X(F/Fs)')

50. subplot(313)

51. plot(f,abs(XF))

52. xlabel('Freq(circle/sec

)')

53. ylabel('X(f)')

54. %Display spectra in the

fundamental range

55. figure(3)

56. subplot(211)

57. plot(F,abs(XaF))

58. plot(F,abs(XF))

59. title('spectra in the

fundamental range')

60. xlabel('Freq(circle/sec

)')

61. ylabel('X(F/Fs)')

62. v = axis;

63. v(1:2) = [-Fs/2 Fs/2];

64. axis(v)

65. subplot(212)

66. plot(f,abs(XF))

67. xlabel('Freq(circle/sec

)')

68. ylabel('X(f)')

69. v = axis;

70. v(1:2) = [-1/2 1/2];

71. axis(v)

Experimental results

Page 6: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

Explanation:

We have superimposed the discrete signal x(n) over x(t) to emphasize the sampling. The plot

shows that it is a scaled version (scaled by Fs = 50) of X(F). Clearly there is no aliasing.

Q2. Reconstruction of xa(t)

72. %Reconstruction of

xa(t)

73. t = tmin:0.001:tmax;

74. figure(4)

75. clf

76. subplot(211)

77. hold on

78. stem(n*Ts,x,'r')

79. for i= 1:size(x,2)

80. xsinc(i,:) =

x(i)*sinc(Fs*(t-(i+min(n)-

1)*Ts));

81. plot(t,xsinc(i,:))

82. end

83. title('Signal

reconstruction')

84. xlabel('time(second)')

85. ylabel('x(n)*Sinc(Fs*(t

-nTs))')

86. hold off

87. xar = sum(xsinc);

88. subplot(212)

89. plot(t,xar,'b-

',t,xa,'r:')

90.

91. legend('Reconstructed

signal','Origin signal')

92. ylabel('Reconstructed

signal xa(t)')

93.

94. xlabel('time (second)')

95. %reconstruction error

96. maxerror = max(abs(xa-

xar));

Experimental Results

Page 7: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

Explanation:

The maximum error between the reconstructed and the actual analog signal is 0.0380. This is

because xa(t) is not strictly band-limited and we also have a finite number of samples. From the

reconstructed figure above, we note that visually the reconstruction is excellent.

Q3. For Fs = 10 samples/cycle, the results are as shown below:

Page 8: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

Explanation:

Here Fs = 10 < 20. There is considerable amount of aliasing. From the figure above, this is

evident since shape of x(n) is different from that of Xa(F) and can be seen as adding overlapping

replicas of Xa(F).

Explanation:

The maximum error between the reconstructed and the actual analog signals is 0.1852, which is

significant and cannot be attributed to the nonband-limitedness of xa(t) alone. From Figure

above, the reconstructed signal differs from the actual one in many places over the interpolated

regions. This is the visual demonstration of aliasing in the time domain. (Proakis, 2012)

Reason why Fs = 50 samples/sec is better than Fs = 10 samples/sec:

- Since the bandwidth of xa(t) = 20Hz, the Nyquist rate Fo = 40 Hz according to the

Sampling theorem. To prevent aliasing, the analog signal should be sampled at a rate

higher than twice the highest frequency in the analog signal.

- Therefore, for Fs = 50 Hz > Fo there is no aliasing hence better compared Fs = 10

samples/sec < Fo . (Manolakis, 1996)

Q4. xa(t) = sin(20πt), 0≤ t ≤ 1. Samples at Ts = 0.01, 0.03, 0.05, 0.07 and 0.1

a) For each Ts, x(n) was plotted.

MATLAB Code

1. tmin = 0; 2. tmax = 1; 3. %Analog signal 4. t = tmin: 0.001: tmax; 5. xa = sin(20*pi*t); 6. %Sample period 7. Ts1 = .01; 8. %Discrete time signal

9. n1 = tmin/Ts1:tmax/Ts1; 10. x1 = sin(20*pi*n1*Ts1);

11. %Display signal in time

domain

12. figure(5)

13. subplot(211)

14. plot(t,xa)

Page 9: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

15. title('Analog and

Discrete Time Signals')

16. xlabel('time(sec)')

17. ylabel('Analog Signal

x(t)')

18. subplot(212)

19. stem(n1,x)

20. xlabel('n1')

21. ylabel('Discrete time

signal x1(n)')

22. Ts2 = .03;

23. %Discrete time signal

24. n2 = tmin/Ts2:tmax/Ts2;

25. x2 = sin(20*pi*n2*Ts2);

26. %Display signal in time

domain

27. figure(6)

28. subplot(211)

29. plot(t,xa)

30. title('Analog and

Discrete Time Signals')

31. xlabel('time(sec)')

32. ylabel('Analog Signal

x(t)')

33. subplot(212)

34. stem(n2,x2)

35. xlabel('n2')

36. ylabel('Discrete time

signal x2(n)')

37. Ts3 = .05;

38. %Discrete time signal

39. n3 = tmin/Ts3:tmax/Ts3;

40. x3 = sin(20*pi*n3*Ts3);

41. %Display signal in time

domain

42. figure(7)

43. subplot(211)

44. plot(t,xa)

45. title('Analog and

Discrete Time Signals')

46. xlabel('time(sec)')

47. ylabel('Analog Signal

x(t)')

48. subplot(212)

49. stem(n3,x3)

50. xlabel('n3')

51. ylabel('Discrete time

signal x3(n)')

52. Ts4 = .07;

53. %Discrete time signal

54. n4 = tmin/Ts4:tmax/Ts4;

55. x4 = sin(20*pi*n4*Ts4);

56. %Display signal in time

domain

57. figure(8)

58. subplot(211)

59. plot(t,xa)

60. title('Analog and

Discrete Time Signals')

61. xlabel('time(sec)')

62. ylabel('Analog Signal

x(t)')

63. subplot(212)

64. stem(n4,x4)

65. xlabel('n4')

66. ylabel('Discrete time

signal x4(n)')

67. Ts5 = .1;

68. %Discrete time signal

69. n5 = tmin/Ts5:tmax/Ts5;

70. x5 = sin(20*pi*n5*Ts5);

71. %Display signal in time

domain

72. figure(9)

73. subplot(211)

74. plot(t,xa)

75. title('Analog and

Discrete Time Signals')

76. xlabel('time(sec)')

77. ylabel('Analog Signal

x(t)')

78. subplot(212)

79. stem(n5,x5)

80. xlabel('n5')

81. ylabel('Discrete time

signal x5(n)')

Page 10: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

For Ts = 0.01, figure 5, Ts = 0.03 figure 6, Ts = 0.05 figure 7, Ts = 0.07 figure 8 and Ts = 0.1

figure 9 were plotted.

(b) Reconstruction of ya(t) code (Proakis, 2012)

Page 11: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

(c) Results

The maximum error between the reconstructed and the actual analog signal is 0.0013. This is

because xa(t) is not strictly band-limited and there is a finite number of samples. From the

reconstructed figure above, we note that visually the reconstruction is excellent.

QUESTIONS

1. What is the MATLAB function that would be used to plot a staircase (ZOH) interpolation

of the analog signal?

stairs(n * Ts * frequency, x);

hold on

stem(n* Ts * frequency, x);

hold off

(Proakis, 2012)

2. What is the MATLAB function that would be used to plot a staircase (ZOH) interpolation

of the analog signal?

plot(n * Ts * frequency, x);

hold on

stem(n* Ts * frequency, x);

hold off

(Proakis, 2012)

3. From the experiment, describe why minimum sampling rate must be at least twice the

bandwidth of an analog signal?

Page 12: DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB

To avoid aliasing

Explanation of the function of each part of DSP system above:

ADC - The output of the A /D converter is a digital signal that is appropriate as an input to the

digital processor. ADC coverts continuous time signal into discrete time signals through

sampling and quantization

The digital signal processor- may be a large programmable digital computer or a small

microprocessor programmed to perform the desired operations on the input signal. It may also be

a hard wired digital processor configured to perform a specified set of operations on the input

signal.

DAC – converts the digital output of the processor into analog signal. This is called

reconstruction.(Manolakis, 1996)

References Manolakis, J. G. (1996). Digital Signal Processing - Principles, Algorithms and Applications (Third ed.).

New Jersey, USA: Prentice Hall International-Inc.

Proakis, V. K. (2012). DIGITAL SIGNAL PROCESSING USING MATLAB (3rd ed.). Stamford, USA: Cengage

Learning.