0% found this document useful (0 votes)
11 views14 pages

Ilovepdf Merged

The document contains MATLAB scripts for simulating various digital communication techniques, including Unipolar NRZ, Unipolar RZ, Polar RZ, Manchester coding, Amplitude Shift Keying (ASK), Phase Shift Keying (PSK), Delta Modulation, and Direct Sequence Spread Spectrum (DSSS). Each section demonstrates how to generate and plot the corresponding signals based on a binary input stream. The scripts also include comments explaining the purpose and functionality of each part of the code.

Uploaded by

Anas Malkani
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)
11 views14 pages

Ilovepdf Merged

The document contains MATLAB scripts for simulating various digital communication techniques, including Unipolar NRZ, Unipolar RZ, Polar RZ, Manchester coding, Amplitude Shift Keying (ASK), Phase Shift Keying (PSK), Delta Modulation, and Direct Sequence Spread Spectrum (DSSS). Each section demonstrates how to generate and plot the corresponding signals based on a binary input stream. The scripts also include comments explaining the purpose and functionality of each part of the code.

Uploaded by

Anas Malkani
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/ 14

Practical 11

clc, clear all, close all;


% ******************* Digital/Binary input information ********************
x = [1 0 1 0 0 0 1 1 0]; % Binary information as a stream of bits
N = length(x);
Tb = 0.0001; % Data rate = 1MHz, bit period (seconds)
disp('Binary Input Information at Transmitter:');
disp(x);
% ************* Represent input information as digital signal *************
nb = 100; % Digital signal per bit
digit = [];
for n = 1:1:N
if x(n) == 1
sig = ones(1, nb);
else
sig = zeros(1, nb);
end
digit = [digit sig];
end
t1 = Tb/nb:Tb/nb:nb*N*(Tb/nb); % Time period
figure('Name','Line Coding Schemes','NumberTitle','off');
% Plot the original digital signal
subplot(5,1,1);
plot(t1, digit, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('Digital Input Signal');
% ***************************** Unipolar NRZ ******************************
for i = 0:N-1
if x(i+1) == 1
Y(i*nb+1:(i+1)*nb) = 1;
else
Y(i*nb+1:(i+1)*nb) = 0;
end
end
subplot(5,1,2)
plot(t1, Y, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('Unipolar NRZ');
% ****************************** Unipolar RZ ******************************
for i = 0:N-1
if x(i+1) == 1
Y(i*nb+1:(i+0.5)*nb) = 1;
Y((i+0.5)*nb+1:(i+1)*nb) = 0;
else
Y(i*nb+1:(i+1)*nb) = 0;
end
end
subplot(5,1,3)
plot(t1, Y, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('Unipolar RZ');
% ******************************* Polar RZ ********************************
for i = 0:N-1
if x(i+1) == 1
Y(i*nb+1:(i+0.5)*nb) = 1;
Y((i+0.5)*nb+1:(i+1)*nb) = 0;
else
Y(i*nb+1:(i+0.5)*nb) = -1;
Y((i+0.5)*nb+1:(i+1)*nb) = 0;
end
end
subplot(5,1,4)
plot(t1, Y, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('Polar RZ');
% ****************************** Manchester *******************************
for i = 0:N-1
if x(i+1) == 1
Y(i*nb+1:(i+0.5)*nb) = 1;
Y((i+0.5)*nb+1:(i+1)*nb) = -1;
else
Y(i*nb+1:(i+0.5)*nb) = -1;
Y((i+0.5)*nb+1:(i+1)*nb) = 1;
end
end
subplot(5,1,5)
plot(t1, Y, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('Manchester');
% ************************** End of the program ***************************
28/1/25 11:12 AM MATLAB Command Window 1 of 2

>> % MATLAB Script for a Binary ASK with two Amplitude Levels
format long;
% Clear all variables and close all figures
clear all;
close all;
% The number of bits to send - Frame Length
N = 8;
% Generate a random bit stream
bit_stream = round(rand(1,N));
% Enter the two Amplitudes
% Amplitude for 0 bit
A1 = 3;
% Amplitude for 1 bit
A2 = 5;
% Frequency of Modulating Signal
f = 3;
% Sampling rate - This will define the resoultion
fs = 100;
% Time for one bit
t = 0: 1/fs : 1;
% This time variable is just for plot
time = [];
ASK_signal = [];
Digital_signal = [];
for ii = 1: 1: length(bit_stream)

% The FSK Signal


ASK_signal = [ASK_signal (bit_stream(ii)==0)*A1*sin(2*pi*f*t)+...
(bit_stream(ii)==1)*A2*sin(2*pi*f*t)];

% The Original Digital Signal


Digital_signal = [Digital_signal (bit_stream(ii)==0)*...
zeros(1,length(t)) + (bit_stream(ii)==1)*ones(1,length(t))];

time = [time t];


t = t + 1;

end
% Plot the ASK Signal
subplot(2,1,1);
plot(time,ASK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('ASK Signal with two Amplitudes');
%axis([0 time(end) 1.5 1.5]);
grid on;
% Plot the Original Digital Signal
subplot(2,1,2);
plot(time,Digital_signal,'r','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
28/1/25 11:12 AM MATLAB Command Window 2 of 2

title('Original Digital Signal');


axis([0 time(end) -0.5 1.5]);
grid on;

>>
>>
>>
MATLAB Command Window Page 1

>> % MATLAB Script for a Binary PSK with two Phases


format long;
% Clear all variables and close all figures
clear all;
close all;
% The number of bits to send - Frame Length
N = 8;
% Generate a random bit stream
bit_stream = round(rand(1,N));
% Enter the two Phase shifts - in Radians
% Phase for 0 bit
P1 = 0;
% Phase for 1 bit
P2 = pi;
% Frequency of Modulating Signal
f = 3;
% Sampling rate - This will define the resoultion
fs = 100;
% Time for one bit
t = 0: 1/fs : 1;
% This time variable is just for plot
time = [];
PSK_signal = [];
Digital_signal = [];
for ii = 1: 1: length(bit_stream)

% The FSK Signal


PSK_signal = [PSK_signal (bit_stream(ii)==0)*sin(2*pi*f*t + P1)+...
(bit_stream(ii)==1)*sin(2*pi*f*t + P2)];

% The Original Digital Signal


Digital_signal = [Digital_signal (bit_stream(ii)==0)*...
zeros(1,length(t)) + (bit_stream(ii)==1)*ones(1,length(t))];

time = [time t];


t = t + 1;

end
% Plot the PSK Signal
subplot(2,1,1);
plot(time,PSK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('PSK Signal with two Phase Shifts');
axis([0 time(end) -1.5 1.5]);
MATLAB Command Window Page 2

grid on;
% Plot the Original Digital Signal
subplot(2,1,2);
plot(time,Digital_signal,'r','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Original Digital Signal');
axis([0 time(end) -0.5 1.5]);
grid on;
>>
% Experiment No-4 : Simulation of Delta Modulation using MATLAB

%%===============================================
clc;
t=0:2*pi/100:2*pi; % Time Duration
x=5*sin(2*pi*t/5); % Define Message Signal with peak voltage 5V and frequency
5Hz
plot(x)
hold on
y=[0]; %Output DM signal i.e. stream of 1 or 0
xr=0; % Output of Integrator i.e. staircase approximation; initial value =0
del=0.4; % Stepsize
for i=1:length(x)-1
if xr(i)<=x(i) % If current sample greater than the previous values or
output of the integrator, output of DM=1
d=1;
xr(i+1)=xr(i)+del; % Staircase approximated value
else
d=0;
xr(i+1)=xr(i)-del; % If current sample less than the previous values
or output of the integrator, output of DM=0
end
y=[y d];

end
stairs(xr); % Show the staircase approximated signal
hold off
MSE=sum((x-xr).^2)/length(x) % MSE
y % Output of DM
MATLAB Command Window Page 1

>> close all;


clear all;
% Input bit sequence
b = input('Enter the input bits (e.g., [1 0 1 1 0]): ');
ln = length(b);
% Convert bit 0 to -1
for i = 1:ln
if b(i) == 0
b(i) = -1;
end
end
% Generating the bit sequence with each bit 8 samples long
k = 1;
bb = []; % Initialize bb array
for i = 1:ln
for j = 1:8
bb(k) = b(i);
k = k + 1;
end
end
len = length(bb);
% Plot the original bit sequence
subplot(2,1,1);
stairs(bb, 'linewidth', 2);
axis([0 len -2 3]);
title('Original Bit Sequence b(t)');

% Generating the pseudo-random bit pattern for spreading


pr_sig = round(rand(1, len)); % Pseudo-random sequence of 0s and 1s
pr_sig(pr_sig == 0) = -1; % Convert 0 to -1
subplot(2,1,2);
stairs(pr_sig, 'linewidth', 2);
axis([0 len -2 3]);
title('Pseudorandom Bit Sequence pr_sig(t)');

% Multiply bit sequence with pseudorandom sequence


bbs = bb .* pr_sig; % Element-wise multiplication

% Modulating the hopped signal


dsss = [];
t = 0:1/10:2*pi;
c1 = cos(t); % Cosine wave for -1 bit
c2 = cos(t + pi); % Cosine wave for 1 bit
for k = 1:len
if bbs(k) == -1
dsss = [dsss c1]; % Append c1 for -1
else
dsss = [dsss c2]; % Append c2 for 1
end
end
MATLAB Command Window Page 2

% Plotting the results


figure;
subplot(2,1,1);
stairs(bbs, 'linewidth', 2);
axis([0 len -2 3]);
title('Multiplier Output Sequence b(t) * pr_sig(t)');

subplot(2,1,2);
plot(dsss);
title('DS-SS Signal');

Enter the input bits (e.g., [1 0 1 1 0]): [1 0 1 1]


MATLAB Command Window Page 3

You might also like