0% found this document useful (0 votes)
37 views12 pages

Simulation Experiments With Output

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views12 pages

Simulation Experiments With Output

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Ex.

No: 13 SIMULATION OF ASK, FSK, AND BPSK GENERATION AND


DETECTIONSCHEMES
Date:

AIM:
To study the FSK,PSK ,DPSK Modulation using MATLAB code & observe the output
waveform.

APPARATUS REQUIRED:

1.Desktop with MATLAB software.

PROGRAM:

% 13.a ASK modulation


clc;
clear all;
close all;
%Generate Carrier Signal
Tb=1; fc=10;
t=0:Tb/100:1;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
%generate message signal
N=8;
m=rand(1,N);
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else m(i)=0;
m_s=zeros(1,length(t));
end
message(i,:)=m_s;
%product of carrier and message
ask_sig(i,:)=c.*m_s;
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
%plot the message and ASK signal
subplot(5,1,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal');xlabel('t--->');ylabel('m(t)');grid on
hold on
subplot(5,1,4);plot(t,ask_sig(i,:));
title('ASK signal');xlabel('t--->');ylabel('s(t)');grid on
hold on
end
hold off
%Plot the carrier signal and input binary data
subplot(5,1,3);plot(t,c);
title('carrier signal');xlabel('t--->');ylabel('c(t)');grid on
subplot(5,1,1);stem(m);
title('binary data bits');xlabel('n--->');ylabel('b(n)');grid on
t1=0;t2=Tb
for i=1:N
t=[t1:Tb/100:t2]
%correlator
x=sum(c.*ask_sig(i,:));
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
%plot demodulated binary data bits
subplot(5,1,5);stem(demod);
title('ASK demodulated signal'); xlabel('n--->');ylabel('b(n)');grid on
OUTPUT

Enter the input bits[1 010101010]


Enter the carrier frequency10
% 13.b PSK modulation
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1;
t=0:Tb/100:Tb; fc=2;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
%generate message signal
N=8;
m=rand(1,N);
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=-1*ones(1,length(t));
end
message(i,:)=m_s;
%product of carrier and message signal
bpsk_sig(i,:)=c.*m_s;
%Plot the message and BPSK modulated signal
subplot(5,1,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal(POLAR form)');xlabel('t--->');ylabel('m(t)');
grid on; hold on;
subplot(5,1,4);plot(t,bpsk_sig(i,:));
title('BPSK signal');xlabel('t--->');ylabel('s(t)');
grid on; hold on;
t1=t1+1.01; t2=t2+1.01;
end
hold off
%plot the input binary data and carrier signal
subplot(5,1,1);stem(m);
title('binary data bits');xlabel('n--->');ylabel('b(n)');
grid on;
subplot(5,1,3);plot(t,c);
title('carrier signal');xlabel('t--->');ylabel('c(t)');
grid on;
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
%correlator
x=sum(c.*bpsk_sig(i,:));
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+1.01;
t2=t2+1.01;
end
%plot the demodulated data bits
subplot(5,1,5);stem(demod);
title('demodulated data');xlabel('n--->');ylabel('b(n)');
grid on

OUTPUT

Enter the input bits[1 1 0 1 0 0 1 0]


Enter the carrier frequency10

% 13.c FSK Modulation


clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1; fc1=2;fc2=5;
t=0:(Tb/100):Tb;
c1=sqrt(2/Tb)*sin(2*pi*fc1*t);
c2=sqrt(2/Tb)*sin(2*pi*fc2*t);
%generate message signal
N=8;
m=rand(1,N);
t1=0;t2=Tb
for i=1:N
t=[t1:(Tb/100):t2]
if m(i)>0.5 m(i)=1;
m_s=ones(1,length(t));
invm_s=zeros(1,length(t));
else m(i)=0;
m_s=zeros(1,length(t));
invm_s=ones(1,length(t));
end
message(i,:)=m_s;
%Multiplier
fsk_sig1(i,:)=c1.*m_s;
fsk_sig2(i,:)=c2.*invm_s;
fsk=fsk_sig1+fsk_sig2;
%plotting the message signal and the modulated signal
subplot(3,2,2);axis([0 N -2 2]);plot(t,message(i,:),'r');
title('message signal');xlabel('t---->');ylabel('m(t)');grid on;hold on;
subplot(3,2,5);plot(t,fsk(i,:));
title('FSK signal');xlabel('t---->');ylabel('s(t)');grid on;hold on;
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
hold off
%Plotting binary data bits and carrier signal
subplot(3,2,1);stem(m);
title('binary data');xlabel('n---->'); ylabel('b(n)');grid on;
subplot(3,2,3);plot(t,c1);
title('carrier signal-1');xlabel('t---->');ylabel('c1(t)');grid on;
subplot(3,2,4);plot(t,c2);
title('carrier signal-2');xlabel('t---->');ylabel('c2(t)');grid on;
% FSK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:(Tb/100):t2]
%correlator
x1=sum(c1.*fsk_sig1(i,:));
x2=sum(c2.*fsk_sig2(i,:));
x=x1-x2;
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
%Plotting the demodulated data bits
subplot(3,2,6);stem(demod);
title(' demodulated data');xlabel('n---->');ylabel('b(n)'); grid on;
OUTPUT

Enter the input bits[1 1 0 1 0 0 1 0]


Enter the first carrier frequency10
Enter the second carrier frequency100

RESULT:
Thus FSK,PSK ,DPSK Modulation using MATLAB code were studied&
output waveforms are noted.
Ex.No: 14 SIMULATION OF QPSK AND QAM GENERATION SCHEMES
Date:
AIM:
To generate a QPSK,QAM modulated waveform and to simulate using MATLAB

APPARATUS REQUIRED:
1.System with Matlab software.
PROGRAM
% 14.a QPSK Modulation
clc;
clear all;
close all;
n=input('Enter the input bits');
y=length(n);
freq=input('Enter the carrier frequency');
for i=1:y
if n(1,i)==00
for t=(i-1)*100+1:(i*100)
y(t)=sin(2*pi*freq*(t/1000));
end
else if n(1,i)==01
for t=(i-1)*100+1:(i*100)
y(t)=sin(2*pi*freq*(t/1000)+(pi/2));
end
else if n(1,i)==10
for t=(i-1)*100+1:(i*100);
y(t)=sin(2*pi*freq*(t/1000)*pi);
end
else if n(1,i)==11
for t=(i-1)*100+1:(i*100);
y(t)=sin(2*pi*freq*(t/1000)+(3*pi)/2);
end
end
end
end
end
end
figure(2);
plot(y);
xlabel('Time in Seconds');
ylabel('Amplitude in Volts');
title('Quadrature Phase Shift Keying');
grid on;
OUTPUT

Enter the input bits [1 0 1 1 0 0]


Enter the carrier frequency 2

% 14.b QAM modulation


clc;
close all;
m=8;
k=log2(m);
n=9e3;
nsamp=1;
x=randint(n,1);
stem(x(1:20),'filled');
title('bit sequence');
xlabel('bit indix');
xsym=bi2de(reshape(x,k,length(x)/k).','left-msb');
figure;
stem(xsym(1:10));
title('symbol plot');
xlabel('symbol index'); ylabel('symbol amplitude');
y=modulate(modem.qammod(m),xsym);
ytx=y;
ebno=10;
snr=ebno+10*log(k)-10*log10(nsamp);
yn=awgn(ytx,snr);
yrx=yn;
scatterplot(y);
scatterplot(yrx,30)
.

RESULT:
Thus the generation of QPSK,QAM was simulated using MATLAB
Ex.No: 15 SIMULATION OF LINEAR BLOCK AND CYCLIC ERROR CONTROL CODING SCHEMES

Date:
AIM:
To write a program in MATLAB for error control coding techniques.

APPARATUS REQUIRED:

System with Matlab software


ALGORITHM

 Get the input binary sequence.


 Calculate the redundancy bits for the corresponding code.
 Transmit the signal that contains message bits redundancy bits added at the
end.
 Calculate the redundancy bits once again for the received bits.
 If the redundancy bits=’0’ then no error in the transmission otherwise
some error inthe transmission.
PROGRAM:
% 15. Linear Block Codes

clc;
clear all;
% Input Generator Matrix
g=input('Enter The Generator Matrix: ')
disp ('G = ')
disp ('The Order of Linear block Code for given Generator Matrix is:')
[n,k] = size(transpose(g))
for i = 1:2^k
for j = k:-1:1
if rem(i-1,2^(-j+k+1))>=2^(-j+k)
u(i,j)=1;
else
u(i,j)=0;
end
end
end
u;
disp('The Possible Codewords are :')
c = rem(u*g,2)
disp('The Minimum Hamming Distance dmin for given Block Code is= ')
d_min = min(sum((c(2:2^k,:))'))
% Code Word
r = input('Enter the Received Code Word:')
p = [g(:,n-k+2:n)];
h = [transpose(p),eye(n-k)];
disp('Hammimg Code')
ht = transpose(h)
disp('Syndrome of a Given Codeword is :')
s = rem(r*ht,2)
for i = 1:1:size(ht)
if(ht(i,1:3)==s)
r(i) = 1-r(i);
break;
end
end
disp('The Error is in bit:')
i
disp('The Corrected Codeword is :')
r

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 Linear block Code for given Generator Matrix is:
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
The Minimum Hamming Distance dmin for given Block Code is=
d_min = 3
Enter the Received Code Word:[1 0 0 0 1 0 0]
r= 1 0 0 0 1 0 0
Hammimg Code
ht =1 0 1
1 1 1
1 1 0
0 1 1
1 0 0
0 1 0
0 0 1
Syndrome of a Given Codeword is :
s= 0 0 1
The Error is in bit: i = 7
The Corrected Codeword is : r = 1 0 0 0 1 0 1

RESULT:

Thus the MATLAB program for error control coding techniques was simulated successfully.
.

You might also like