0% found this document useful (0 votes)
5 views3 pages

Example2 Comm w4

The document discusses quantizing and sampling an analog signal using 3 bits. It generates a sample signal by sampling a sine wave every 0.05 seconds. It then partitions the signal range into 8 levels and quantizes the samples to the closest level. The quantized values and original signal are plotted. Finally, the sample indexes are converted to binary codes.

Uploaded by

AAA AAA
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)
5 views3 pages

Example2 Comm w4

The document discusses quantizing and sampling an analog signal using 3 bits. It generates a sample signal by sampling a sine wave every 0.05 seconds. It then partitions the signal range into 8 levels and quantizes the samples to the closest level. The quantized values and original signal are plotted. Finally, the sample indexes are converted to binary codes.

Uploaded by

AAA AAA
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/ 3

Example 2:

An example analog signal is given as between [s]

clc;
clear all;

Sample this analog signal each 0.05 s and quantize using 3 bits.

3-bits gives us number of quantization value (n).

n=2^3

n = 8

Then sample the signal:

t = [0:.05:1] % Times at which to sample the sine function

t = 1×21
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500

sig = 0.99*sin(2*pi*t) % Original continuous signal, a sine wave

sig = 1×21
0 0.3059 0.5819 0.8009 0.9415 0.9900 0.9415 0.8009

plot(t,sig)

1
Partion values between -1 and +1 and space 2/(n-1)

partition = [-1:2/7:1] % Length 8

partition = 1×8
-1.0000 -0.7143 -0.4286 -0.1429 0.1429 0.4286 0.7143 1.0000

codebook = [-(1):2/8:(1)] % Length 9, one entry for each interval

codebook = 1×9
-1.0000 -0.7500 -0.5000 -0.2500 0 0.2500 0.5000 0.7500

[index,quants] = quantiz(sig,partition,codebook); % Quantize.


quants

quants = 1×21
0 0.2500 0.5000 0.7500 0.7500 0.7500 0.7500 0.7500

plot(t,sig,'x',t,quants,'.')
legend('Original signal','Quantized signal');
axis([-0.1 1.1 -1.2 1.1])

2
Binary Codes

bindat=dec2bin(index)

bindat = 21×3 char array


'100'
'101'
'110'
'111'
'111'
'111'
'111'
'111'
'110'
'101'
'100'
'011'
'010'
'001'
'001'
'001'
'001'
'001'
'010'
'011'
'100'

You might also like