DSP_Lab_2_slides_part2

LOGO
LAB 2
Sampling &
Quantization
Part 2
iugaza2010.blogspot.com
[email protected]
Part 2: Aliasing in Frequency Domain
2
Ex: x(t)=5 cos (2pi*2000* t)‫‏‬+3 cos (2pi *3000* t)
Fs=8000 Hz
Fs> 2Fm=2*3000=6 kHZ
Sampled Signal
3
Ex: x(t)=5 cos (2pi*2000* t)‫‏‬+3 cos (2pi *5000* t)
Fs=8000 Hz
Fs< 2Fm=2*5000=10 kHZ
4
Part 2: Aliasing in Frequency Domain
See the related video
5
6
7
8
9
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));
end
10
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
11
4
0
12
13
2
15
2
0
14
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
15
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
16
Image Quantization
Exercise 1
17
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
18
b=1
19
b=2
20
b=3
21
b=4
22
b=5
23
b=6
24
b=7
25
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
26
Audio Quantization
Exercise 2
semilogy
Hint : x=original signal , q=quantized signal , Error=x-q , SQNR=Px/PE , Px=mean(x.^2)
27
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
28
Simulink model for sampling and quantization
29
Exercise 3
30
31
Quantization
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
32
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 :

e q (t ) 
t for (  T  t  T )
2T
T
T
1
1
 2
2
Pq 
(e q (t )) dt 
( t ) dt 


2T T
2T T 2T
1   



2T  2T 
2

2
t
T dt  12
2 T
33
Signal to quantization noise ratio
the signal to quantization noise ratio
A2 
Psig  2 
SQNR 

Pq
 2 
 
 12 
x max  x min A  (A ) 2A



12
L
L
L
A2 


Psig
2
3
SQNR 
  2  L2
Pq
 4A  2

2 
12
L


2
3
SQNR (dB )  10log10 (SQNR )  10log10 ( 22b )  1.76  6.02b
2
34
If the desired sampling rate is lower than the sampling
rate of the available data, in this case, we may use
a process called downsampling.
Scaling
X(n) ={ ---- , 0 , 2 , 0 , 1 , 0 , ….}
X(n/3) ={ ---- , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , ….}
35
X(n) ={ ---- , 9 , 5 , 2 , 0 , 1 , 2 , 4 , 8 ,…..}
X(3n) ={ ---- , 0 , 0 , 0 , 9 , 0 , 4 , 0 , 0 , ….}
36
Example
If the original sequence with a sampling period T= 0.1 second (sampling rate =
10 samples per sec) is given by:
x(n) : 8 7 4 8 9 6 4 2 2 5 7 7 6 4 . . .
and we downsample the data sequence by a factor of 3, we obtain the
downsampled sequence as
y(m) =y(3n)= 8 8 4 5 6 . . .
with the resultant sampling period T = 3 x 0.1 = 0.3 second (the sampling rate
now is 3.33 samples per second).
37
By MATLAB, we can do this in an easy way. For example,
>> x=1:1:10
x=
1 2 3
4
5
>> x2=x(1:2:end)
x2 =
1 3 5 7
9
6
7
8
9
10
38
Anti-aliasing Filter
39
LOGO
40