Aim:

1.To understand the operation theory of pulse coded modulation (PCM).
2.To understand the theory of PCM demodulation circuit. 

Program:
clc;
clear all;
close all;
f=600; % Generate sinusoidal wave of frequency of 200/300/400/500/600 Hz
t = 0:1e-4:25/f; % Time period varies from 0 to 5/f,10/f,15/f,20/f,25/f
w = 2*pi*f;
sig1 = sin(w*t);
figure,subplot(321); plot(sig1); xlabel('time'); title('original signal');ylabel('Amplitude');
fs=6500 ; %Generate sampled signal with frequwncy of 2500/3500/4500/5500/6500 Hz
Ts = 1/fs;
t2=(0:Ts:25/f);
sig = sin(w*t2);
subplot(323); stem(t2,sig); xlabel('time'); title('sampled signal');ylabel('Amplitude');
Vh=max(sig);Vl=min(sig);
N=4;M=2^N;S=(Vh-Vl)/M; %design N-bit uniform quantizer with stepsize=S
partition = [Vl+S:S:Vh-S]; % Length M-1, to represent M intervals
codebook = [Vl+S/2:S:Vh-S/2]; % Length M, one entry for each interval
[index,quantized_sig,distor] = quantiz(sig,partition,codebook); % Quantize.
subplot(325); stem(t2,quantized_sig); xlabel('time'); title('quantized signal');
codedsig=de2bi(index,'left-msb');
codedsig=codedsig';
txbits=codedsig(:); %serial transmit
tt=[0:N*length(t2)-1];
subplot(322);stairs(tt,txbits); axis([0 30 -2 3]);xlabel('time'); title('PCM waveform');
rxbits=reshape(txbits,N,length(sig));
rxbits=rxbits';
index1=bi2de(rxbits,'left-msb'); %decode
index2=S*index1+Vl+(S/2);
reconstructedsig=index2; %re-quantize
subplot(324);plot(t2,reconstructedsig); xlabel('time'); title('received signal');

Algorithm:
1. Clear command window
2. Clear all variables in workspace window
3. Close all the files in current folder window
4. Generate the sinusoidal expression with frequency(f) to 200/300/400/500/600 Hz
and time(t) from 0 to 5/f, 10/f, 15/f, 20/f, 25/f in interval of
sec.
5. Generate the expression for samples with time(t) from 0 to 5/f, 10/f, 15/f, 20/f, 25/f
in interval of sampling frequency of 2500/3500/4500/5500/6500 Hz
6. Determine maximum and minimum of sampled signal
7. Determine the N value for N-bit uniform quantizer and also step size
8. Determine the no.of intervals, possibly M-1 (M=2N)
9. Determine the no.of entries in each interval, possibly M
10. Perform the quantization process of the sampled signal, determine the quantization
levels and quantized values
11. Plot the quantized values
12. Convert the quantization levels from decimal to binary and transpose it
13. Determine the time duration for PCM encoded signal possibly from 0 to N*(length
of sampled interval)-1
14. Plot the PCM encoded signal using stairs command
15. Reconstruct the original signal from PCM encoded signal, N, no.of elements in
sampled signal and transpose the vector
16. Convert the reconstructed signal from binary to decimal and plot the reconstructed
signal.

Real Time applications:
Computer Disk, Digital Telephony, Digital Audio Applications