Professional Documents
Culture Documents
Signal Processing
Signal Processing
Signal Processing
Quantization Noise
Jay Soni
12040700
1
MATLAB Code
1 % Given Parameters
2 f = 1000; % Frequency
3 Fs = 48000; % Sampling Frequency
4 duration = 1; % Duration
5 t = 0:1/ Fs : duration ; % Time Vector
6 x = 2* sin (2* pi * f * t ) ; % Given Signal
7
1 % Q (2 ,14)
2 q2_14 = fi (x ,1 ,16 ,12) ;
3
4 % Q (4 ,12)
5 q4_12 = fi (x ,1 ,16 ,12) ;
6
7 % Q (8 ,4)
8 q8_4 = fi (x ,1 ,12 ,4) ;
2
Code To Convert To Fixed Point Format
MATLAB Code
1 figure ;
2
3 subplot (3 ,1 ,1) ;
3
4 plot ( t (1: samples_to_plot ) , x (1: samples_to_plot ) , ’
b - ’ , t (1: samples_to_plot ) , q2_14 (1:
samples_to_plot ) , ’r : ’) ;
5 xlabel ( ’ Time ( seconds ) ’) ;
6 ylabel ( ’ Amplitude ’) ;
7 title ( ’ Original vs Q (2 ,14) Quantized Signal ’) ;
8 legend ( ’ Original ’ , ’ Quantized ’) ;
9 grid on ;
10
11 subplot (3 ,1 ,2) ;
12 plot ( t (1: samples_to_plot ) , x (1: samples_to_plot ) , ’
b - ’ , t (1: samples_to_plot ) , q4_12 (1:
samples_to_plot ) , ’g : ’) ;
13 xlabel ( ’ Time ( seconds ) ’) ;
14 ylabel ( ’ Amplitude ’) ;
15 title ( ’ Original vs Q (4 ,12) Quantized Signal ’) ;
16 legend ( ’ Original ’ , ’ Quantized ’) ;
17 grid on ;
18
19 subplot (3 ,1 ,3) ;
20 plot ( t (1: samples_to_plot ) , x (1: samples_to_plot ) , ’
b - ’ , t (1: samples_to_plot ) , q8_4 (1:
samples_to_plot ) , ’y : ’) ;
21 xlabel ( ’ Time ( seconds ) ’) ;
22 ylabel ( ’ Amplitude ’) ;
23 title ( ’ Original vs Q (8 ,4) Quantized Signal ’) ;
24 legend ( ’ Original ’ , ’ Quantized ’) ;
25 grid on ;
4
Figure 6: Error for Q(4,12)
MATLAB Code
5 figure ;
6
7 subplot (3 ,1 ,1) ;
8 plot ( t (1: samples_to_plot ) , error_q2_14 (1:
samples_to_plot ) , ’r ’) ;
9 xlabel ( ’ Time ( seconds ) ’) ;
10 ylabel ( ’ Error ’) ;
11 title ( ’ Error for Q (2 ,14) ’) ;
12 grid on ;
13
14 subplot (3 ,1 ,2) ;
15 plot ( t (1: samples_to_plot ) , error_q4_12 (1:
samples_to_plot ) , ’g ’) ;
16 xlabel ( ’ Time ( seconds ) ’) ;
17 ylabel ( ’ Error ’) ;
18 title ( ’ Error for Q (4 ,12) ’) ;
19 grid on ;
20
5
21 subplot (3 ,1 ,3) ;
22 plot ( t (1: samples_to_plot ) , error_q8_4 (1:
samples_to_plot ) , ’y ’) ;
23 xlabel ( ’ Time ( seconds ) ’) ;
24 ylabel ( ’ Error ’) ;
25 title ( ’ Error for Q (8 ,4) ’) ;
26 grid on ;
MATLAB Code
6
1 SQNR_q2_14 = mean ( abs ( x ) .^2) / mean ( abs (
error_q2_14 ) .^2) ;
2 SQNR_q4_12 = mean ( abs ( x ) .^2) / mean ( abs (
error_q4_12 ) .^2) ;
3 SQNR_q8_4 = mean ( abs ( x ) .^2) / mean ( abs ( error_q8_4 )
.^2) ;
4