0% found this document useful (0 votes)
25 views1 page

Program

This code quantizes an audio signal to 8 bits, resulting in 120 samples being represented by one of 256 possible integer values between 0 and 255. The original signal is scaled to fall between -1 and 1, then rounded and shifted to the corresponding integer-valued quantized signal. The error between the original and quantized signals is also calculated and plotted along with the two signals to show the effect of quantization.

Uploaded by

Amboro Dwi
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)
25 views1 page

Program

This code quantizes an audio signal to 8 bits, resulting in 120 samples being represented by one of 256 possible integer values between 0 and 255. The original signal is scaled to fall between -1 and 1, then rounded and shifted to the corresponding integer-valued quantized signal. The error between the original and quantized signals is also calculated and plotted along with the two signals to show the effect of quantization.

Uploaded by

Amboro Dwi
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/ 1

%Quantize a signal to n bits.

and +1.

This code assumes the signal is %between -1

n=8;
%Number of bits;
m=120;
%Number of samples;
x=wavread ('bel rumah.wav');
%signal between -1 and 1.
%Trying "sin()" instead of "sawtooth"
%results in more interesting error(to
%the extent that error is interesting).
x(find(x>=1))=(1-eps);
%Make signal from -1 to just less than 1.
xq=floor((x+1)*2^(n-1));
%Signal is one of 2^n int values (0 to
% 2^n-1)
xq=xq/(2^(n-1));
%Signal is from 0 to 2 (quantized)
xq=xq-(2^(n)-1)/2^(n);
%Shift signal down (rounding)
xe=x-xq;
%Error
figure (1)
stem(x,'b');
hold on;
stem(xq,'r');
hold on;
stem(xe,'g');
legend('exact','quantized','error','Location','Southeast')
title(sprintf('Signal, Quantized signal and Error for %g bits, %g
quantization levels',n,2^n));
hold off
figure (2)
sound (xq)
subplot (2,1,1)
spectrogram (xq)
subplot (2,1,2)
spectrogram (xq)

You might also like