You are on page 1of 11

Department of Electronic Engineering

Advanced Digital Signal Processing

ELE4ASP project

A Matlab implementation of a DPCM encoder

and decoder
Aim:
There are two main aims of this project.
Learn and understand the basic principle of a DPCM encoder and decoder.
Perform simulations using Maltab.

Introduction to DPCM:
DPCM is a technique in which an analogue signal is converted into a digital signal. This
method consists of sending a quantized version of the difference between a function of
the previous samples and the current sample. DPCM is based on the fact that most source
signals show significant correlation between successive samples so encoding uses
redundancy in sample values which implies lower bit rate.

There are two structures for DPCM: open-loop and closed-loop.

The figure below shows the encoder part of an open-loop DPCM.

Here in the encoder section, the input signal s[n] is passes through the prediction
block and then the predicted value, sp[n] and the original signal s[n] is subtracted to get
the error, e[n]. this error value is the passed through the quantization block to get the
quantized error value eq[n] as shown in the figure above.

In the encoder:
e[n] = s[n] sp[n]

2
sp[n]= ais[n i]

eq[n] = Q(e[n])
Where, y = Q(x) represents a quantization function.
The figure below shows the decoder part of an open-loop DPCM.

The Decoder part is the inverse of the encoder part. Here in the decoder part, the
quantized error signal, eq[n] from the encoder is passed through the de-quantization
section of the decoder part and the value e1[n] is obtained. This de-quantized value is then
passed through the prediction block and then added to the 2nd value of the signal to get the
signal r[n]. This value is then passed through the prediction block and the predicted
value, rp[n] is then added to the next value of the signal and this continues until the rest of
the values of the signal.

In the decoder:
e1[n] = [eq[n]]
r(n)=e1(n)+rp(n)

r(n)=e1(n)+ r[n-i]

3
The figure below shows the encoder of a closed loop DPCM:

Here in the encoder of the closed loop, an error, e[n] is generated and it is passed
through the quantization block to obtain eq[n]. This value is then passes through the de-
quantization block to obtain e1[n]. The de-quantized signal is then passed through the
prediction block and the predicted signal is then subtracted with the 1st value of the
original signal. Then quantized and de-quantized and we get and output e1[n] from the de-
quantization block. This value is added with the previous value and then again fed into
the prediction block and the process goes on until the rest of the signal.

The decoder is the same as that of an open-loop DPCM.

4
Compression of video and image signals using DPCM:

Good compression ratio is obtained when DPCM is conducted on signals with correlation
between successive samples. Examples are image and video signals. In video signals this
means that there is a correlation between the same pixels in consecutive frames and
inside frames whereas in images, the correlation is between the neighboring pixels.

There are two methods of DPCM compression, namely, intra-frame coding and inter-
frame coding where intra-frame coding exploits spatial redundancy and inter-frame
coding exploits temporal redundancy. In the intra-frame coding the difference is formed
between the neghboring pixels of the same frame, while in the inter-frame coding it is
formed between the value of the same value in two consecutive frames. In both coding
intra- and inter- frame the value of target pixel is predicted using the previously-coded
neighboring pixels.
Advantages of DPCM:
The real advantage of DPCM is that the unconditional entropy of the error signal
(based on the quantized error signal monogram statistics) is approximately equal
to the first-order conditional entropy of the actual signal.
In the case of voice signals, the optimum signal to quantization noise advantage of
DPCM over a standard PCM is in the neighborhood of 4-11 dB.
DPCM can also be expressed in bit rate.
Since from the equation:
10log10(SNR)o = 1.8 + 6R
6dB of quantization noise is equivalent to 1 bit per sample.
For a constant signal to quantization noise ratio (Assuming sampling rate of 8
kHz), the use of DPCM may provide a saving of about 8-16 kb/s (i.e. 1 to 2 bits
per sample ) compared to the standard PCM.
Other disadvantage of DPCM is that it is much more sensitive to noise than
ordinary PCM. Since a reconstructed picture element depends on all past picture
elements, a single error appears in all remaining picture elements. Because of thee
large amount of data transmitted for any picture, transmission errors could be a

5
serious problem. Error recovery procedures in the transmission link might solve
this problem.

Disadvantages of DPCM:
The main disadvantage of DPCM is that it is much more sensitive to noise then ordinary
PCM. Since a reconstructed picture element depends on all past picture elements, a single
error appears in all remaining picture elements. Because of thee large amount of data
transmitted for any picture, transmission errors could be a serious problem. Error
recovery procedures in the transmission link might solve this problem.

GUI Graphical User Interface:


This is the graphical user interface part of the MATLAB. When a GUI file is run, it
created two file namely an m-file and a fig-file. The fig-file is shown below, where we
can make changes.

6
When the above shown fig-file is run, the below shown image is obtained where we can
input the audio, k-value for the quantizer, and prediction order. It also displays the Mean
Square Error value and the corresponding plots of the input signal.
Here, audio file used = cashtill.wav, given the order as 7 with a 2 bit quantizer and the
following plot and MSE is obtained.

The m-file is used to edit the program basically to create callback functions for each
component palette and to create individual function.

7
GUI Main programs:
This function is called when the Run Program button is pressed.
function run_program_Callback(hObject, eventdata, handles)
% hObject handle to run_program (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

N=str2double(get(handles.quantizer_edit_txt,'String')); % to get the


%Quantizer value and converting to double
t=str2double(get(handles.prediction_edit_txt,'String'));% to get the
%prediction order and converting to double
filename=get(handles.name,'String'); % getting the filename as string

y=wavread(filename); %reads the wave file


axes(handles.orisignal);
plot(y);
len=length(y); %putting the length of y in len
axes(handles.orispectrum);
semilogy(abs(fft(y)));

%Optimum linear prediction


[e,pa,b1]=opt_lin_pre(y,t,len);

% Quantization
[ss,quant,es]=quantize(e,N);

% De-quantization
r_vector=de_quan(ss,quant,es,len,t,b1);
axes(handles.encoder);
plot(r_vector);
axes(handles.decoder);
semilogy(abs(fft(r_vector)));

% Writing the quantized prediction error to a file


k=fopen('q_error.wav','w'); %opens the file in write mode
fwrite(k,quant); %write in the file

8
% Calculating mean squared error
MSE=mean_error(y,r_vector);
set(handles.dis_MSE,'String',MSE); %putting the value of MSE in GUI
end

This function is called when the Decoded Audio button is pressed:


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
N=str2double(get(handles.quantizer_edit_txt,'String'));
t=str2double(get(handles.prediction_edit_txt,'String'));
f=get(handles.name,'String');
y=wavread(f);
len=length(y);
%Optimum linear prediction
[e,pa,b1]=opt_lin_pre(y,t,len);
% Quantization
[ss,quant,es]=quantize(e,N);
% De-quantization
r_vector=de_quan(ss,quant,es,len,t,b1);
% Calculating mean squared error
sound(r_vector); %plays the decoded audio
end

This function is called when the Play the audio file button is pressed:
function Play_audio_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Play_audio_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename=get(handles.name,'String');
y=wavread(filename);
sound(y);
end

9
Functions definition:
%Optimum linear prediction
function [e,pa,b1]=opt_lin_pre(y,t,len)
b=lpc(y,t); %passing the values of y and t in lpc and storing in b
b1=-b(2:end); %
p=conv(b1,y); %convoluting b1 with y
paa=p(1:len-1);
pa=[0;paa];
e=(y-pa); %subtracting the predicted value and the original signal
end

% Quantization
function [ss,quant,es]=quantize(e,N)
ae=abs(e); %taking absolute of error value
MAX=max(ae); %getting the max of error
MIN=min(ae); %getting the min of error
ss=((MAX-MIN)/(2^N)); %calculating step size
quant=round(ae/ss); %rounding of the value
es=sign(e); % changing the sign of the signal e and storing in es
end

% De-quantization
function r_vector=de_quan(ss,quant,es,len,t,b1)
dequan=(ss*(quant+1/2)); %dequantized signal
dequan=(es.*dequan);%multiplying the dequan signal with es(sign change)
r_vector(1:len)=zeros;
r(1)=dequan(1);
r_vector(:,1)=r;

for i=2:t
rpt=conv(b1,r);
rt=dequan(i)+rpt(i-1);
r_vector(:,i)=rt;
end

for i=t+1:len

10
r_predict=r_vector(i-t:i-1);

j=1:length(b1);
B=fliplr(r_predict); %altering the dmensions
rp=sum(b1(j).*B); %reconstruction

rt=dequan(i)+rp; %reconstructed de-quantized signal


r_vector(:,i)=rt;

end

end

% Calculating mean squared error


function MSE=mean_error(y,r_vector)
dE=(y-(r_vector')); %subtracting the decoded signal with the original
%input
MSE =mean(dE.^2); %squaring the value and getting the mean
end

Result:
Simulations have been run with various audio files and the results have been
verified.

Reference:
Lecture Notes
ASP Labs
http://deepblue.lib.umich.edu/bitstream/2027.42/4581/4/bab4765.0001.001.txt

11

You might also like