Uploaded by Yasmeen Mezyed

Lab2 (2)

advertisement
1
LOGO
LAB 3
Sampling
and
Quantization
Sampling Theorem
3
x a (t )  x (nT s )
4
1
X  (t) =
T

  (t  nT
n 
s
)
X S (t) = X (t )X  (t)
1
X  (f) =
Ts

  (f
n 
1
X s (f) = X (f ) * X  (f) 
T
 nf s )

 X (f
n 
 nf s )
5
Sampled Signal
1 
X s (f) =
X (f  nf s )

T n 
1
1
1
1
1
 .......  X (f  2f s )  X (f  f s )  X (f s )  X (f  f s )  X (f  2f s )  .......
T
T
T
T
T
6
7
Ex: x(t)=5 cos (2pi*2000* t)‫‏‬+3 cos (2pi *3000* t)
Fs=8000 Hz
Fs> 2Fm=2*3000=6 kHZ
8
Ex: x(t)=5 cos (2pi*2000* t)‫‏‬+3 cos (2pi *5000* t)
Fs=8000 Hz
Fs< 2Fm=2*5000=10 kHZ
9
Faliased  Fbase  k FS
k =  1,  2,  3,......
10
Anti-aliasing Filter
11
Practical Parts
Part 1: Aliasing in Time Domain
a) Let Fs=10 kHz and Fo=1 kHz. Compute and
plot x[n] using stem.
12
1
0.5
0
-0.5
-1
0
10
20
30
40
50
60
13
b) Use subplot to plot x(t) for Fo=300 Hz and 700 Hz
14
1
0
-1
0
1
2
3
4
5
-3
x 10
1
0
-1
0
1
2
3
4
5
-3
x 10
15
c) Use subplot to plot x(n) for Fo=300 Hz and 700 Hz
16
1
0.5
0
-0.5
-1
0
10
20
30
40
50
60
0
10
20
30
40
50
60
1
0.5
0
-0.5
-1
17
d) Use subplot to plot x(t) for Fo=9700 Hz and 9300 Hz
18
1
0
-1
0
1
2
3
4
5
-3
x 10
1
0
-1
0
1
2
3
4
5
-3
x 10
19
c) Use subplot to plot x(n) for Fo=9700 Hz and 9300 Hz
20
1
0.5
0
-0.5
-1
0
10
20
30
40
50
60
0
10
20
30
40
50
60
1
0.5
0
-0.5
-1
21
Faliased  Fbase  k FS
k =  1,  2,  3,......
Faliased  300  (1) 10000 =9700
Faliased  700  (1) 10000 =9300
300  9700
700  9300
22
23
1
0.5
0
-0.5
-1
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
gives the same sample every one Ts
-3
x 10
24
d) Use subplot to plot x(t) for Fo=10300 Hz and 10700 Hz
25
1
0.5
0
-0.5
-1
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
-3
x 10
1
0.5
0
-0.5
-1
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
-3
x 10
26
c) Use subplot to plot x(n) for Fo=10300 Hz and 10700 Hz
27
1
0.5
0
-0.5
-1
0
10
20
30
40
50
60
0
10
20
30
40
50
60
1
0.5
0
-0.5
-1
28
Faliased  Fbase  k FS
k =  1,  2,  3,......
Faliased  300  (1) 10000 =10300
Faliased  700  (1) 10000 =10700
300  9700  10300
700  9300  10700
29
Part 2: Aliasing in Frequency Domain
30
31
32
33
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));
34
Example: Quantized x=2sin (2pi*t) using 16 levels.
2
4
2
0
X max  X min 2  (2)
del 

 4 /15
L 1
16  1
35
4
0
36
37
2
15
2
0
38
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
39
2
0
-2
0
200
400
600
800
1000
1200
0
200
400
600
800
1000
1200
0
200
400
600
800
1000
1200
2
0
-2
2
0
-2
40
Image Quantization
Exercise 1
41
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
42
b=1
43
b=2
44
b=3
45
b=4
46
b=5
47
b=6
48
b=7
49
Audio Quantization
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
50
Audio Quantization
Exercise 2
51
plotting SNR
plotting SNR
4
1400
10
1200
3
10
1000
2
10
800
1
10
600
0
10
400
-1
10
200
0
-2
0
1
2
3
4
5
6
7
8
10
2
3
4
5
6
7
8
52
Simulink model for sampling and quantization
53
Exercise 3
54
x max  x min
Quantization step = 
L 1
Quantization error : eq (n )  x q (n )  x (n )


  error 
2
2

0.1
0.1
 error 
2
2
55
Quantization of sinusoidal signal
Average power of sinusoidal signal :
Psig
1

2
2
1
2
0 S (t )dt  2
2
2
A
2
(
A
sin
wt
)
dt 
0
2
Average power of quantized signal :

eq (t ) 
t for (  T  t  T )
2T
T
T
1
1
 2
2
Pq 
(eq (t )) dt 
( t ) dt 


2T T
2T T 2T
1   



2T  2T 
2

2
t
T dt  12
2 T
56
Signal to quantization noise ratio
the signal to quantization noise ratio
 A2 
Psig  2 
SQNR 

Pq
 2 
 12 
 12 
2
x max  x min A  ( A ) 2A



L
L
L
 A2 


Psig
2
3 2


SQNR 

 L
2
Pq
 4A  2

2 
 12L 
57
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.
58
LOGO
59
Download