BPSK Modulation and Demodulation: All All
BPSK Modulation and Demodulation: All All
clc;
clear all;
close all;
x=[1 0 0 1 1 0 1];
bp=0.000001;
disp('binary information at the transmitter:');
disp(x);
bit=[];
for n=1:1:length(x);
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'linewidth',2.5);grid on;
axis([0 bp*length(x) -.5 1.5]);
ylabel('amplitude (volt)');
xlabel('time (sec)');
title('transmitting information as digital signal');
A=5;
br=1/bp;
f=br*2;
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if(x(i)==1)
y=A*cos(2*pi*f*t2);
else
y=A*cos(2*pi*f*t2+pi);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary PSK modulation');
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t);
mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm)
zz=round((2*z/bp))
if(zz>0)
a=1;
else
a=0;
end
mn=[mn a];
end
disp('binary information at receiver');
disp(mn);
bit=[];
for n=1:length(mn);
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3);
plot(t4,bit,'linewidth',2.5);grid on;
axis([0 bp*length(mn) -.5 1.5]);
ylabel('amplitude (volt)');
xlabel('time (sec)');
title('received information as digital signal after binary PSK
demodulation');
1
amplitude (volt)
0.5
-0.5
0 1 2 3 4 5 6 7
time (sec) -6
x 10
waveform for binary PSK modulation
5
amplitude(volt)
-5
0 1 2 3 4 5 6 7
time(sec) -6
x 10
received information as digital signal after binary PSK demodulation
1.5
1
amplitude (volt)
0.5
-0.5
0 1 2 3 4 5 6 7
time (sec) -6
x 10
binary information at the transmitter:
1 0 0 1 1 0 1
z =2.4499e-06
zz =5
z =-2.4499e-06
zz =-5
z =-2.4499e-06
zz =-5
z =2.4499e-06
zz =5
z =2.4499e-06
zz =5
z =-2.4499e-06
zz =-5
z =2.4499e-06
zz =5
1 0 0 1 1 0 1
QPSK MODULATION AND DEMODULATION
clc;
clear all;
close all;
data=[0 1 0 1 1 1 0 0 1 1];
%number_of-bit=1024;
%data=randint(number_of_bit,1);
figure(1)
stem(data,'linewidth',3);grid on;
title('information before transmitting');
axis([0 11 0 1.5]);
data_NZR=2*data-1;
%data represented in QPSK modulation
s_p_data=reshape(data_NZR,2,length(data)/2);%S/P converted to data
br=10.^6;%let the transmission bit rATE 1000000
f=br;%minimum carrier frequency
T=1/br;
t=T/99:T/99:T;
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t);
y2=s_p_data(2,i)*sin(2*pi*f*t);
y_in=[y_in y1];
y_qd=[y_qd y2];
y=[y y1+y2];
end
Tx_sig=y;
tt=T/99:T/99:(T*length(data))/2;
figure(2);
subplot(3,1,1);
plot(tt,y_in,'linewidth',3),grid on;
title('waveform for inphase component in QPSK modulation');
xlabel('time(sec)');
ylabel('amplitude(volt)');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3),grid on;
title('waveform for quadrature component in QPSK modulation');
xlabel('time(sec)');
ylabel('amplitude(volt)');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3),grid on;
title(' QPSK modulated signal(sum of inphase and quadrature phase
signal)');
xlabel('time(sec)');
ylabel('amplitude(volt)');
Rx_data=[];
Rx_sig=Tx_sig;
for(i=1:1:length(data)/2)
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
Z_in_intg=(trapz(t,Z_in))*(2/T);
if(Z_in_intg>0)
Rx_in_data=1;
else
Rx_in_data=0;
end
Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
Z_qd_intg=(trapz(t,Z_in))*(2/T);
if(Z_qd_intg>0)
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_data Rx_in_data Rx_qd_data];
end
figure(3)
stem(Rx_data,'linewidth',3)
title('information after receving:');
axis([0 11 0 1.5]),grid on;
FIGURE 1:Input
0.5
0
0 1 2 3 4 5 6 7 8 9 10 11
FIGURE 2:Modulated Waveforms
waveform for inphase component in QPSK modulation
1
0.5
amplitude(volt)
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time(sec) -6
x 10
waveform for quadrature component in QPSK modulation
1
0.5
amplitude(volt)
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time(sec) -6
x 10
QPSK modulated signal(sum of inphase and quadrature phase signal)
2
1
amplitude(volt)
-1
-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time(sec) -6
x 10
FIGURE 3:Output
0.5
0
0 1 2 3 4 5 6 7 8 9 10 11
QAM
M=16;
k=log2(M);
n=3e4;
nSyms=n/k;
hMod=modem.qammod(M);
hMod.InputType='Bit';
hMod.SymbolOrder='Gray';
hDemod=modem.qamdemod(hMod);
x=randi([0 1],n,1);
tx=modulate(hMod,x);
EbNo=0:10;
SNR=EbNo+10*log10(k);
rx=zeros(nSyms,length(SNR));
bit_error_rate=zeros(length(SNR),1);
for i=1:length(SNR)
rx(:,1)=awgn(tx,SNR(i),'measured');
end
rx_demod=demodulate(hDemod,rx);
for i=1:length(SNR)
[~,bit_error_rate(i)]=biterr(x,rx_demod(:,i));
end
theoryBer=3/(2*k)*erfc(sqrt(0.1*k*(10.^(EbNo/10))));
figure;
semilogy(EbNo,theoryBer,'-',EbNo,bit_error_rate,'^-');
grid on;
legend('theory','simulation');
xlabel('Eb/No,dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for 16-QAM MODULATION');
OUTPUT:
Bit error probability curve for 16-QAM MODULATION
0
10
theory
simulation
-1
10
Bit Error Rate
-2
10
-3
10
0 1 2 3 4 5 6 7 8 9 10
Eb/No,dB
FSK modulation and demodulation
clc;
clear all;
close all;
x=[1 0 0 1 1 0 1];
bp=.000001;
disp('binary information at the transmitter:');
disp(x);
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'linewidth',2.5);grid on;
axis([0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel('time(sec)');
title('transmitting information as digital signal');
A=5;
br=1/bp;
f1=br*8;
f2=br*2;
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if(x(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end
m= [m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary FSK modulaion corresponding binary information');
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t);
y2=cos(2*pi*f2*t);
mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm)
z2=trapz(t4,mmm)
zz1=round(2*z1/bp)
zz2=round(2*z2/bp)
if(zz1>A/2)
a=1;
else(zz2>A/2)
a=0;
end
mn=[mn a];
end
disp('binary information at the receiver');
disp(mn);
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3);
plot(t4,bit,'linewidth',2.5);grid on;
axis([0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel('time(sec)');
title('received information as digital signal after binary fsk
demodulation');
transmitting information as digital signal
1.5
1
amplitude(volt)
0.5
-0.5
0 1 2 3 4 5 6 7
time(sec) -6
x 10
waveform for binary FSK modulaion corresponding binary information
5
amplitude(volt)
-5
0 1 2 3 4 5 6 7
time(sec) -6
x 10
received information as digital signal after binary fsk demodulation
1.5
1
amplitude(volt)
0.5
-0.5
0 1 2 3 4 5 6 7
time(sec) -6
x 10
binary information at the transmitter:
1 0 0 1 1 0 1
z1 =2.4555e-06
z2 =-4.7142e-08
zz1 =5
zz2 =0
z1 =-4.7142e-08
z2 =2.4499e-06
zz1 =0
zz2 =5
ans =1
z1 =-4.7142e-08
z2 =2.4499e-06
zz1 =0
zz2 =5
ans =1
z1 =2.4555e-06
z2 =-4.7142e-08
zz1 =5
zz2 =0
z1 =2.4555e-06
z2 =-4.7142e-08
zz1 =5
zz2 =0
z1 =-4.7142e-08
z2 =2.4499e-06
zz1 =0
zz2=5
ans =1
z1 =2.4555e-06
z2 =-4.7142e-08
zz1 =5
zz2 =0
clc;
clear all;
close all;
x=[1 0 0 1 1 0 1];
bp=0.000001;
disp('binary information at the transmitter:');
disp(x);
bit=[];
for n=1:1:length(x);
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'linewidth',2.5);grid on;
axis([0 bp*length(x) -.5 1.5]);
ylabel('amplitude (volt)');
xlabel('time (sec)');
title('transmitting information as digital signal');
A=5;
br=1/bp;
f=br*2;
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if(x(i)==1)
y=A*cos(2*pi*f*t2);
else
y=A*cos(2*pi*f*t2+pi);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary PSK modulation');
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t);
mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm)
zz=round((2*z/bp))
if(zz>0)
a=1;
else
a=0;
end
mn=[mn a];
end
disp('binary information at receiver');
disp(mn);
bit=[];
for n=1:length(mn);
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3);
plot(t4,bit,'linewidth',2.5);grid on;
axis([0 bp*length(mn) -.5 1.5]);
ylabel('amplitude (volt)');
xlabel('time (sec)');
title('received information as digital signal after binary PSK
demodulation');
1
amplitude (volt)
0.5
-0.5
0 1 2 3 4 5 6 7
time (sec) -6
x 10
waveform for binary PSK modulation
5
amplitude(volt)
-5
0 1 2 3 4 5 6 7
time(sec) -6
x 10
received information as digital signal after binary PSK demodulation
1.5
1
amplitude (volt)
0.5
-0.5
0 1 2 3 4 5 6 7
time (sec) -6
x 10
binary information at the transmitter:
1 0 0 1 1 0 1
z =2.4499e-06
zz =5
z =-2.4499e-06
zz =-5
z =-2.4499e-06
zz =-5
z =2.4499e-06
zz =5
z =2.4499e-06
zz =5
z =-2.4499e-06
zz =-5
z =2.4499e-06
zz =5
1 0 0 1 1 0 1
DPSK
PROGRAM:
clc;
clear all;
close all;
M=4;
x=randi([0 M-1],1000,1);
y=dpskmod(x,M,pi/8,'bin');
z=dpskdemod(y,M);
s1=symerr(x,z)
s2=symerr(x(2:end),z(2:end))
y=dpskmod(x,M)
y=dpskmod(x,M,pi/8)
y=dpskmod(x,M,pi/8,'bin')
s=RandStream.create('mt19937ar','seed',131);
prevStream=RandStream.setDefaultStream(s);
M=4;
x=randi([0 M-1],500,1);
y=dpskmod(x,M,pi/8);
plot(y);
OUTPUT:
LINEAR BLOCK CODES
OUTPUT:
enter the generator matrix[1 0 0 0 1 0 1;0 1 0 0 1 1 1;0 0 1 0 1 1 0; 0 0 0 1
0 1 1]
g =
1 0 0 0 1 0 1
0 1 0 0 1 1 1
0 0 1 0 1 1 0
0 0 0 1 0 1 1
G=the order of the linear block for the given generator matrix:
n =7
k =4
the possible codewords are:
c =
0 0 0 0 0 0 0
0 0 0 1 0 1 1
0 0 1 0 1 1 0
0 0 1 1 1 0 1
0 1 0 0 1 1 1
0 1 0 1 1 0 0
0 1 1 0 0 0 1
0 1 1 1 0 1 0
1 0 0 0 1 0 1
1 0 0 1 1 1 0
1 0 1 0 0 1 1
1 0 1 1 0 0 0
1 1 0 0 0 1 0
1 1 0 1 0 0 1
1 1 1 0 1 0 0
1 1 1 1 1 1 1
r =
1 0 0 0 1 0 0
Hamming code
ht =
1 0 1
1 1 1
1 1 0
0 1 1
1 0 0
0 1 0
0 0 1
PROGRAM:
clc;
clear all;
close all;
CNup=30:1:60;
ln=length(CNup);
k=-228.6;
T1=500;
Ts1=10*log10(T1);
B1=10*log10(43.2*10^6);
N1=k+Ts1+B1;
Pr1=N1+CNup;
R=4*10^7;
D=5;
Ae=0.68;
lmb=0.0212;
Gt1=10*log10(Ae*(pi*D/lmb)^2);
Lp1=10*log10((4*pi*R/lmb)^2);
Gr1=31;
Lp1=-Lp1;
Lant=-2;
Pt1=Pr1-(Gt1+Gr1+Lp1+Lant);
for i=1:ln
Ptw(i)=10^(Pt1(i)/10);
end
subplot(2,1,1);
plot(CNup,Ptw,'linewidth',1.5);
xlabel('C/N ratio in db');
ylabel('Transmitted power Pt in Watts');
title('C/N vs. Pt');
grid on;
CNdwn=17.2:1:50;
ln=length(CNdwn);
k=-228.6;
T2=30;
Ts2=10*log10(T2);
B2=10*log10(43.2*10^6);
N2=k+Ts2+B2;
Pr2=N2+CNdwn;
Lp2=207.2-20*log10(14.15/11.45);
Pt2=10*log10(80)-1;
Gt2=31;
Lp2=-Lp2;
La=-3;
Gr2=Pr2-(Pt2+Gt2+Lp2+La);
for i=1:ln
Grw(i)=10^(Gr2(i)/10);
end
subplot(2,1,2);
plot(CNdwn,Grw,'linewidth',1.5);
xlabel('C/N ratio in db');
ylabel('Receiving Antenna gain Gr in watts');
title('C/N vs. Gr');
grid on;
OUTPUT:
Zero forcing algorithm:
Program:
clc;
clear all;
close all;
T=1;
No=1;
Fs=2/T;
Ts=1/Fs;
t=-10*T:T/2:10*T;
x=1./(1+((0.5/T)*t).^2);
stem(t,x);
X=[];
for m=-2:1:2
for n=-2:1:2
X(m+3,n+3)=1./(1+((0.5/T)*(m*T-n*T/2)).^2);
end
end
k=inv(X);
copt=K*[0 0 1 00]';
equalizedoutput= filter(copt,1,[X 00]);
figure;
stem(x);
figure;
stem(equalizeoutput);
Output:
LMS PROGRAM:
clc;
close all;
clear all;
N=input('length of sequence N=');
t=[0:N-1];
w0=0.001; phi=0.1;
d=sin(2*pi*[1:N]*w0+phi);
x=d+randn(1,N)*0.5;
w=zeros(1,N);
mu=input('mu=');
for i=1:N
e(i)=d(i)-w(i)'*x(i);
w(i+1)=w(i)+mu*e(i)*x(i);
end
for i=1:N
yd(i)=sum(w(i)'*x(i));
end
subplot(2,2,1),plot(t,d),ylabel('desired signal'),
subplot(2,2,2),plot(t,x),ylabel('input signal + noise'),
subplot(2,2,3),plot(t,e),ylabel('error'),
subplot(2,2,4),plot(t,yd),ylabel('adaptive desired output');
OUTPUT: