0% found this document useful (0 votes)
26 views4 pages

Code Segment:: All All

This document contains code to simulate signal quantization and encoding. It samples a signal, quantizes the sample values, encodes the quantized values into binary, decodes and reconstructs the signal. Plots show the original and processed signals. An error curve is also plotted, showing quantization error decreases as bitrate increases but saturates after a point. For a example with lower sample rate, the encoded and decoded signals are also displayed.

Uploaded by

Saidur Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Code Segment:: All All

This document contains code to simulate signal quantization and encoding. It samples a signal, quantizes the sample values, encodes the quantized values into binary, decodes and reconstructs the signal. Plots show the original and processed signals. An error curve is also plotted, showing quantization error decreases as bitrate increases but saturates after a point. For a example with lower sample rate, the encoded and decoded signals are also displayed.

Uploaded by

Saidur Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Code segment:

close all
clear all
clc
fs=.0001;
b=3;
xa=0:.00001:.05;
ya=f(xa);
subplot(2,3,1),plot(xa,ya);
%sampling
x=0:fs:.05;
y=f(x);
subplot(2,3,2),stem(x,y);
%quantization
a=min(y):((max(y)-min(y))/(2^b-1)):max(y);
for i=1:length(y)
for j=1:length(a)
if ((a(j)<y(i))&&(a(j+1)>y(i)))
y1(i)=a(j);
y2(i)=j;
end
end
end
subplot(2,3,3),plot(x,y1);
%encoding
yen=dec2bin(y2);
%decoding
y3=bin2dec(yen);
for i=1:length(yen)
if y3(i)==0
ydec(i)=0;
else
ydec(i)=a(y3(i));
end
% ydec(i)=a(y3(i)+1);
end
z=ydec;
subplot(2,3,4),plot(x,z)
%reconstruction
f1=.001*fs;
x1=min(x):f1:max(x);
z=interp1(x,y,x1);
subplot(2,3,5),plot(x1,z);

For error curve the code segment is following,
fs=.0001;
b=[2 3 4 5 6 7];
for c=1:6
xa=0:.00001:.05;
ya=f(xa
%sampling
x=0:fs:.05;
y=f(x);
%quantization
a=min(y):((max(y)-min(y))/(2^b(c)-1)):max(y);
for i=1:length(y)
for j=1:length(a)
if ((a(j)<y(i))&&(a(j+1)>y(i)))
y1(i)=a(j);
end
end
end
sigms=sum((y1-y).^2)/(length(y)-1);
sigmx=sum(x.^2)/(length(xa)-1);
sqnr=sigmx/sigms;
db(c)=10*log10(sqnr);
end
plot(b,db);

Final outputs:
Main signal Sampled signal

Quantized signal Decoded signal


Reconstructed signal Error curve



For b=3 and fs=.01 the encoded signal is (due to the massive size of yen for higher fs lower value is
chosen here for example)
yen =

000
101
111
000
101
001
And the final decoded signal is (for b=3 and fs=.01)
ydec =

0 0.5435 0.8152 0 0.5435 0



Discussion:
For higher sampling frequency the data points number is higher thus it gives a better transmission of
signal. Similar thing can be said for the bitrate. Basically bitrate controls the data quality. The higher the
bitrate the higher levels of quantization level becomes thus the final output becomes more like the
actual one. But it doesnt means that if we continue to increase the bitrate the error level is gong to just
keep decreasing. It becomes almost saturated after a point.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy