Vous êtes sur la page 1sur 26

FREQUENCY SHIFT KEYING MODULATION AND DEMODULATION

Program coding:
clc;
clear all;
f=500;
fc=700;
fs=100*fc;
x=Randint(1,20,[0,1]);
l=length(x);
n=0:l-1;
m=0:l*fs/f;
c=cos(2*3.14*(fc/fs)*m);
y=dmod(x,fc,f,fs,'fsk',2);
z=ddemod(y,fc,f,fs,'fsk',2);
figure();
subplot(4,1,1),stem(n,x),axis([0 20 0 1]),title('frequency shift keying'),grid,title('message
bits');
subplot(4,1,2),plot(c,'g'),axis([0 l*(fs/f) -1 1]), grid,title('carrier signal');
subplot(4,1,3),plot(y,'r'),axis([0 l*(fs/f) -1 1]), grid,title('modulated bits');
subplot(4,1,4),stem(n,z),axis([0 20 0 1],grid,title('demodulated bits');
xlabel('time period');
ylabel('amplitude');

OUTPUT:

m e s s a g e bits
1
0.5
0

10
12
c a rrie r s ig n a l

14

16

18

20

1
0
-1

5 00

1000

1500
m o d u la te d s ig n a l

2 0 00

2500

5 00

1000

1500
de m o d u la te d bits

2 0 00

2500

14

1
0
-1

am p

1
0.5
0

10
tim e

12

16

18

20

AMPLITUDE SHIFT KEYING MODULATION AND DEMODULATION

Program coding:
clc;
clear all;
f=500;
fc=800;
fs=100*fc;
x=Randint(1,20,[0,1]);
l=length(x);
n=0:l-1;
m=0:l*fs/f;
c=sin(2*pi*(fc/fs)*m);
y=dmod(x,fc,f,fs,'ask',4);
z=ddemod(y,fc,f,fs,'ask',4);
figure();
subplot(4,1,1),stem(n,x),axis([0 20 0 1]),title('amplitude shift keying'),grid,title('message
bits');
subplot(4,1,2),plot(c,'g'),axis([0 l*(fs/f) -1 1]),grid,title('carrier signal');
subplot(4,1,3),plot(y,'r'),axis([0 l*(fs/f) -1 1]),grid,title('modulated signal');
subplot(4,1,4),stem(n,z),axis([0 20 0 1]),grid,title('demodulated bits');
xlabel('time period');
ylabel('amplitude');

OUTPUT:

m e s s a g e b its
1
0 .5
0

10
12
c a rrie r s ig n a l

14

16

18

20

1
0
-1

500

1000

1500
2000
m o d u la te d s ig n a l

2500

3000

500

1000

1500
2000
d e m o d u la te d b its

2500

3000

1
0
-1

am p

1
0 .5
0

10
tim e

12

14

16

18

20

PHASE SHIFT KEYING MODULATION AND DEMODULATION


Program coding:

clc;
clear all;
f=500;
fc=1000;
fs=100*fc;
x=Randint(1,10,[0,1]);
l=length(x);
n=0:l-1;
m=0:l*fs/f;
c=cos(2*pi*(fc/fs)*m);
y=dmod(x,fc,f,fs,'psk',2);
z=ddemod(y,fc,f,fs,'psk',2);
figure();
subplot(4,1,1),stem(n,x),axis([0 10 0 1]),title('phase shift keying'),grid,title('message bits');
subplot(4,1,2),plot(c,'g'),axis([0 l*(fs/f) -1 1]),grid,title('carrier signal');
subplot(4,1,3),plot(y,'r'),axis([0 l*(fs/f) -1 1]),grid,title('modulated signal');
subplot(4,1,4),stem(n,z),axis([0 10 0 1]),grid,title('demodulated bits');
xlabel('time period');
ylabel('amplitude');

OUTPUT:

m e s s a ge bits
1
0.5
0

200

400

600

200

400

600

5
6
c arrie r s ign al

10

800
10 00 1200
m odu late d s igna l

1400

16 00

1800

2000

800
10 00 1200
d em od ulated bits

1400

16 00

1800

2000

10

1
0
-1
1
0
-1

am p

1
0.5
0

5
tim e

M-ARRAY FREQUENCY SHIFT KEYING MODULATION AND DEMOULATION


Program coding:
clc;
clear all;
close all;
M=[4,8,16];
k=log2(M);
n=10*4*3;
Fc=900;
Fs=100*Fc;
Fd=500;
type='fsk';
EbNo=1:1:10;
x=Randint(n,1);
l=20;
m=0:l*(Fs/Fd);
c=sin(2*pi*(Fc/Fs)*m);
length(M);
for i=1:1:length(M);
ll=k(i);
xsym=bi2de(reshape(x,k(i),length(x)/k(i)).','left-msb');
y=dmod(xsym,Fc,Fd,Fs,'fsk',M(i));
Syy1=10*log10(fftshift(abs(fft(y))));
ly1=length(y);
freq1=(-Fs/2:Fs/ly1:(Fs/2)-(Fs/ly1));
zsym=ddemod(y,Fc,Fd,Fs,type,M(i));
z=de2bi(zsym,'left-msb');
z=reshape(z.',numel(z),1);
figure();
subplot(4,1,1),stem(xsym'),axis([0 20 0 M(i)]),grid,title([type,'M= ',num2str(M(i))]);
subplot(4,1,2),plot(c,'g'),axis([0 l*(Fs/Fd) -1 1]),grid,title('CARRIER SIGNAL');
subplot(4,1,3),plot(y,'r'),axis([0 l*(Fs/Fd) -1 1]),grid,title('MODULATED SIGNAL');
subplot(4,1,4),stem(zsym'),axis([0 20 0 M(i)]),grid, title('DEMODULATED SIGNAL');

xlabel('TIME');
ylabel('AMPLITUDE');
end
figure();
for i=1:1:length(M)
ber=berawgn(EbNo,type,M(i),'nondiff');
semilogy(EbNo,ber);
hold all;
end
title('BIT ERROR PROBABILITY OF fsk');
xlabel('EbNo in dB');
ylabel('BER');
grid,legend('M=4','M=8','M=16');

OUTPUT:

fskM= 4
4
2
0

10

12

14

16

18

20

CARRIER SIGNAL
1
0
-1

500

1000

1500

2000

2500

3000

3500

2500

3000

3500

MODULATED SIGNAL

AMPLITUDE

1
0
-1

500

1000

1500

2000

DEMODULATED SIGNAL
4
2
0

10
TIME

12

14

16

18

20

fskM= 16
10
0

10

12

14

16

18

20

CARRIER SIGNAL
1
0
-1

500

1000

1500

2000

2500

3000

3500

2500

3000

3500

MODULATED SIGNAL

AMPLITUDE

1
0
-1

500

1000

1500

2000

DEMODULATED SIGNAL
10
0

10
TIME

12

14

16

18

20

M-ARRAY PHASE SHIFT KEYING MODULATION AND DEMODULATION


Program coding:
clc;
clear all;
close all;
M=[4,8,16];
k=log2(M);
n=10*4*3;
Fc=900;
Fs=100*Fc;
Fd=500;
type='psk';
EbNo=1:1:10;
x=Randint(n,1);
l=20;
m=0:l*(Fs/Fd);
c=sin(2*pi*(Fc/Fs)*m);
length(M);
for i=1:1:length(M);
ll=k(i);
xsym=bi2de(reshape(x,k(i),length(x)/k(i)).','left-msb');
y=dmod(xsym,Fc,Fd,Fs,'psk',M(i));
Syy1=10*log10(fftshift(abs(fft(y))));
ly1=length(y);
freq1=(-Fs/2:Fs/ly1:(Fs/2)-(Fs/ly1));
zsym=ddemod(y,Fc,Fd,Fs,type,M(i));
z=de2bi(zsym,'left-msb');
z=reshape(z.',numel(z),1);
figure();
subplot(4,1,1),stem(xsym'),axis([0 20 0 M(i)]),grid,title([type,'M= ',num2str(M(i))]);
subplot(4,1,2),plot(c,'g'),axis([0 l*(Fs/Fd) -1 1]),grid,title('CARRIER SIGNAL');
subplot(4,1,3),plot(y,'r'),axis([0 l*(Fs/Fd) -1 1]),grid,title('MODULATED SIGNAL');

subplot(4,1,4),stem(zsym'),axis([0 20 0 M(i)]),grid, title('DEMODULATED SIGNAL');


xlabel('TIME');
ylabel('AMPLITUDE');
end
figure();
for i=1:1:length(M)
ber=berawgn(EbNo,type,M(i),'nondiff');
semilogy(EbNo,ber);
hold all;
end
title('BIT ERROR PROBABILITY OF psk');
xlabel('EbNo in dB');
ylabel('BER');
grid,legend('M=4','M=8','M=16');

OUTPUT:
pskM= 4
4
2
0

8
10
12
CARRIER SIGNAL

14

16

18

20

1
0
-1

500

1000

1500
2000
MODULATED SIGNAL

2500

3000

3500

500

1000

1500
2000
DEMODULATED SIGNAL

2500

3000

3500

1
0

AMPLITUDE

-1
4
2
0

10
TIME

12

14

16

18

20

12

14

16

18

20

pskM= 8
5
0

10

CARRIER SIGNAL
1
0
-1

500

1000

1500

2000

2500

3000

3500

2500

3000

3500

MODULATED SIGNAL

AMPLITUDE

1
0
-1

500

1000

1500

2000

DEMODULATED SIGNAL
5
0

10
TIME

12

14

16

18

20

pskM= 16
10
0

10

12

14

16

18

20

CARRIER SIGNAL
1
0
-1

500

1000

1500

2000

2500

3000

3500

2500

3000

3500

MODULATED SIGNAL

AMPLITUDE

1
0
-1

500

1000

1500

2000

DEMODULATED SIGNAL
10
0

10

10

10

BER

10

10

10

10

10
TIME

12

14

16

18

20

BIT E RROR PROB A B ILITY OF psk

M =4
M =8
M =16

-1

-2

-3

-4

-5

-6

5
6
EbNo in dB

10

BIT ERROR RATE OF FSK


Program coding:
clc;
clear all;
N=10^5;
T=8;
t=[0:1/T:0.99];
tR=kron(ones(1,N),t);
Eb_N0_db=[0:11];
for ii=1:length(Eb_N0_db)
%generating the bits
ip=rand(1,N)>0.5;
freqM=ip+1;
freqR=kron(freqM,ones(1,T));
x=(sqrt(2)/sqrt(T))*cos(2*pi*freqR.*tR);
n=1/sqrt(2)*[randn(1,N*T)+1i*randn(1,N*T)];
y=x+10^(-Eb_N0_db(ii)/20)*n;
op1=conv(y,sqrt(2/T)*cos(2*pi*1*t));
op2=conv(y,sqrt(2/T)*cos(2*pi*2*t));
ipHat=[real(op1(T+1:T:end))<real(op2(T+1:T:end))];
nErr(ii)=size(find([ip-ipHat]),2);
end
simBer=nErr/N;
theoryBer=0.5*erfc(sqrt(10.^(Eb_N0_db/10))/2);
close all
figure
semilogy(Eb_N0_db,theoryBer,'b-');
hold on
semilogy(Eb_N0_db,simBer,'mx-');
axis([0 11 10^-4 0.5])
grid on
legend('theory:fsk-coh','sim:fsk-coh');
xlabel('Eb/No,db')

ylabel('bit error rate')


title('bit error probablilty error')

OUTPUT:
b it e rro r p ro b a b lilty e rro r
th e o ry :fs k -c o h
s im :fs k -c o h

b it e rro r ra te

10

10

10

10

-1

-2

-3

-4

5
6
E b /N o ,d b

10

11

BIT ERROR RATE OF PSK


Program coding:
clc;
clear all;
N=10^6;
rand('state',100);
rand('state',200);
%transmitter
ip=rand(1,N)>0.5;
s=2*ip-1;
n=1/sqrt(2)*[randn(1,N)+1i*randn(1,N)];
Eb_N0_db=[-3:10];
for ii=1:length(Eb_N0_db)
y=s+10^(-Eb_N0_db(ii)/20)*n;
ipHat=real(y)>0;
nErr(ii)=size(find([ip-ipHat]),2);
end
simBer=nErr/N;
theoryBer=0.5*erfc(sqrt(10.^(Eb_N0_db/10))/2);
close all
figure
semilogy(Eb_N0_db,theoryBer,'b-');
hold on
semilogy(Eb_N0_db,simBer,'mx-');
axis([-3 10 10^-5 0.5])
grid on
legend('theory:psk-coh','sim:psk-coh');
xlabel('Eb/No,db')
ylabel('bit error rate')
title('bit error probablilty error')

OUTPUT:
b it e rro r p ro b a b lilty e rro r
th e o ry :p s k -c o h
s im :p s k -c o h
10

b it e rro r ra te

10

10

10

10

-1

-2

-3

-4

-5

-2

4
E b /N o ,d b

10

MONOALPHABETIC CEASAR CIPHER


Program coding:
clc;
clearall;
disp('MONOALPHABETIC CAESER CIPHER');
disp('');
pt=input('Enter the plain text:');
asc=double(pt);
disp('');
shift=input('Enter the left shift(+1) or right shift(-1):');
mt=asc;
%ENCRYPTION
for i=1:length(mt)
mt(i)=mt(i)+shift;
ifmt(i)>127
corr=mt(i)-127;
mt(i)=32+corr-1;
end
end
disp('');
disp('CIPHER TEXT');
disp(char(mt));
%DECRYPTION
for i=1:length(mt)
mt(i)=mt(i)-shift;
ifmt(i)<32
corr=32-mt(i);
mt(i)=127-corr+1;
end
end
disp('');

disp('DECRYPTED TEXT');
disp(char(mt));

SAMPLE INPUT AND OUTPUT:


Case i:
Enter the plain text : ['ece']
Enter the left shift(+1) or right shift(-1): 1
CIPHER TEXT
fdf
DECRYPTED TEXT
ece
Case ii:
Enter the plain text: ['ece']
Enter the left shift(+1) or right shift(-1): -1
CIPHER TEXT
dbd
DECRYPTED TEXT
ece

POLY ALPHABETIC CIPHER-TRITHEMIUS KEY


Program coding:
clc;
closeall;
disp('POLY ALPHABETIC CIPHER-TRITHEMIUS KEY');
pt=input('Enter the plain text:');
asc=double(pt);
disp('');
type=input('Enter the left shift key(+1) or right shift(-1):');
start=32:127;
for i=1:96
if type==1
k=96-i+1;
elseif type==-1
k=i+1;
if i==96
k=1;
end
end
end
for j=1:96
tri(i,j)=start(k);
if k==96
k=0;
end
k=k+1;
end
end
mt=asc;
for i=1:length(mt)
col=mt(i)-31;

mt(i)=tri(i,col);
end

disp('');
disp('CIPHER TEXT:');
disp(char(mt));
for i=1:length(mt)
col=mt(i)-31;
mt(i)=tri(96-i,col);
end
disp('');
disp('DECRYPTED TEXT:');
disp(char(mt));
disp('');

SAMPLE INPUT AND OUTPUT:


POLY ALPHABETIC CIPHER-TRITHEMIUS KEY
Case i:
Enter the plain text:['sun']
Enter the left shift key(+1) or right shift(-1):1
CIPHER TEXT:
rtm
DECRYPTED TEXT:
Sun
Case ii:
Enter the plain text:['sun']
Enter the left shift key(+1) or right shift(-1):-1
CIPHER TEXT:
tvo
DECRYPTED TEXT:
sun

RIVEST, SHAMIR AND ADLEMAN (RSA) ALGORITHM


Program coding:
clc;
clearall;
closeall;
disp('RSA METHOD');
disp('');
pt=input('Enter plain text: ');
asc=double(pt);
mt=asc;
n=input('Enter value of n(public): ');
ea=input('Enter value of ea(public): ');
da=input('Enter value of da(secret): ');
eb=input('Enter value of eb(public): ');
db=input('Enter value of db(secret): ');
%SIGNING
for i=1:length(mt)
f=mt(i);
mt(i)=1;
for x=1:da
mt(i)=mod(mt(i)*f,n);
end
end
disp('');
disp('SIGNED TEXT: ');
disp(mt);
%ENCRYPTION
for i=1:length(mt)
f=mt(i);

mt(i)=1;
for x=1:eb
mt(i)=mod(mt(i)*f,n);
end
end
disp('');
disp('CIPHER TEXT: ');
disp(mt);
%AUTHENTICATION
for i=1:length(mt)
f=mt(i);
mt(i)=1;
for x=1:db
mt(i)=mod(mt(i)*f,n);
end
end
disp('');
disp('AUTHENTICATED TEXT: ');
disp(mt);
%DECRYPTION
for i=1:length(mt)
f=mt(i);
mt(i)=1;
for x=1:ea
mt(i)=mod(mt(i)*f,n);
end
end
disp('');
disp('DECRYPTED TEXT: ');
disp(char(mt));

SAMPLE INPUT AND OUTPUT:


Input:
RSA METHOD
Enter plain text: ['ece']
Enter value of n(public): 3233
Enter value of ea(public): 17
Enter value of da(secret): 2753
Enter value of eb(public): 31
Enter value of db(secret): 1711
Output:
SIGNED TEXT:
2106

89

2106

CIPHER TEXT:
1676

1497

1676

AUTHENTICATED TEXT:
2106

89

DECRYPTED TEXT:
ece

2106

Vous aimerez peut-être aussi