Вы находитесь на странице: 1из 23

Band pass Techniques

ASK ................................................................................................................................................................ 2
PSK ................................................................................................................................................................ 6
FSK ............................................................................................................................................................... 10
QPSK ............................................................................................................................................................ 14
PAM............................................................................................................................................................. 18
PWM ........................................................................................................................................................... 21

ASK
clear screen
clear all
clc
%% Bit Genration
x=round(rand(1,102));
d=1;
t=0:1/1000:0.3;
w=110;
%% Signals
%By using 8 ASK
s1=1*(cos(w*t));
s2=5*(cos(w*t));
s3=9*(cos(w*t));
s4=13*(cos(w*t));
s5=17*(cos(w*t));
s6=21*(cos(w*t));
s7=25*(cos(w*t));
s8=29*(cos(w*t));
%% Modulation
% mod is empty vector and when use in loop it store the new value and also
% keep the previous value
mod=[];
%Genrating the information (MODULATION)
for(i=1:3:length(x))
if(x(i)==0 && x(i+1)==0 && x(i+2)==0)
mod=[mod s1];
elseif(x(i)==0 && x(i+1)==0 && x(i+2)==1)
mod=[mod s2];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==0)
mod=[mod s3];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==1)
mod=[mod s4];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==0)
mod=[mod s5];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==1)
mod=[mod s6];
elseif(x(i)==1 && x(i+1)==1 && x(i+2)==0)
mod=[mod s7];
elseif(x(i)==1 && x(i+1)==1 && x(i+2)==1)

mod=[mod s8];
end
end
Val=mod;
cv=length(t);
subplot(3,1,1)
plot(Val)
%% Transmission
%SNR signal to noise ratio
snr=1;
zxc=awgn(Val,snr);
subplot(3,1,2)
plot(zxc)
%% Reciving (De-MODULATION)
for(i=1:length(x)/3)
dem(i,:)=Val((((i-1)*cv)+1):i*cv);
end
for(i=1:length(x)/3)
g(i)=max(dem(i,:));
if(g(i)<=3)
xs(i)=1;
elseif(g(i)>3 && g(i)<=7)
xs(i)=2;
elseif(g(i)>7 && g(i)<=11)
xs(i)=3;
elseif(g(i)>11 && g(i)<=15)
xs(i)=4;
elseif(g(i)>15 && g(i)<=19)
xs(i)=5;
elseif(g(i)>19 && g(i)<=23)
xs(i)=6;
elseif(g(i)>23 && g(i)<=27)
xs(i)=7;
elseif(g(i)>27 && g(i)<=31)
xs(i)=8;
end
end
%% Decision Making
%comparing the vector xs positions with the numbers to judge what signal
transmited
d=1;
for(i=1:3:length(x))

if(xs(d)==1)
val(i)=0;
val(i+1)=0;
val(i+2)=0;

elseif(xs(d)==2)
val(i)=0;
val(i+1)=0;
val(i+2)=1;

elseif(xs(d)==3)
val(i)=0;
val(i+1)=1;
val(i+2)=0;

elseif(xs(d)==4)
val(i)=0;
val(i+1)=1;
val(i+2)=1;

elseif(xs(d)==5)
val(i)=1;
val(i+1)=0;
val(i+2)=0;

elseif(xs(d)==6)
val(i)=1;
val(i+1)=0;
val(i+2)=1;

elseif(xs(d)==7)
val(i)=1;
val(i+1)=1;
val(i+2)=0;

elseif(xs(d)==8)
val(i)=1;
val(i+1)=1;
val(i+2)=1;
end
d=d+1;
end

%% Error
%xor(val,x) is use to show the error in the input and output if any one bit
%is changed output is 1 else zero.
num2str is used to display the all
%bits in a string
Error=sum((xor(val,x)))

PSK
clear all
clc
%% Bits Generation
x=round(rand(1,1002));
t=0:1/1000:0.3;

% Sampling Time

%% Phases
th1=44;
th2=89;
th3=134;
th4=179;
th5=224;
th6=269;
th7=314;
th8=359;
%% Signals
w=250; %frequency
s1=5*(cos(w*t+th1));
s2=5*(cos(w*t+th2));
s3=5*(cos(w*t+th3));
s4=5*(cos(w*t+th4));
s5=5*(cos(w*t+th5));
s6=5*(cos(w*t+th6));
s7=5*(cos(w*t+th7));
s8=5*(cos(w*t+th8));

%% Modulation
%By Using 8-PSK
Val=[];
for(i=1:3:length(x))
if(x(i)==0 && x(i+1)==0 && x(i+2)==0)
Val=[Val s1];
elseif(x(i)==0 && x(i+1)==0 && x(i+2)==1)
Val=[Val s2];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==0)
Val=[Val s3];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==1)
Val=[Val s4];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==0)
Val=[Val s5];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==1)
Val=[Val s6];

elseif(x(i)==1 && x(i+1)==1 && x(i+2)==0)


Val=[Val s7];
elseif(x(i)==1 && x(i+1)==1 && x(i+2)==1)
Val=[Val s8];
end
end

subplot(2,1,1)
plot(Val);
%% Transmission
subplot(2,1,2)
Val=awgn(Val,1);
plot(Val);
%% DE-Modulation
cv=length(t);
for(i=1:length(x)/3)
dem(i,:)=Val((((i-1)*cv)+1):i*cv);
% Correlation function using to find maximum values
end
for(i=1:length(x)/3)
xc=dem(i,:);
co1=xcorr(xc,s1);
mx1=max(co1);
co2=xcorr(xc,s2);
mx2=max(co2);
co3=xcorr(xc,s3);
mx3=max(co3);
co4=xcorr(xc,s4);
mx4=max(co4);
co5=xcorr(xc,s5);
mx5=max(co5);
co6=xcorr(xc,s6);
mx6=max(co6);
co7=xcorr(xc,s7);
mx7=max(co7);
co8=xcorr(xc,s8);

mx8=max(co8);
mx=[mx1,mx2,mx3,mx4,mx5,mx6,mx7,mx8];
[as,pos]=max(mx);
xs(i)=pos;
end
% xs is the vector which have the position of all the transmitted bits
%% Decision Making
%comparing the vector xs positions with the numbers to judge what signal
transmited
d=1;
for(i=1:3:length(x))
if(xs(d)==1)
val(i)=0;
val(i+1)=0;
val(i+2)=0;

elseif(xs(d)==2)
val(i)=0;
val(i+1)=0;
val(i+2)=1;

elseif(xs(d)==3)
val(i)=0;
val(i+1)=1;
val(i+2)=0;

elseif(xs(d)==4)
val(i)=0;
val(i+1)=1;
val(i+2)=1;

elseif(xs(d)==5)
val(i)=1;
val(i+1)=0;
val(i+2)=0;

elseif(xs(d)==6)
val(i)=1;
val(i+1)=0;
val(i+2)=1;

elseif(xs(d)==7)

val(i)=1;
val(i+1)=1;
val(i+2)=0;

elseif(xs(d)==8)
val(i)=1;
val(i+1)=1;
val(i+2)=1;
end
d=d+1;
end
%val is the vector which have all the bits after demodulation
%% Error
Error=sum(xor(x,val))
%disp commands display the mesage on the Main scree of Matlab
disp('Input Bits')
num2str(x)
disp('Output Bits After Demodulation')
num2str(val)

FSK
clear all
clc
x=round(rand(1,1002));
t=0:1/1000:0.3;

% Sampling Time

%% Frequencies
w1=20;
w2=45;
w3=70;
w4=95;
w5=110;
w6=130;
w7=165;
w8=220;
%% Signals
s1=5*(cos(w1*t+0));
s2=5*(cos(w2*t+0));
s3=5*(cos(w3*t+0));
s4=5*(cos(w4*t+0));
s5=5*(cos(w5*t+0));
s6=5*(cos(w6*t+0));
s7=5*(cos(w7*t+0));
s8=5*(cos(w8*t+0));

%% Modulation
%By Using 8-FSK
Val=[];
for(i=1:3:length(x))
if(x(i)==0 && x(i+1)==0 && x(i+2)==0)
Val=[Val s1];
elseif(x(i)==0 && x(i+1)==0 && x(i+2)==1)
Val=[Val s2];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==0)
Val=[Val s3];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==1)
Val=[Val s4];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==0)
Val=[Val s5];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==1)
Val=[Val s6];
elseif(x(i)==1 && x(i+1)==1 && x(i+2)==0)
Val=[Val s7];
elseif(x(i)==1 && x(i+1)==1 && x(i+2)==1)

Val=[Val s8];
end
end

subplot(2,1,1)
plot(Val);
%% Transmission
subplot(2,1,2)
Val=awgn(Val,1);
plot(Val);
%% DE-Modulation
cv=length(t);
for(i=1:length(x)/3)
dem(i,:)=Val((((i-1)*cv)+1):i*cv);
% Correlation function using to find maximum values
end
for(i=1:length(x)/3)
xc=dem(i,:);
co1=xcorr(xc,s1);
mx1=max(co1);
co2=xcorr(xc,s2);
mx2=max(co2);
co3=xcorr(xc,s3);
mx3=max(co3);
co4=xcorr(xc,s4);
mx4=max(co4);
co5=xcorr(xc,s5);
mx5=max(co5);
co6=xcorr(xc,s6);
mx6=max(co6);
co7=xcorr(xc,s7);
mx7=max(co7);
co8=xcorr(xc,s8);
mx8=max(co8);
mx=[mx1,mx2,mx3,mx4,mx5,mx6,mx7,mx8];
[as,pos]=max(mx);

xs(i)=pos;
end
% xs is the vector which have the position of all the transmitted bits
%% Decision Making
%comparing the vector xs positions with the numbers to judge what signal
transmited
d=1;
for(i=1:3:length(x))
if(xs(d)==1)
val(i)=0;
val(i+1)=0;
val(i+2)=0;

elseif(xs(d)==2)
val(i)=0;
val(i+1)=0;
val(i+2)=1;

elseif(xs(d)==3)
val(i)=0;
val(i+1)=1;
val(i+2)=0;

elseif(xs(d)==4)
val(i)=0;
val(i+1)=1;
val(i+2)=1;

elseif(xs(d)==5)
val(i)=1;
val(i+1)=0;
val(i+2)=0;

elseif(xs(d)==6)
val(i)=1;
val(i+1)=0;
val(i+2)=1;

elseif(xs(d)==7)
val(i)=1;
val(i+1)=1;
val(i+2)=0;

elseif(xs(d)==8)
val(i)=1;
val(i+1)=1;
val(i+2)=1;
end
d=d+1;
end
%val is the vector which have all the bits after demodulation
%% Error
Error=sum(xor(x,val))
%disp commands display the mesage on the Main scree of Matlab
disp('Input Bits')
num2str(x)
disp('Output Bits After Demodulation')
num2str(val)

QPSK
clear screen
clear all
clc
%% Bits Generation
x=round(rand(1,102));
d=1;
t=0:1/1000:0.3;
w=110;
%%Signals
%By using ASK and PSK
s1=1*(cos(w*t+179));
s2=1*(cos(w*t+358));
s3=9*(cos(w*t+179));
s4=9*(cos(w*t+359));
s5=17*(cos(w*t+179));
s6=17*(cos(w*t+359));
s7=25*(cos(w*t+179));
s8=25*(cos(w*t+359));
%% Modulation
% mod is empty vector and when use in loop it store the new value and also
% keep the previous value
mod=[];
%Genrating the information (MODULATION)
for(i=1:3:length(x))
if(x(i)==0 && x(i+1)==0 && x(i+2)==0)
mod=[mod s1];
elseif(x(i)==0 && x(i+1)==0 && x(i+2)==1)
mod=[mod s2];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==0)
mod=[mod s3];
elseif(x(i)==0 && x(i+1)==1 && x(i+2)==1)
mod=[mod s4];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==0)
mod=[mod s5];
elseif(x(i)==1 && x(i+1)==0 && x(i+2)==1)
mod=[mod s6];
elseif(x(i)==1 && x(i+1)==1 && x(i+2)==0)
mod=[mod s7];

elseif(x(i)==1 && x(i+1)==1 && x(i+2)==1)


mod=[mod s8];
end
end
Val=mod;
cv=length(t);
subplot(3,1,1)
plot(Val)
%% Transmission
%SNR signal to noise ratio
snr=1;
zxc=awgn(Val,snr);
subplot(3,1,2)
plot(zxc)
%% Reciving (De-MODULATION)
for(i=1:length(x)/3)
dem(i,:)=Val((((i-1)*cv)+1):i*cv);
end
for(i=1:length(x)/3)
g(i)=max(dem(i,:));
xc=dem(i,:);

if(g(i)<=5)
mx1=max(xcorr(xc,s1));
mx2=max(xcorr(xc,s2));
mx=[mx1,mx2];
[as,pos]=max(mx);
xs(i)=pos;
elseif(g(i)>5 && g(i)<=14)
mx1=max(xcorr(xc,s3));
mx2=max(xcorr(xc,s4));
mx=[0,0,mx1,mx2];
[as,pos]=max(mx);
xs(i)=pos;
elseif(g(i)>14 && g(i)<=22)
mx1=max(xcorr(xc,s5));
mx2=max(xcorr(xc,s6));

mx=[0,0,0,0,mx1,mx2];
[as,pos]=max(mx);
xs(i)=pos;
elseif(g(i)>22 && g(i)<=30)
mx1=max(xcorr(xc,s7));
mx2=max(xcorr(xc,s8));
mx=[0,0,0,0,0,0,mx1,mx2];
[as,pos]=max(mx);
xs(i)=pos;

end
end
%% Decison Making
%Comparing the vector xs positions with the numbers to judge what signal
transmited
val=[];
for(i=1:length(x)/3)
if(xs(i)==1)
val=[val 0 0 0];
elseif(xs(i)==2)
val=[val 0 0 1];
elseif(xs(i)==3)
val=[val 0 1 0];
elseif(xs(i)==4)
val=[val 0 1 1];
elseif(xs(i)==5)
val=[val 1 0 0];
elseif(xs(i)==6)
val=[val 1 0 1];
elseif(xs(i)==7)
val=[val 1 1 0];
elseif(xs(i)==8)

val=[val 1 1 1];
end
end
%% Error
%xor(val,x) is use to show the error in the input and output if any one bit
%is changed output is 1 else zero.
num2str is used to display the all
%bits in a string
Error=sum(xor(val,x))

PAM
clf
clc
clear screen
close all
%%User Defined
size=1000;

%Size of genrated bits

N_A=2;

%Amplitude of the Noise

W_S=5;

%Width of rectangular pulse

%% Bit Genration
bits=round(rand(1,size));
L_B=length(bits);

%Genration of bits
%length of bits

%% Modulation
mod=[];
for i=1:2:L_B
if(bits(i)==0 && bits(i+1)==0)
x=-3*ones(1,W_S);
elseif(bits(i)==0 && bits(i+1)==1)
x=-1*ones(1,W_S);
elseif(bits(i)==1 && bits(i+1)==1)
x=1*ones(1,W_S);
elseif(bits(i)==1 && bits(i+1)==0)
x=3*ones(1,W_S);
end
mod=[mod x];

% Modulated Signal

end
S_P=sum(mod.^2);

% Signal Power

%% Transmition
Noise=2*N_A*rand(1,((L_B*W_S)/2))-N_A; %Noise Signal Genration
N_P=sum(Noise.^2);

%Noise Power

Transmit=mod+Noise;

%Transmited Signal

%% Recving
T_L=length(Transmit);
demod=[];

%Demodulated Signal

for i=1:W_S:T_L
x=Transmit(i:i+W_S-1);
y=sum(x)/W_S;
if y > 2
demod=[demod 1 0];
elseif y>0 && y<=2
demod=[demod 1 1];
elseif y>-2 && y<=0
demod=[demod 0 1];
else
demod=[demod 0 0];
end
end

%% Errors and Signal Strength


loss=xor(bits,demod)
Error=sum(loss)

%Error in the Transmitted Signal

SNR=10*log(S_P/N_P)

%% Signals Ploting / Graphical view


figure
subplot(2,1,1)
stem(bits)
title('Information at source end')

subplot(2,1,2)
stem(demod)
title('Information at reciving end')

figure
subplot(2,1,1)
stem(Transmit)
title('Signal in medium')
subplot(2,1,2)
stem(loss)
title('Signal lost in medium')

%Signal to Noise Ratio of the Signal

PWM
clf
clc
clear screen
close all
%%User Defined
size=1000;

%Size of genrated bits

N_A=2;

%Amplitude of the Noise

W_S=2;

%Width of rectangular pulse

%% Bit Generation
bits=round(rand(1,size));
L_B=length(bits);

%Genration of bits
%length of bits

%% Modulation
mod=[];
for i=1:2:L_B
if(bits(i)==0 && bits(i+1)==0)
x=16*ones(1,1*W_S);
y=16*zeros(1,3*W_S);
elseif(bits(i)==0 && bits(i+1)==1)
x=16*ones(1,2*W_S);
y=16*zeros(1,2*W_S);
elseif(bits(i)==1 && bits(i+1)==1)
x=16*ones(1,3*W_S);
y=16*zeros(1,1*W_S);
elseif(bits(i)==1 && bits(i+1)==0)

x=16*ones(1,4*W_S);
y=16*zeros(1,0*W_S);
end
mod=[mod x y];

% Modulated Signal

end
S_P=sum(mod.^2);

% Signal Power

%% Transmition
Noise=2*N_A*rand(1,((4*L_B*W_S)/2))-N_A; %Noise Signal Genration
N_P=sum(Noise.^2);
Transmit=mod+Noise;

% Noise Power
%Transmited Signal

%% Receiving
T_L=length(Transmit);
demod=[];
for i=1:4*W_S:T_L
x=Transmit(i:i+(4*W_S)-1)
y=sum(x)/W_S;
if y > 13
demod=[demod 1 0];
elseif y>9 && y<=13
demod=[demod 1 1];
elseif y>5 && y<=9
demod=[demod 0 1];
else
demod=[demod 0 0];
end
end

%Demodulated Signal

%% Errors and Signal Strength


loss=xor(bits,demod)
Error=sum(loss)

%Error in the Transmited Signal

SNR=10*log(S_P/N_P)

%% Signals Ploting / Graphical view


figure
subplot(2,1,1)
stem(bits)
title('Information at source end')

subplot(2,1,2)
stem(demod)
title('Information at reciving end')

figure
subplot(2,1,1)
stem(Transmit)
title('Signal in medium')
subplot(2,1,2)
stem(loss)
title('Signal lost in medium')

%Signal to Noise Ratio of the Signal

Вам также может понравиться