PCM & Sampling, FSK, PSK
PCM & Sampling, FSK, PSK
clc;
clear all;
close all;
n=input('enter n value for n bit pcm system:');
n1=input('enter number of samples in a period:');
L=2^n;
x=0:2*pi/n1:4*pi;
s=8*sin(x);
subplot(3,2,1)
plot(s);
title('analog signal');
ylabel('amplitude');
xlabel('time');
subplot(3,2,2)
stem(s);
grid on;
title('sampled signal');
ylabel('amplitude');
xlabel('time');
%quantization process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax;
code=vmin-(del/2):del:vmax+(del/2);
[ind,q]=quantiz(s,part,code);
L1=length(ind);
L2=length(q);
for i=1:L1
if(ind(i)~=0)
ind(i)=ind(i)-1;
q(i)=vmin+(del/2);
end
end
subplot(3,2,3)
stem(q);
grid on;
title('quantized signal');
ylabel('amplitude');
xlabel('time');
%encoding process figure
code=de2bi(ind,'left-msb');
k=1;
for i=1:L1
for j=1:n
coded(k)=code(i,j);
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(3,2,4);
grid on;
stairs(coded);
axis([0 100 -2 3]);
title('encoded signal');
ylabel('amplitude');
xlabel('time');
%demodulation of pcm signal
qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb');
q=del*index+vmin+(del/2);
subplot(3,2,5);
grid on;
plot(q);
title('demodulated signal');
ylabel('amplitude');
xlabel('time');
%sampling theorem%
clc;clear all; close all;
t=0:0.001:1;
f=8;
x=cos(2*pi*f*t);
plot(t,x);title('Original Signal');
%when fs>2fm%
fs1=8*f;
ts1=1/fs1;
n1=0:ts1:1;
xs1=cos(2*pi*f*n1);
figure;
plot(n1,xs1,'r');title('Over sampled signal');
hold on;
plot(t,x);
hold off;
%when fs=2fm%
fs2=2*f;
ts2=1/fs2;
n2=0:ts2:1;
xs2=cos(2*pi*f*n2);
figure;
plot(n2,xs2,'r');title('Critical sampled signal');
hold on;
plot(t,x);
hold off;
%when fs<2fm%
fs3=1.7*f;
ts3=1/fs3;
n3=0:ts3:1;
xs3=cos(2*pi*f*n3);
figure;
plot(n3,xs3,'r');title('Under sampled signal');
hold on;
plot(t,x);
hold off;
clc;
clear all;
close all;
fc1=input('enter the freq of 1st sine wave carrier:');
fc2=input('enter the freq of 2nd sine wave carrier:');
fp=input('enter the freq of period binary pulse(message):');
amp=input('enter the amplitude(for both carrier & binary pulse message):');
amp=amp/2;
t=0:0.001:1;
c1=amp.*sin(2*pi*fc1*t);
c2=amp.*sin(2*pi*fc2*t);
subplot(4,1,1);
plot(t,c1)
xlabel('time')
ylabel('amplitude')
title('carrier 1 wave')
subplot(4,1,2)
plot(t,c2)
xlabel('time')
ylabel('amplitude')
title('carrier 2 wave')
m=amp.*square(2*pi*fp*t)+amp
subplot(4,1,3)
plot(t,m)
xlabel('time');
ylabel('amplitude');
title('binary message pulses')
for i=0:1000
if m(i+1)==0
mm(i+1)=c2(i+1);
else
mm(i+1)=c1(i+1);
end
end
subplot(4,1,4)
plot(t,mm)
xlabel('time')
ylabel('amplitude')
title('modulated wave')
output :
clc;
clear all;
close all;
fc1=input('enter the freq of 1st sine wave carrier:');
fc2=input('enter the freq of 2nd sine wave carrier:');
fp=input('enter the freq of periodic binary pulse (message)');
amp=input('enter the amplitude (for both carrier & binary pulse messsage):');
amp=amp/2;
t=0:0.001:1;
c1=amp.*sin(2*pi*fc1*t);
c2=amp.*sin(2*pi*fc2*t+pi);
subplot(4,1,1);
plot(t,c1)
xlabel('time')
ylabel('amplitude')
title('carrier 1 wave')
subplot(4,1,2)
plot(t,c2)
xlabel('time')
ylabel('amplitude')
title('carrier 2 wave')
m=amp.*square(2*pi*fp*t)+amp;
subplot(4,1,3);
plot(t,m)
xlabel('time')
ylabel('amplitude')
title('binary message pulses')
for i=0:1000
if m(i+1)==0
mm(i+1)=c2(i+1);
else
mm(i+1)=c1(i+1);
end
end
subplot(4,1,4)
plot(t,mm)
xlabel('time')
ylabel('amplitude')
title('modulated wave')
OUTPUT: