Roll no.
: 19 Name: Yash Rajendra Gulave
Practical 11: Simulate the line coding techniques using MATLAB and Simulink
Q. Write MATLAB code for line coding: unipolar, polar, bipolar and
Manchester code
clc; % Bipolar NRZ Encoding manchester((i-
1)*n+1:(i-0.5)*n) = -1;
clear; bipolar = zeros(1,
length(binary_data) * n); manchester((i-
close all;
0.5)*n+1:i*n) = 1;
last_bit = -1;
end
for i =
% Input binary data
1:length(binary_data) end
sequence
if binary_data(i) == 1
binary_data = [1 0 1 1 0 0
1 0 1 1]; last_bit = -last_bit; % Plot the results
bitrate = 1; % bits per bipolar((i-1)*n+1:i*n) figure;
second = last_bit;
subplot(4,1,1);
T = length(binary_data) / else
plot(time, unipolar, 'b',
bitrate;
bipolar((i-1)*n+1:i*n) 'LineWidth', 2);
n = 100; % Number of = 0;
ylabel('Unipolar');
samples per bit
end
ylim([-0.2, 1.2]);
end
grid on;
time = linspace(0, T,
length(binary_data) * n);
% Manchester Encoding
subplot(4,1,2);
manchester = zeros(1,
% Unipolar Encoding plot(time, polar, 'r',
length(binary_data) * n);
'LineWidth', 2);
unipolar =
for i =
repelem(binary_data, n); ylabel('Polar');
1:length(binary_data)
ylim([-1.2, 1.2]);
if binary_data(i) == 1
% Polar NRZ Encoding grid on;
manchester((i-
polar = 1)*n+1:(i-0.5)*n) = 1;
repelem(binary_data * 2 -
manchester((i- subplot(4,1,3);
1, n);
0.5)*n+1:i*n) = -1;
plot(time, bipolar, 'g',
else 'LineWidth', 2);
ylabel('Bipolar'); subplot(4,1,4); ylim([-1.2, 1.2]);
ylim([-1.2, 1.2]); plot(time, manchester, xlabel('Time (s)');
'k', 'LineWidth', 2);
grid on; grid on;
ylabel('Manchester');
Output:
Roll no. : 19 Name: Yash Rajendra Gulave
Practical 12: Simulate the Binary amplitude shift keying using MATLAB and
Simulink
Q. Observe the ASK output for bit stream 1100101
clc; carrier = sin(2 * pi * fc * subplot(2,1,1);
t);
clear; stem(0:length(binary_dat
a)-1, binary_data, 'filled',
close all;
'LineWidth', 2);
% Generate ASK signal
ylabel('Binary Data');
ask_signal = zeros(1,
% Input binary data
length(t)); ylim([-0.2, 1.2]);
sequence
for i = xlabel('Bit Index');
binary_data = [1 1 0 0 1 0
1:length(binary_data)
1]; grid on;
if binary_data(i) == 1
bitrate = 1; % bits per
second ask_signal((i-
title('Binary Data
1)*fs*T+1:i*fs*T) =
fs = 100; % Sampling Sequence');
carrier((i-
frequency
1)*fs*T+1:i*fs*T);
T = 1 / bitrate; % Bit
else subplot(2,1,2);
duration
ask_signal((i- plot(t, ask_signal, 'b',
t=
1)*fs*T+1:i*fs*T) = 0; 'LineWidth', 2);
0:1/fs:length(binary_data
)*T - 1/fs; end ylabel('ASK Signal');
end xlabel('Time (s)');
% Carrier wave grid on;
fc = 5; % Carrier % Plot the ASK title('Amplitude Shift
frequency in Hz modulated signal Keying (ASK)
Modulation');
figure;
Output:
Q. Observe the ASK output for bit stream 1110100
clc; T = 1 / bitrate; % Bit ask_signal = zeros(1,
duration length(t));
clear;
t= for i =
close all;
0:1/fs:length(binary_data 1:length(binary_data)
)*T - 1/fs;
if binary_data(i) == 1
% Input binary data
ask_signal((i-
sequence
% Carrier wave 1)*fs*T+1:i*fs*T) =
binary_data = [1 1 1 0 1 0 carrier((i-
fc = 5; % Carrier
0]; 1)*fs*T+1:i*fs*T);
frequency in Hz
bitrate = 1; % bits per else
carrier = sin(2 * pi * fc *
second
t); ask_signal((i-
fs = 100; % Sampling 1)*fs*T+1:i*fs*T) = 0;
frequency
end
% Generate ASK signal
end ylabel('Binary Data'); subplot(2,1,2);
ylim([-0.2, 1.2]); plot(t, ask_signal, 'b',
'LineWidth', 2);
% Plot the ASK xlabel('Bit Index');
modulated signal ylabel('ASK Signal');
grid on;
figure; xlabel('Time (s)');
subplot(2,1,1); grid on;
title('Binary Data
stem(0:length(binary_dat Sequence'); title('Amplitude Shift
a)-1, binary_data, 'filled', Keying (ASK) Modulation
'LineWidth', 2); ‘);
Roll no. : 19 Name: Yash Rajendra Gulave
Practical 13: Simulate the Binary Phase Shift Keying using MATLAB and
Simulink
Q. Draw BPSK modulated waveforms for input data 11110000
Q. Draw BPSK modulated waveforms for input data 10101010
Q. Draw BPSK modulated waveforms for input data 11111111
Q. Draw BPSK modulated waveforms for input data 11001100
Roll no. : 19 Name: Yash Rajendra Gulave
Practical 14: Simulate the delta modulation using MATLAB and Simulink
Q. Write a MATLAB program to perform Delta Modulation
clc; delta_modulated(i) = end
1;
clear;
x = x + delta;
close all; % Plot Results
else
figure;
delta_modulated(i) =
% Generate a sample subplot(3,1,1);
0;
input signal
plot(t, message, 'b',
x = x - delta;
fs = 1000; % Sampling 'LineWidth', 2);
frequency end
title('Original Signal');
T = 1; % Signal duration approx_signal(i) = x;
ylabel('Amplitude');
t = 0:1/fs:T-1/fs; end
grid on;
message = sin(2 * pi * 2 *
t); % Example message
% Delta Modulation
signal (sine wave) subplot(3,1,2);
Decoding
stairs(t, delta_modulated,
x_decoded = 0;
'r', 'LineWidth', 2);
% Delta Modulation
decoded_signal = zeros(1,
Parameters title('Delta Modulated
length(delta_modulated))
Signal');
delta = 0.1; % Step size ;
ylabel('Bit Value');
x = 0; % Initial value of for i =
the approximated signal 1:length(delta_modulate grid on;
d)
delta_modulated =
zeros(1, if delta_modulated(i)
subplot(3,1,3);
length(message)); == 1
plot(t, decoded_signal,
approx_signal = zeros(1, x_decoded =
'g', 'LineWidth', 2);
length(message)); x_decoded + delta;
title('Demodulated
else
Signal');
% Delta Modulation x_decoded =
ylabel('Amplitude');
Encoding x_decoded - delta;
xlabel('Time (s)');
for i = 1:length(message) end
grid on;
if message(i) > x decoded_signal(i) =
x_decoded;
Output:
Roll no. : 19 Name: Yash Rajendra Gulave
Practical 15: Simulate the Direct Sequence Spread Spectrum using MATLAB
and Simulink
Q. use PN sequence for the DSSS signal to trace the DSSS signal
corresponding to 2 different bit pattern and the same PN sequence used as
the modulation.
clc; % Generate PN sequence stairs(spread_signal1, 'r',
'LineWidth', 2);
clear; pn_sequence = [1 -1 1 -1
1 1 -1 1]; % Example PN title('DSSS Signal for Bit
close all;
sequence Pattern 1');
ylabel('Amplitude');
% Parameters
% Spread the signal using grid on;
fs = 1000; % Sampling PN sequence
frequency
spread_signal1 =
subplot(2,1,2);
T = 1; % Signal duration kron(2*bit_pattern1-1,
pn_sequence); stairs(spread_signal2, 'b',
t = 0:1/fs:T-1/fs;
'LineWidth', 2);
title('DSSS Signal for Bit
spread_signal2 =
% Define two different bit Pattern 2');
kron(2*bit_pattern2-1,
patterns
pn_sequence); ylabel('Amplitude');
bit_pattern1 = [1 0 1 1 0
xlabel('Time (samples)');
1 0 0];
% Plot the DSSS signals grid on;
bit_pattern2 = [0 1 0 0 1
0 1 1]; figure;
subplot(2,1,1);
Output:
Q. observe the DSSS signal corresponding to 2 different bit pattern for check
frequency 120 KHZ.
clc; pn_sequence = [1 -1 1 -1
1 1 -1 1]; % Example PN
clear; % Plot the DSSS signals
sequence
close all; figure;
subplot(2,1,1);
% Spread the signal using
% Parameters PN sequence plot(t(1:length(dsss_signa
l1)), dsss_signal1, 'r',
fs = 1000; % Sampling spread_signal1 =
'LineWidth', 1.5);
frequency kron(2*bit_pattern1-1,
pn_sequence); title('DSSS Signal for Bit
T = 1; % Signal duration
Pattern 1 (120 kHz)');
spread_signal2 =
t = 0:1/fs:T-1/fs;
kron(2*bit_pattern2-1, ylabel('Amplitude');
fc = 120e3; % Carrier pn_sequence);
xlabel('Time (s)');
frequency (120 kHz)
grid on;
% Modulate with carrier
% Define two different bit frequency
patterns subplot(2,1,2);
carrier = cos(2 * pi * fc *
bit_pattern1 = [1 0 1 1 0 t(1:length(spread_signal1 plot(t(1:length(dsss_signa
1 0 0]; ))); l2)), dsss_signal2, 'b',
'LineWidth', 1.5);
bit_pattern2 = [0 1 0 0 1 dsss_signal1 =
0 1 1]; spread_signal1 .* carrier; title('DSSS Signal for Bit
Pattern 2 (120 kHz)');
dsss_signal2 =
spread_signal2 .* carrier; ylabel('Amplitude');
% Generate PN sequence
xlabel('Time (s)'); grid on;
Q. Generate PN sequence using MATLAB
clc; for i = 1:pn_length dsss_signal1 =
spread_signal1 .* carrier;
clear; pn_sequence(i) =
lfsr(end); dsss_signal2 =
close all;
spread_signal2 .* carrier;
feedback = xor(lfsr(1),
lfsr(3)); % XOR feedback
% Parameters taps (example for 8-bit
% Plot the DSSS signals
LFSR)
fs = 1000; % Sampling
figure;
frequency lfsr = [feedback
lfsr(1:end-1)]; subplot(2,1,1);
T = 1; % Signal duration
end plot(t(1:length(dsss_signa
t = 0:1/fs:T-1/fs;
l1)), dsss_signal1, 'r',
pn_sequence = 2 *
fc = 120e3; % Carrier 'LineWidth', 1.5);
pn_sequence - 1; %
frequency (120 kHz)
Convert to bipolar (-1,1) title('DSSS Signal for Bit
Pattern 1 (120 kHz)');
% Define two different bit ylabel('Amplitude');
% Spread the signal using
patterns
PN sequence xlabel('Time (s)');
bit_pattern1 = [1 0 1 1 0
spread_signal1 = grid on;
1 0 0];
kron(2*bit_pattern1-1,
bit_pattern2 = [0 1 0 0 1 pn_sequence);
0 1 1]; subplot(2,1,2);
spread_signal2 =
kron(2*bit_pattern2-1, plot(t(1:length(dsss_signa
pn_sequence); l2)), dsss_signal2, 'b',
% Generate PN sequence
'LineWidth', 1.5);
using LFSR
title('DSSS Signal for Bit
pn_length = 8; % Modulate with carrier
Pattern 2 (120 kHz)');
frequency
lfsr = [1 0 0 1 1 0 1 1]; %
ylabel('Amplitude');
Initial seed (example) carrier = cos(2 * pi * fc *
t(1:length(spread_signal1 xlabel('Time (s)');
pn_sequence = zeros(1,
)));
pn_length); grid on;