EM Disc ch1 part1

Post on 04-Oct-2021

0 views 0 download

transcript

1

LOGO

LAB 3

Sampling

and

Quantization

3

Sampling Theorem

4

( ) ( )a sx t x nT

5

1( )s

n

X (t) = t nTT

1

( )s

ns

X (f) = f nfT

( )SX (t) = X t X (t)1

( )* ( )s s

n

X (f) = X f X (f) X f nfT

6

1( )

1 1 1 1 1....... ( 2 ) ( ) ( ) ( ) ( 2 ) .......

s s

n

s s s s s

X (f) = X f nfT

X f f X f f X f X f f X f fT T T T T

Sampled Signal

7

8

Ex: x(t)=5 cos (2pi*2000* t)3+‏ cos (2pi *3000* t)

Fs=8000 Hz

Fs> 2Fm=2*3000=6 kHZ

9

Ex: x(t)=5 cos (2pi*2000* t)3+‏ cos (2pi *5000* t)

Fs=8000 Hz

Fs< 2Fm=2*5000=10 kHZ

10

k k 1, 2, 3,......S = aliased baseF F F

11

Anti-aliasing Filter

12

Practical Parts

Part 1: Aliasing in Time Domain

a) Let Fs=10 kHz and Fo=1 kHz. Compute and

plot x[n] using stem.

130 10 20 30 40 50 60

-1

-0.5

0

0.5

1

14

b) Use subplot to plot x(t) for Fo=300 Hz and 700 Hz

15

0 1 2 3 4 5

x 10-3

-1

0

1

0 1 2 3 4 5

x 10-3

-1

0

1

16

c) Use subplot to plot x(n) for Fo=300 Hz and 700 Hz

17

0 10 20 30 40 50 60-1

-0.5

0

0.5

1

0 10 20 30 40 50 60-1

-0.5

0

0.5

1

18

d) Use subplot to plot x(t) for Fo=9700 Hz and 9300 Hz

19

0 1 2 3 4 5

x 10-3

-1

0

1

0 1 2 3 4 5

x 10-3

-1

0

1

20

c) Use subplot to plot x(n) for Fo=9700 Hz and 9300 Hz

21

0 10 20 30 40 50 60-1

-0.5

0

0.5

1

0 10 20 30 40 50 60-1

-0.5

0

0.5

1

22

k k 1, 2, 3,......S = aliased baseF F F

300 ( 1) 10000 =9700

700 ( 1) 10000 =9300

300 9700

700 9300

aliased

aliased

F

F

23

24

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

x 10-3

-1

-0.5

0

0.5

1

gives the same sample every one Ts

25

d) Use subplot to plot x(t) for Fo=10300 Hz and 10700 Hz

26

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

x 10-3

-1

-0.5

0

0.5

1

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

x 10-3

-1

-0.5

0

0.5

1

27

c) Use subplot to plot x(n) for Fo=10300 Hz and 10700 Hz

28

0 10 20 30 40 50 60-1

-0.5

0

0.5

1

0 10 20 30 40 50 60-1

-0.5

0

0.5

1

29

k k 1, 2, 3,......S = aliased baseF F F

300 ( 1) 10000 =10300

700 ( 1) 10000 =10700

300 9700 10300

700 9300 10700

aliased

aliased

F

F

30

Part 2: Aliasing in Frequency Domain

31

32

33

34

Part 3: Quantization

function y=uquant(x,n)

del=((max(max(x))-(min(min(x)))))/(n-1);

r=(x-min(min(x)))/del;

r=round(r);

y=r*del+min(min(x));

35

Example: Quantized x=2sin (2pi*t) using 16 levels.

max min 2 ( 2)4 /15

1 16 1

X Xdel

L

2

2

4

0

36

4

0

37

38

2

2

15

0

39

t=0:.001:1;

y=2*sin(2*pi*t)

figure(1)

subplot(311)

plot(y)

q1=uquant(y,4)

subplot(312)

plot(q1)

q2=uquant(y,32)

subplot(313)

plot(q2)

Ps=mean(y.^2);

Pq1=mean(q1.^2);

Pq2=mean(q2.^2);

SQR1=Ps/Pq1

SQR2=Ps/Pq2

40

0 200 400 600 800 1000 1200-2

0

2

0 200 400 600 800 1000 1200-2

0

2

0 200 400 600 800 1000 1200-2

0

2

41

Image Quantization

Exercise 1

42

clc

clear all

y1=imread('office_4.jpg');

y=rgb2gray(y1);

for i=1:7;

L=2^i;

Q=uquant(y,L);

i=i+1;

pause

L

figure(i)

imshow(Q)

end

43

b=1

44

b=2

45

b=3

46

b=4

47

b=5

48

b=6

49

b=7

50

clc

clear all

[y,fs]=wavread('speech_dft.wav');

sound(y,fs)

for b=1:7;

L=2.^b;

yQ=uquant(y,L);

pause

b

sound(yQ,fs);

end

Audio Quantization

51

Exercise 2

Audio Quantization

52

2 3 4 5 6 7 810

-2

10-1

100

101

102

103

104

plotting SNR

0 1 2 3 4 5 6 7 80

200

400

600

800

1000

1200

1400plotting SNR

53

Simulink model for sampling and quantization

54

Exercise 3

55

Q ua ntization error : ( ) ( ) ( )q qe n x n x n

2 2error

max minQuantization step =1

x x

L

0.1 0.1

2 2error

56

Quantization of sinusoidal signal

2 2

2 2

0 0

2 2

2

2

2

1 1P ( ) ( sin )

2 2

( ) for ( T t T )2

1 1P ( ( )) ( )

2 2

1

2 2

2

2

sig

q

T T

q q

T T

T

T

S t dt A wt dt

e t tT

e t dt t dtT T T

t dtT T

A

Average power of sinusoidal signal :

Average power of quantized signal :

2

12

57

Signal to quantization noise ratio

2

12

2

max min

2

2

2

2

2

the signal to quantization noise ratio

P

P

( ) 2

P 2

P

2

12

4

12

3

2

sig

q

sig

q

SQNR

x x A A A

L L L

A

SQNR

A

LA

L

58

Note:

Your report should include the following:

All Matlab program and its results with a short comment

on each result.

Answer any internal questions in practical parts.

Solve all lab exercises.

LOGO

59