0% found this document useful (0 votes)
77 views7 pages

Pulse Code Modulation

The document outlines a procedure to generate a pulse code modulated (PCM) signal using MATLAB. It explains the theory behind PCM, provides a MATLAB code for generating and quantizing a sinusoidal signal, and includes steps for calculating the signal-to-noise ratio (SNR). The results demonstrate the successful implementation of PCM and the relationship between quantization levels and SNR.

Uploaded by

ajulanilkumar27
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)
77 views7 pages

Pulse Code Modulation

The document outlines a procedure to generate a pulse code modulated (PCM) signal using MATLAB. It explains the theory behind PCM, provides a MATLAB code for generating and quantizing a sinusoidal signal, and includes steps for calculating the signal-to-noise ratio (SNR). The results demonstrate the successful implementation of PCM and the relationship between quantization levels and SNR.

Uploaded by

ajulanilkumar27
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/ 7

PULSE CODE MODULATION

AIM

To generate a pulse code modulated signal.

THEORY
Pulse-code modulation (PCM) is a method used to digitally represent sampled analog signals.
It is the standard form of digital audio in computers, compact discs, digital telephony and
other digital audio applications. 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.

PROGRAM

% PCM CODE

clc;

clear all;

close all; % closing any opened figures

% Plotting the offset sinusoidal signal

time = 0:.0005:.05;

freq_msg=100; %wave form frequency

dc_ofst=2; % signal offset

signal=sin(2*pi*freq_msg*time)+dc_ofst; %Generating the signal

% plotting the signal

figure;

plot(time,signal);

xlabel('time');

ylabel('Amplitude');

title('Signal');

% Sampling the signal

freq_sample=15*freq_msg; % sampling frequency

samp_time=0:1/freq_sample:0.05; % sampling time


samp_signal=dc_ofst+sin(2*pi*freq_msg*samp_time);% generating the sampled signal

hold on

plot(samp_time,samp_signal,'rx') % plotting the sampled signal

title('Sampled Signal')

legend('Original signal','Sampled signal');

% Uniform Quantizer

L=8; %No of Quantization levels

smin=round(min(signal)); smax=round(max(signal));

Quant_levl=linspace(smin,smax,L); % Length 8, to represent 9 intervals

codebook = linspace(0,smax,L+1); % Length 9, one entry for each interval

[index,quants] = quantiz(samp_signal,Quant_levl,codebook); % Quantize.

figure;

plot(samp_time,samp_signal,'x',samp_time,quants,'.-')% plotting sampled signal and quantization


level title('Quantized Signal')

legend('Original signal','Quantized signal');

figure;

plot(samp_time,index,'.-')% plotting quantization levels of input signal

title('Encoded Signal');

% Binary coding

for i=1:length(index)

bincode_sig{i}=dec2bin(round(index(i)),3);

end

disp('binary encoded signal');

disp(bincode_sig)

% SNR ratio calculation

noise=quants-samp_signal; % calculating noise

figure;

plot(samp_time,noise,'.-'); % plotting figure


title('Noise');

r=snr(index,noise);% SNR

snr1=['SNR :',num2str(r)];

disp(snr1)

% Function for ploting Quant_level vs SNR


function [ r ] = IMPL_Quant( l,b )
% Plotting the offset sinusoidal signal

time = 0:.0005:.05;

freq_msg=100; %wave form frequency

dc_ofst=2; % signal offset

signal=sin(2*pi*freq_msg*time)+dc_ofst; %Generating the signal

% Sampling the signal

freq_sample=15*freq_msg; % sampling frequency

samp_time=0:1/freq_sample:0.05; % sampling time

samp_signal=dc_ofst+sin(2*pi*freq_msg*samp_time);% generating the sampled signal

% Uniform Quantizer

L=l; %No of Quantization levels

smin=round(min(signal));

smax=round(max(signal));

Quant_levl=linspace(smin,smax,L); % Length 8, to represent 9 intervals

codebook = linspace(0.7,smax,L+1); % Length 9, one entry for each interval

[index,quants] = quantiz(samp_signal,Quant_levl,codebook);

% Quantize.

% Binary coding

for i=1:length(quants)

bincode_sig{i}=dec2bin(round(quants(i)),b);

end
% SNR ratio calculation

noise=quants-samp_signal; % calculating noise

r=snr(index,noise);% SNR

end

% PCM SNR PLOT

% Program for plotting quantization level vs SNR

clc;

clear all;

close all;

l=[8,16,32,64,128];% defining different levels


b=[3,4,5,6,7];

for i=1:length(l)

r(i) = IMPL_Quant(l(i),b(i));% calling the function

end

%Plotting

figure;

plot(l,r);

xlabel('L');

ylabel('SNR');

title('L vs SNR');

PROCEDURE
1. Run MATLAB.

2. Open a new script file.

3. Write the code for PCM.

4. Run the code for execution and obtain the necessary results.

WAVEFORMS
RESULT
Pulse code modulation is performed using MATLAB and plot of quantization level versus
SNR is obtained.

You might also like