Sie sind auf Seite 1von 13

Lab # 3 Analysis of Uniform and Non uniform

Quantization of Speech Signals (u-law and A-law)

OBJECTIVES:
To assist the students in developing a thorough understanding of the process of
uniform and non-uniform quantization. The students will be able to differentiate between uniform
and non-uniform quantization and develop codes to implement both processes.

INTRODUCTION:

This lab basically deals with the quantization process of the speech signal.
Quantization is a main function when an analog signal is digitalized and different levels are
adjusted for the better outcomes. The quantization process is that in which the amplitude of the
analog signal is defined in different levels so that the amplitude can be discretized. After
quantization process the signal does not have infinite amplitude values because the amplitude sets
according to different quantized levels. There are different types of quantization such as 1) uniform
quantization, 2) non-uniform quantization. In uniform quantization the levels set for quantization
have same distance (called as q), and all levels are uniform so if the analog signal have large
amplitude uniform quantization will be easy and give almost same waveform but if the analog
signal’s amplitude is small than there will be more chance of quantization error by using the
uniform quantization, so for this case non-uniform quantization is used. When the amplitude of
the analog signal is small and in-fact most of the signals have low amplitude, the non-uniform
quantization is quite useful and there will be less chance of error.in non-uniform quantization some
of the levels are set very closely for the small amplitude and some levels are set with higher
separation to tackle the large amplitude peaks and thus in this way the quantization error will be
less. For the non-uniform quantization two methods are used: 1) u-law method 2) A-law, and
both have formulas for quantization as follows :
u-law :

log( 1 + 𝜇|𝑚|)
|𝑣| =
log( 1 + 𝜇)

Where |v| = Normalized output.

|m| = Normalized input

From the compressor we can get the expander as

(1 + 𝜇)|𝑣| − 1
|𝑚| =
𝜇

A-Law :

𝐴|𝑚|
, 0 ≤ |𝑚| ≤ 1/𝐴
1+log 𝐴
|𝑣| = {1+log(𝐴|𝑚|) 1
, ≤ |𝑚| ≤ 1
1+𝑙𝑜𝑔𝐴 𝐴

We get the expander from the above equation as

|𝑣|(1 + 𝑙𝑜𝑔𝐴)
, 0 ≤ |𝑣| ≤ 1/(1 + 𝑙𝑜𝑔𝐴)
𝐴
|𝑚| =
10(|𝑣|(1+𝑙𝑜𝑔𝐴)−1) 1
, ≤ |𝑣| ≤ 1
{ 𝐴 1 + 𝑙𝑜𝑔𝐴

IN-LAB TASKS :

TASK 01 :

1. Read a .wav sound file (preferably a speech clip).


2. A .wav file is usually sampled at 44.1 KHz (High Fidelity sampling), figure out the
sampling rate of your sound clip, if it is 44.1 KHz down sample it 10 times to 4.41 KHz
(Low fidelity sampling).
3. Plot the frequency response of actual signal and the down sampled signal.
4. Create a .wav file using the down sampled version and listen to the original and down
sampled version. Comment

MATLAB CODE :

clear all %to clear all previous simulations and graphs


close all
clc

[y, Fs] = wavread('orig4.wav') %command used for read a wav(audio) file and
gives y as output
figure();
plot(y) %command used for plotting y values
xlabel('time')
ylabel('amplitude')
title('time domain')

y1 = downsample(y,10); %command used to downsample the signal by a


factor of 10.1o times signal will reduce on x-axis
figure();
plot(y1)
xlabel('time')
ylabel('amplitude')
title('time domain')

N = length(y) %to find the total length of the obtained signal


Ts = 1/Fs; %to find the sample time by using the sampling frequency
N1 = length(y1) % to find the total length of the downsample signal

Y11 = fftshift(fft(y,N)); % calculate the fourier transform of the


original obtained signal(y)

siglen = [0:1/N:1-1/N]; %to define total signal length in pieces


figure();
plot(siglen,abs(Y11)) %plot the absolute value of fft signal of y.
xlabel('frequency')
ylabel('amplitude')
title('freq domain of original signal') %

Y12 = fftshift(fft(y1,N1)); % calculate the fourier transform of the


obtained downsample signal(y1)

siglen1 = [0:1/N1:1-1/N1]; %to define total signal length in pieces


figure();
plot(siglen1,abs(Y12)) %plot the absolute value of fft signal of y1.
xlabel('frequency')
ylabel('amplitude')
title('freq domain of downsample signal')
MATLAB FIGURES:

This picture represent the original signal obtained from the audio file using the function wavread,
the signal have the sampling frequency of the signal is 44.1KHz and the amplitude have different
variations.

Above figure represent the down sampled signal of the original signal obtained from the audio
file,thus by down sampling by a factor of 10 compress the original signal 10 times on time axis.
This figure is a fourier transform representation of the signal obtained from the audio file.in
frequency domain all the values are very concentrated due to the fftshift because fftshift
converge all the values on 0.

This figure shows the fft transform of the down sampled signal. From this figure we can observed
the down sample effect in frequency domain, in frequency domain down sample suppress the
signal by a factor of 10.
TASK 2:
1. A .wav file is usually 16 bit quantized. Use a uniform quantizer to reduce the down
sampled version to it to 4-bit.
2. Find out the quantization noise. Plot it and find out mean square quantization error.
3. Use µ -LAW to reduce the 16-bit quantization to 4-bit. Plot quantization noise and find
mean square error for different values of µ.
4. Use A-LAW to reduce the 16-bit quantization to 4-bit. Plot quantization noise and find
mean square error for different values of A.
5. Repeat the tasks (1-4) but now use 8-bit quantization.
6. Present your results in tabular form, compare quantization noise plot of uniform and non-
uniform quantization.

MATLAB CODE:
clear all %to clear all previous simulations and graphs
close all
clc

[y,Fs] = wavread('orig4.wav') %command used a wav(audio) file in matlab


which inreturn sampling frequency and signal y

figure();
plot(y) %command ysed to plot the signal
l = 4;

L = 2^l; %defining the steps

max_val = max(y) %finding the maximum value of signal y

min_val = min(y) %finding the minimum value of signal y

z = ((max_val-min_val)/L) %defining the step size of the quantization

level = linspace(min_val-z/2,max_val+z/2,L) %defining different levels

for k = 1:length(y); %FOR loop for finding every quantized value of


signal y

temp = abs(level-y(k)); %finding the difference between level value and


signal y value at every instant
[val index] = min(temp); %allocate the signal value with respect of the
minimum value.
quan_sig = level(index); %atleast finding the quantized level for the
signal y and assign these values at different
sampling time
end

error1 = y-quan_sig; %finfing the quantized error for the signal y.

mse1 = mean(error1)^2 %finding the mean square quantized error for


signal y

MATLAB FIGURE:

This picture represent the original signal obtained from the audio file using the function wavread,
the signal have the sampling frequency of the signal is 44.1KHz and the amplitude have different
variations.

Above figure shows the levels defined for the quantization and the distance between each level is
same so this is uniform quantization. Also the mean square error was calculated and which show
the gap between the analog signal and the quantized level, there will be less error for more
quantization levels.

DOWNSAMPLED SIGNAL:

MATLAB SIGNAL :
clear all %to clear all previous simualtions
close all
clc

[y,Fs] = wavread('orig4.wav') %command used a wav(audio) file in matlab


which inreturn sampling frequency and signal y
figure();
plot(y) %command ysed to plot the signal
l = 4;

L = 2^l; %defining the steps

max_val = max(y) %finding the maximum value of signal y

min_val = min(y) %finding the minimum value of signal y

z = ((max_val-min_val)/L) %defining the step size of the quantization

level = linspace(min_val-z/2,max_val+z/2,L) %defining different levels

for k = 1:length(y); %FOR loop for finding every quantized value


of signal y

temp = abs(level-y(k)); %finding the difference between level value and


signal y value at every instant

[val index] = min(temp); %allocate the signal value with respect of the
minimum value.

q_sig = level(index); %atleast finding the quantized level for the


signal y and assign these values at different
sampling time

end

error = y-q_sig; %finfing the quantized error for the signal y.

mse = mean(error)^2 %finding the mean square quantized error for


signal y

%downsampled signal
y11 = downsample(y,10); %down sample the original signal by factor 10
figure();
plot(y11)

max_val1 = max(y11); %define the maximum value of down-sampled signal


min_val1 = min(y11); %define the minimum value of down-sampled signal
z = ((max_val1-min_val1)/L); %defining the step size of the
quantization
level = linspace(min_val1-z/2,max_val1+z/2,L); %defining different
levels

for k = 1:length(y11) %FOR loop for finding every quantized value


of signal down-sampled signal.
temp = abs(level-y11(k)); %finding the difference between level value
and signal y value at every instant
[val index] = min(temp); %allocate the signal value with respect of the
minimum value.
q_sig = level(index);
end

error1 = y11-q_sig; %finfing the quantized error for the down-sample.

mse1 = mean(error1)^2 %finding the mean square quantized error for


signal y

ms = mse-mse1
MATLAB FIGURE:

This picture represent the original signal obtained from the audio file using the function wavread,
the signal have the sampling frequency of the signal is 44.1KHz and the amplitude have different
variations.
This figure represent the mean square error obtained from the down sampled signal by factor 10.
The error also reduced 10 times in down sampled signal which is a quite useful information of
down sampled signal.

POST-LAB:

TASK:

 Read an image using command


>> A=imread('peppers.png');
Using imshow you can display the image
>> imshow(A);
Following command converts the image into gray-scale
>> Ag=rgb2gray(A);
>> imshow(Ag);
Ag will be a matrix where each value represents a pixel which is quantized into 8 bits.
 Change the quantization level of Ag into 4 bits and display
 Change the quantization level of Ag into 6 bits and display
 Change the quantization level of Ag into 2 bits and display
 Compare and evaluate the results.

MATLAB CODE:

clear all %to clear all previous simulations


close all
clc
y = imread('website.jpg'); %command used for to Read Images
subplot(3,2,[1,2]);
imshow(y) %command used to Show Images
title('Original Image with no changes');

grscale = rgb2gray(y); %Convert RGB colours to Gray


subplot(3,2,3)
imshow(grscale)
title('Image with Gray Scale conversion');

% Display the 64-level image


thre6 = multithresh(grscale,15); %this command converts the picture
in to a single valu
value_max16 = [thre6 max(gray_scale(:))]; %getting maximum value of picture
[quantI,index] = imquantize(grscale, thr6, value_max16); %command used for
to convert an image into a two-level image.

subplot(3,2,4)
imshow(quantI,[])
title('Image with quantization level of 6 bits');

% Display the 16-level image


thresh4 = multithresh(grscale,15);
value_max4 = [thresh4 max(grscale(:))];
[quantI, index] = imquantize(grscale, thresh4, value_max4);

subplot(3,2,5)
imshow(quantI,[])
title('Image with quantization level of 4 bits');

% Obtain 7 thresholds from MULTITHRESH to split the image into 8 levels


thresh = multithresh(grscale,3);
% Reduce the number of levels using the maximum value in each interval
% to replace the values in I
value_max2 = [thresh max(gray_scale(:))];
[quantI, index] = imquantize(grscale, thresh, value_max2);

% Display the 4-level image


subplot(3,2,6)
imshow(quantI,[])
title('Image with quantization level of 2 bits');
MATLAB FIGURE :

This figure shows the different variation of quantization level on the picture, as the quantization
level decreased the picture gets more blured and thus determine that there will be more error in
2-bit quantization than 16-bit quantization levels.

CRITICAL ANALYSIS:

This lab was about the basics of quantization. Quantization is a basic


steps of converting the analog signal into digital signal. Quantization is a main part of this process,
the amplitude axis of the analog signal defined in the different levels and the analog signal
continuous amplitude corresponds to these different levels. In this lab we studied two types of
quantization. First is uniform quantization and it is quite useful when the analog signal have higher
amplitude so there will be less chance of error, which is experimentally proved in this lab tasks.
Second type is non-uniform quantization which is quite useful when the analog signal have low
amplitude, so that some of the levels are very adjacent to each other for maintaining the low
amplitude and some levels are far apart for maintain the large peaks. Also the effect of down
sampling were observed. When the analog signal downsample by a factor of 10, then it reduced
10 time on time axis in time domain and 10 time reduce in amplitude when we observed it in
frequency domain, but one of the main advantage is that the quantization error also reduced 10
times for the down sample signal, which gives the approximately te same value as the analog signal
have. In last the effect of quantization was observed, when we use higher level the quantization
error was low as the more levels cover the same amplitude interval in respect of the low levels
quantization in which low number of levels exist in the amplitude error. This quantization levels
effect also observed in post-lab task, in which the picture gets more blured when we used 2-bit
quantization and the picture obtained almost the same as original when we used 16-bit
quantization, so the quantization level effect the digital signal shape which is the main purpose of
this lab.

Das könnte Ihnen auch gefallen