0% found this document useful (0 votes)
3 views7 pages

Experiment 1

The document details Experiment 1 conducted by Kanishk Devatwal in February 2025, focusing on generating and plotting samples of a sine wave signal. It includes MATLAB code for signal generation, fixed-point representation, quantization comparisons, error plotting, and calculating Signal-to-Quantization Noise Ratio (SQNR) for different formats. The results indicate SQNR values for Q(2, 14), Q(4, 12), and Q(8, 4) as 98.64 dB, 87.36 dB, and 37.69 dB respectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Experiment 1

The document details Experiment 1 conducted by Kanishk Devatwal in February 2025, focusing on generating and plotting samples of a sine wave signal. It includes MATLAB code for signal generation, fixed-point representation, quantization comparisons, error plotting, and calculating Signal-to-Quantization Noise Ratio (SQNR) for different formats. The results indicate SQNR values for Q(2, 14), Q(4, 12), and Q(8, 4) as 98.64 dB, 87.36 dB, and 37.69 dB respectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment 1

Kanishk Devatwal
February 2025

1 Experiment-1
Question 1
To Generate and plot samples of x(t) = 2sin(2πf t)

f = 1kHz
Fs = 48kHz
Duration = 1Sec

Here is the matlab code to plot given samples:


Matlab Code:
f = 1000;
Fs = 4 8 0 0 0 ;
duration = 1;

t = 0 : 1 / Fs : d u r a t i o n ;

x t = 2 ∗ s i n (2 ∗ pi ∗ f ∗ t ) ;

num samples = round ( 5 ∗ Fs / f ) ;


t p l o t = t ( 1 : num samples ) ;
x p l o t = x t ( 1 : num samples ) ;

figure ;
plot ( t plot , x plot , ’b ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
t i t l e ( ’ Generated S i g n a l x ( t ) f o r 5 Cycles ’ ) ;
g r i d on ;
legend ( ’ x ( t ) = 2 s i n (2\ pi f t ) ’ ) ;

1
Figure 1: Sine wave samples for 1 Second Duration

Question 2
Converting the samples to fixed point formats of Q(2, 14), Q(4, 12), Q(8, 4)
MALAB Code:
x t = x t ( 1 : num samples ) ;

Q2 14 = round ( x t ∗ 2 ˆ 1 4 ) ;
Q4 12 = round ( x t ∗ 2 ˆ 1 2 ) ;
Q8 4 = round ( x t ∗ 2 ˆ 4 ) ;

x Q2 14 = Q2 14 / 2 ˆ 1 4 ;
x Q4 12 = Q4 12 / 2 ˆ 1 2 ;
x Q8 4 = Q8 4 / 2 ˆ 4 ;

figure ;
subplot (3 ,1 ,1);
p l o t ( t ( 1 : num samples ) , x Q2 14 , ’ r ’ ) ;
t i t l e ( ’ Fixed−P oi nt R e p r e s e n t a t i o n Q( 2 , 1 4 ) ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
g r i d on ;

subplot (3 ,1 ,2);

2
p l o t ( t ( 1 : num samples ) , x Q4 12 , ’ g ’ ) ;
t i t l e ( ’ Fixed−P oi nt R e p r e s e n t a t i o n Q( 4 , 1 2 ) ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
g r i d on ;

subplot (3 ,1 ,3);
p l o t ( t ( 1 : num samples ) , x Q8 4 , ’ b ’ ) ;
t i t l e ( ’ Fixed−P oi nt R e p r e s e n t a t i o n Q( 8 , 4 ) ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
g r i d on ;

Figure 2: Fixed Point Representation

Question 3
Plot the Quantized signal vs Original signal:
Matlab Code:
Q2 14 = round ( x t ∗ 2 ˆ 1 4 ) / 2 ˆ 1 4 ;
Q4 12 = round ( x t ∗ 2 ˆ 1 2 ) / 2 ˆ 1 2 ;
Q8 4 = round ( x t ∗ 2 ˆ 4 ) / 2 ˆ 4 ;

figure ;

subplot (3 ,1 ,1);

3
p l o t ( t p l o t , x t , ’ k ’ , ’ LineWidth ’ , 1 . 2 ) ; h o l d on ;
p l o t ( t p l o t , Q2 14 , ’ r − − ’);
t i t l e ( ’Q( 2 , 1 4 ) vs O r i g i n a l ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
l e g e n d ( ’ O r i g i n a l ’ , ’Q( 2 , 1 4 ) ’ ) ;
g r i d on ;

subplot (3 ,1 ,2);
p l o t ( t p l o t , x t , ’ k ’ , ’ LineWidth ’ , 1 . 2 ) ; h o l d on ;
p l o t ( t p l o t , Q4 12 , ’ g − − ’);
t i t l e ( ’Q( 4 , 1 2 ) vs O r i g i n a l ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
l e g e n d ( ’ O r i g i n a l ’ , ’Q( 4 , 1 2 ) ’ ) ;
g r i d on ;

subplot (3 ,1 ,3);
p l o t ( t p l o t , x t , ’ k ’ , ’ LineWidth ’ , 1 . 2 ) ; h o l d on ;
p l o t ( t p l o t , Q8 4 , ’ b− − ’);
t i t l e ( ’Q( 8 , 4 ) vs O r i g i n a l ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Amplitude ’ ) ;
l e g e n d ( ’ O r i g i n a l ’ , ’Q( 8 , 4 ) ’ ) ;
g r i d on ;

4
Figure 3: Quantized Signal vs Original signal

Question 4
Plot errors in each case:
Matlab Code:
Q2 14 = round ( x t ∗ 2 ˆ 1 4 ) / 2 ˆ 1 4 ;
Q4 12 = round ( x t ∗ 2 ˆ 1 2 ) / 2 ˆ 1 2 ;
Q8 4 = round ( x t ∗ 2 ˆ 4 ) / 2 ˆ 4 ;

e r r o r Q 2 1 4 = x t − Q2 14 ;
e r r o r Q 4 1 2 = x t − Q4 12 ;
e r r o r Q 8 4 = x t − Q8 4 ;

figure ;

subplot (3 ,1 ,1);
plot ( t plot , error Q2 14 , ’ r ’ ) ;
t i t l e ( ’ Q u a n t i z a t i o n E r r o r f o r Q( 2 , 1 4 ) ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Error ’ ) ;
g r i d on ;

subplot (3 ,1 ,2);
plot ( t plot , error Q4 12 , ’g ’ ) ;

5
t i t l e ( ’ Q u a n t i z a t i o n E r r o r f o r Q( 4 , 1 2 ) ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Error ’ ) ;
g r i d on ;

subplot (3 ,1 ,3);
plot ( t plot , error Q8 4 , ’b ’ ) ;
t i t l e ( ’ Q u a n t i z a t i o n E r r o r f o r Q( 8 , 4 ) ’ ) ;
x l a b e l ( ’ Time ( s ) ’ ) ;
y l a b e l ( ’ Error ’ ) ;
g r i d on ;

Figure 4: Error Plot for each case

6
Question 5

mean(x[n]2 )
SQN R =
mean(e[n]2 )
Matlab Code:
signal power = mean ( x t . ˆ 2 ) ;
error power Q2 1 4 = mean ( e r r o r Q 2 1 4 . ˆ 2 ) ;
error power Q4 1 2 = mean ( e r r o r Q 4 1 2 . ˆ 2 ) ;
error power Q8 4 = mean ( e r r o r Q 8 4 . ˆ 2 ) ;

SQNR Q2 14 = 10 ∗ l o g 1 0 ( s i g n a l p o w e r / e r r o r p o w e r Q 2 1 4 ) ;
SQNR Q4 12 = 10 ∗ l o g 1 0 ( s i g n a l p o w e r / e r r o r p o w e r Q 4 1 2 ) ;
SQNR Q8 4 = 10 ∗ l o g 1 0 ( s i g n a l p o w e r / e r r o r p o w e r Q 8 4 ) ;

f p r i n t f ( ’SQNR f o r Q( 2 , 1 4 ) : %.2 f dB\n ’ , SQNR Q2 14 ) ;


f p r i n t f ( ’SQNR f o r Q( 4 , 1 2 ) : %.2 f dB\n ’ , SQNR Q4 12 ) ;
f p r i n t f ( ’SQNR f o r Q( 8 , 4 ) : %.2 f dB\n ’ , SQNR Q8 4 ) ;
OUTPUT:
SQNR for Q(2, 14) : 98.64dB
SQNR for Q(4, 12) : 87.36dB
SQNR for Q(8, 4) : 37.69dB

You might also like