clc; clear all;
f=2; %Maximum frequency of the signal 
fs=20*f;  % Sampling freq rate 
t=0:1/fs:1; 
a=2;  %Amplitude 
x=a*sin(2*pi*f*t);    
x1=x+a; %level shifting 
q_op=round(x1); %Quantization 
pcm=de2bi(q_op,'left-msb') %encode to PCM
disp(pcm)
deco=bi2de(pcm,'left-msb'); %Decode PCM value
xr=deco-a; % shift amplitude level to the original value 
plot(t,x,'r- ',t,xr,'k+-'); 
xlabel('Amplitude'); 
ylabel('original Signal'); 
legend('original signal','Reconstructed Signal');
