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

DCT Lab PCM

The document describes a process for quantizing, encoding, and decoding a continuous time signal. It generates a continuous time signal, samples and plots it. It then quantizes the sampled signal into bins and plots the quantized signal. Finally, it decodes the quantized bins back into a regenerated continuous time signal by associating bin values with quantization levels, and plots the regenerated signal.
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)
15 views4 pages

DCT Lab PCM

The document describes a process for quantizing, encoding, and decoding a continuous time signal. It generates a continuous time signal, samples and plots it. It then quantizes the sampled signal into bins and plots the quantized signal. Finally, it decodes the quantized bins back into a regenerated continuous time signal by associating bin values with quantization levels, and plots the regenerated signal.
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

PCM CODE

close all;
clear;
clc;

%% Continuous time signal generation


fs = 200;
t = 0:1/fs:1;
f1 = 2; f2 = 2.5; fm = max(f1,f2);
x = 1 + sin(2*pi*f1*t) + 2*cos(2*pi*f2*t) + sin(2*pi*f2*t);
subplot(2,2,1);
plot(t,x,'LineWidth',1.5);
grid on;
title('Input Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(2,2,2);
stem(t,x);
grid on;
title('Sampled Signal');
xlabel('Time');
ylabel('Amplitude');

%% Quantization and Encoder


bin = []; quan = [];
for n = 1:length(t)
if x(n)>=3 && x(n)<4, q=3.5;
b='000';
elseif x(n)>=2 && x(n)<3, q=2.5;
b='001';
elseif x(n)>=1 && x(n)<2, q=1.5;
b='010';
elseif x(n)>=0 && x(n)<1, q=0.5;
b='011';
elseif x(n)>=-1 && x(n)<0, q=-0.5;
b='100';
elseif x(n)>=-2 && x(n)<-1, q=-1.5;
b='101';
end
quan=[quan,q];
bin=[bin,b];
end
subplot(2,2,3);
plot(t,quan,'LineWidth',1.5);
grid on;
title('Quantized Signal');
xlabel('Time');
ylabel('Amplitude');

%% Decoder
deco= [];
for n=1:3:length(bin)-2
if bin(n)=='0' && bin(n+1)=='0' && bin(n+2)=='0'
de=3.5;
elseif bin(n)=='0' && bin(n+1)=='0' && bin(n+2)=='1'
de=2.5;
elseif bin(n)=='0' && bin(n+1)=='1' && bin(n+2)=='0'
de=1.5;
elseif bin(n)=='0' && bin(n+1)=='1' && bin(n+2)=='1'
de=0.5;
elseif bin(n)=='1' && bin(n+1)=='0' && bin(n+2)=='0'
de=-0.5;
elseif bin(n)=='1' && bin(n+1)=='0' && bin(n+2)=='1'
de=-1.5;
end
deco = [deco,de];
end

%% fs = sampling freq = no. of samples per sec; fc = fs/4 (cutoff freq)


fn=2*fm; %% Nyquist Rate
F=fir1(20, 2*fm/fs);
fil_sig=filtfilt(F,1,deco);
subplot(2,2,4);
plot(t, fil_sig, 'LineWidth', 1.5);
hold on;
grid on;
title ('Regenerated Signal');
OUTPUT:

SIMULINK MODEL:
OUTPUT:

NAME: MASTER BIBEK KUMAR MOHANTY


ID – B220029, ETC (5TH SEMESTER)

You might also like