0% found this document useful (1 vote)
1K views

Code: Amplitude Shift Keying

The document contains MATLAB code and simulations for different digital modulation techniques: 1) Amplitude Shift Keying (ASK) modulates a carrier wave by varying the amplitude of the carrier proportionally to the modulating signal. 2) Frequency Shift Keying (FSK) modulates the carrier frequency by changing it in accordance with the modulating signal. 3) Binary Phase Shift Keying (BPSK) modulates the phase of the carrier wave by changing it either 0 or 180 degrees based on the binary message signal. 4) The document also contains MATLAB code for block code generation, PN sequence generation, and verification of properties of the generated PN sequence.

Uploaded by

Mohamed Rias
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
1K views

Code: Amplitude Shift Keying

The document contains MATLAB code and simulations for different digital modulation techniques: 1) Amplitude Shift Keying (ASK) modulates a carrier wave by varying the amplitude of the carrier proportionally to the modulating signal. 2) Frequency Shift Keying (FSK) modulates the carrier frequency by changing it in accordance with the modulating signal. 3) Binary Phase Shift Keying (BPSK) modulates the phase of the carrier wave by changing it either 0 or 180 degrees based on the binary message signal. 4) The document also contains MATLAB code for block code generation, PN sequence generation, and verification of properties of the generated PN sequence.

Uploaded by

Mohamed Rias
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Amplitude Shift Keying:

Code:

clear;
clear all;
t=0:0.0001:0.05;

x=square(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
title('Modulating wave');
xlabel('time->');
ylabel('amp->');

y=sin(2*pi*1000*t);
subplot(3,1,2);
plot(t,y);
title('Carrier wave');
xlabel('time->');
ylabel('amp->');

z=x.*y;
a=z+y;
subplot(3,1,3);
plot(t,a);
title('Modulated wave');
xlabel('time->');
ylabel('amp->');

Simulation:

Modulating wave
1
amp->

-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
time->
Carrier wave
1
amp->

-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
time->
Modulated wave
2
amp->

-2
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
time->
Frequency Shift Keying:
Code:
clc;
clear all;
t=0:0.0001:0.05;

disp('ENTER DETAILS OF MESSAGE:');


vm=input('Amplitude');
fm=input('Frequency');
wm=2*pi*fm;

disp('ENTER DETAILS OF CARRIER:');


vc=input('Amplitude');
fc=input('Frequency');
wc=2*pi*fc;

Vm=vm*(square(wm*t));
subplot(3,1,1);
plot(t,Vm);
title('MESSAGE');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

Vc=vc*(square(wc*t));
subplot(3,1,2);
plot(t,Vc);
title('CARRIER');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

x=sin(2*pi*(fc+25*Vm).*t);
subplot(3,1,3);
plot(t,x);
title('MODULATED');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

Simulation:

MESSAGE
AMPLITUDE---->

-5
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
TIME---->
CARRIER
AMPLITUDE---->

-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
TIME---->
MODULATED
AMPLITUDE---->

-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
TIME---->
Binary Phase Shift Keying:
Code:
fs=1000000;
fc=1000;
fm=100;
t=(1/fs):(1/fs):(2/fm);
m=square(2*pi*fm*t);
c=sin(2*pi*fc*t);
s=c.*m;
subplot(4,1,1);
plot(t,m);
title('MESSAGE');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

subplot(4,1,2);
plot(t,c);
title('CARRIER');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

subplot(4,1,3);
plot(t,s);
title('MODULATING SIGNAL');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

q=s.*c;
n=1; wn=0.005;
u=butter(n,wn,'low');
subplot(4,1,4);
plot(t,q);
title('DEMODULATING SIGNAL');
xlabel('TIME---->'); ylabel('AMPLITUDE---->');

Simulation:
MESSAGE
AMPLITUDE---->

-1
0 0.002 0.004 0.006 0.008CARRIER
0.01 0.012 0.014 0.016 0.018 0.02
AMPLITUDE---->

1 TIME---->

-1
0 0.002 0.004 0.006 MODULATING
0.008 0.01 SIGNAL
0.012 0.014 0.016 0.018 0.02
AMPLITUDE---->

1 TIME---->

-1
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
AMPLITUDE---->

DEMODULATING
TIME----> SIGNAL
1
0
-1
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
TIME---->
Block Code Generation:
Code:
clc;
clear all;
w=[1 0 0 0 1 0];
disp('THE ORIGINAL CODE :');
disp(w);
p=[1 1 0; 0 1 1; 0 0 1];
i=[1 0 0; 0 1 0; 0 0 1];
pt=p';
h=[pt,i];
ht=h';
disp(ht);
for(i=1:3)
s1=0;
for(j=1:6)
s1=xor(s1,ht(j,i)*w(j));
end
s(i)=s1;
end
disp('THE SYNDROME :');
disp(s);
for(k=1:6)
if(s==ht(k,:))
temp=k;
end
end
fprintf('THE ERROR IS IN THE POSITION %d \n',temp);
w(temp)=xor(w(temp),i);
disp('THE CORRECTED CODE:');
disp(w);

OUTPUT:

THE ORIGINAL CODE :


1 0 0 0 1 0

1 1 0
0 1 1
0 0 1
1 0 0
0 1 0
0 0 1

THE SYNDROME :
1 0 0

THE ERROR IS IN THE POSITION 4


THE CORRECTED CODE:
1 0 0 1 1 0
PN Sequence Generation:
Code:

%PN SEQUENCE%
clc;
clear all;
x=input('ENTER NUMBER OF REGISTERS:');
len=(2^x)-1;
fprintf('\nINTIAL STATE:');
for i=1:x
if(i==1)
r(i)=1;
else
r(i)=0;
end
fprintf('\t %d',r(i));
end
fprintf('\nPN Sequence:');
for j=1:len
out(j)=xor(r(1),r(x));
p(j)=out(j);
for(s=x:-1:1)
if(s==1)
r(s)=out(j);
else
r(s)=r(s-1);
end
end
fprintf('\t %d',p(j));
end

%BALANCE PROPERTY%
ones=0;
zeros=0;
for(i=1:len)
if(p(i)==1)
ones=ones+1;
else
zeros=zeros+1;
end
end
if(ones>zeros)
fprintf('\n BALANCE PROPERTY IS SATISFIED');
else
fprintf('\n BALANCE PROPERTY IS NOT SATISFIED');
end
%RUN PROPERTY%
run=0;
for(j=1:(len-1))
if(p(j)~=p(j+1))
run=run+1;
end
end
fprintf('\n NUMBER OF RUNS=%d',run);
if(run==(2^(x-1)))
fprintf('\n RUN PROPERTY IS SATISFIED');
else
fprintf('\n RUN PROPERTY IS NOT SATISFIED');
end

%AUTO CORRELATION PROPERTY%


temp=p(len);
fprintf('\nPN sequence after shifting');
output=p;
for j=len:-1:2
output(j)=output(j-1);
end
output(1)=temp;
fprintf('\t %d',output);
ag=0;
da=0;
for(j=1:len)
if(output(j)==p(j))
ag=ag+1;
else
da=da+1;
end
end
if(da>ag)
fprintf('\n AUTO CORRELATION PROPERTY IS SATISFIED\n\n');
else
fprintf('\n AUTO CORRELATION PROPERTY IS NOT SATISFIED \n\n');
end

OUTPUT:

ENTER NUMBER OF REGISTERS:4

INTIAL STATE: 1 0 0 0
PN Sequence: 1 1 1 0 1 0 1 1 0
0 1 0 0 0 1
BALANCE PROPERTY IS SATISFIED
NUMBER OF RUNS=8
RUN PROPERTY IS SATISFIED
PN sequence after shifting 1 1 1 1 0 1 0
1 1 0 0 1 0 0 0
AUTO CORRELATION PROPERTY IS SATISFIED

You might also like