Nothing Special   »   [go: up one dir, main page]

National Institute of Technology: Communication Engineering Lab II

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

National Institute of Technology

CALICUT

Communication Engineering Lab II


Experiment - 1

PCM AND DPCM (BPSK)

SUBMITTED BY : GROUP B6
1 MIRIYALA KISHAN B181030EC miriyala_b181030ec@nitc.ac.in

2 POLISETTY SAI ROHITH B180482EC sairohith_b180482ec@nitc.ac.in

3 PYLA KOUSTHUB B180669EC pyla_b180669ec@nitc.ac.in

1
Problem Statement :
Simulate using MATLAB a digital communication system that employs
PCM to convert an analog n signal to a bit stream and subsequently uses
BPSK modulation to transmit it over an Additive White Gaussian Noise
Channel.
Input the analog signal 5+5.cos(2πf0 t), t ϵ [0,30/f 0 ]
Sample the signal at rate fs .Denote the number of quantization levels as l.
Assume that f 0 =1 KHz. At the receiver, reconstruct the analog signal from
the demodulated bit
stream.
(i) Calculate the Mean Squared Error (MSE) between the original analog
signal and the reconstructed signal.

(ii) Plot the MSE v/s f for f s = f0, 2f0 , 4f0 , 8f0 , 16f0 , 32f0 for all l (values
s
given below)
(iii) Plot the MSE v/s l, l= 4, 8, 16,…, 32 for all fs .
Repeat the experiment using DPCM. Compare the performance of PCM and
DPCM.

Theory
Pulse coded modulation (PCM)

Pulse Code Modulation Pulse-code modulation (PCM) is a method used


to digitally represent sampled analog signals.

In a PCM stream, the amplitude of the analog signal is sampled


regularly at uniform intervals, and each sample is quantized to the
nearest value within a range of digital steps.

A PCM stream has two basic properties that determine the stream's
fidelity to the original analog signal: the sampling rate, which is the
number of times per second that samples are taken; and the bit depth,
which determines the number of possible digital values that can be used
to represent each sample.
Differential Pulse Code Modulation (DPCM)

Differential pulse-code modulation (DPCM) is a signal encoder that


uses the baseline of pulse-code modulation (PCM) but adds some
functionalities based on the prediction of the samples of the signal.

The DPCM Transmitter consists of Quantizer and Predictor with two


summer circuits. Following is the block diagram of DPCM transmitter.

The predictor assumes a value, based on the previous outputs at both


the transmitter and receiver.

The input given to the decoder is processed and that output is summed
up with the output of the predictor, to obtain a better output.

Transmitter
Receiver

Algorithm and Outputs


● A input wave 5 + 5sin(x) is taken with a frequency of 1 kHz and is
sampled at a frequency higher than the nyquist rate frequency
● The resultant signal is quantized and is converted into binary
equivalent i.e. a PCM signal. (Encoded)
● The binary wave is then modulated using BPSK scheme with NRZ
modification.
● Then this modulated wave is sent through a AWGN channel and is
received at the receiver.
● BPSK demodulation is performed and then, Decoding is performed
and reconstructed signal is hence plotted.
● Similarly for DPCM an extra parameter Predictor is introduced to
predict the upcoming output sampled value.
● Corresponding Mean Square error vs quantization levels and
sampling frequency is plotted

Mean Square error


● The MSE can be written as the sum of the variance of the estimator
and the squared bias of the estimator, providing a useful way to
calculate the MSE and implying that in the case of unbiased
estimators, the MSE and variance are equivalent
Code :
clear;
close all;
global ct
ct=1;
A=zeros(5,5);
B=zeros(5,5);
Fs=[1,2,4,8,16];
N=[2,3,4,5,6];
for i =1:1:5
for u =1:1:5
A(i,u)=MSE(Fs(u),N(i));
end
end

for i=1:1:5
for u=1:1:5
B(i,u)=MSE(Fs(i),N(u));
end
end

figure(4)
for i =1:1:4
hold on
la=num2str(2^N(i));
lab=strcat("L=",la);
plot(Fs,A(i,:),'DisplayName',lab)
title('MSE vs fs')
legend

end

figure(5)
for i =1:1:5
hold on
la2=num2str(Fs(i));
lab2=strcat("fs=",la2);
plot(N,B(i,:),'DisplayName',lab2)
title('MSE vs number of Quantization Levels')
legend
end

function out=MSE(fs_,l)
f=1000;
fs=fs_*f;
n=l;
t=[0:1/(fs*10) :2];
x=5*cos(2*pi*f*t);
x1=x+5;
%quantisation
%q=round(x1);
maxsig=max(x1); %signal max
interv=maxsig/(2^n-1);
u=maxsig+interv/2;
partition = [0:interv:maxsig];
codebook = [0-interv/2:interv:u];
[q,quants] = quantiz(x1,partition,codebook);
enc=de2bi(q,'left-msb');

h=length(enc);
bpsk_=reshape(enc,1,h*n);
bpsk(bpsk_==1)=1;
bpsk(bpsk_ ==0)=-1;

SNR=10.^(14/10);
No=1/SNR;
N=sqrt(No/2)*randn(1,h*n);
BPSK_AWGN=bpsk+N;
detected=zeros(1,h*n);
for i = 1:1:length(BPSK_AWGN)
if(BPSK_AWGN(i)>0)
detected(i) = 1;
else
detected(i) = -1;
end
end

detected_(detected==1)=1;
detected_(detected==-1)=0;
rec=reshape(detected_,h,n);
dec=bi2de(rec,'left-msb');
x_re=dec*interv;

y=lowpass(x_re,1000.001,30000);
y=reshape(y,1,length(y));

out=immse(y,x1);
global ct
if fs_== 2 && ct==1
ct=0;
figure(1);
subplot(3,1,1);
plot(t,x1,'r');
title('Original Signal')
xlim([0.001 0.003])
subplot(3,1,2);
stem(t,x1);
title('Sampled Signal')
xlim([0.001 0.003])
subplot(3,1,3);
plot(t,q);
title('Quantized Signal')
xlim([0.001 0.003])
figure(2);
subplot(3,1,1);
stem(bpsk)
title('BPSK modulated')
xlim([0 90])
subplot(3,1,2);
stem(BPSK_AWGN)
title('BPSK in AWGN')
xlim([0 90])
subplot(3,1,3);
plot(t,x_re,t,y);
title('Recovered Signal')
xlim([0.001 0.003])
figure(3);
plot(t,y)
xlim([0.001 0.003])
title('Reconstructed Signal')
end
end
Plots And Waveforms:
Plots And Waveforms:
Observations and Inferences

● The Mean Square error decreases as quantization levels are increased


● The Mean Square error decreases as sampling frequency is increased
● DPCM takes less bandwidth to transmit the same signal than PCM.
● DPCM has more Mean square error than PCM for the same
quantization levels and sampling frequency
● Mean Square error in DPCM is higher than PCM and hence is not
advised to use. DPCM only helps us in saving the bandwidth as we are
only transmitting the difference and not the whole signal.

You might also like