Lecture-2 Line Coding
Lecture-2 Line Coding
❑ Unipolar NRZ
Steps
➢ Define the binary sequence and parameters (bit duration and sampling rate).
➢ Create a time array for one bit and initialize an empty signal array.
➢ Use a loop to append a constant signal for each bit (high for 1, low for 0).
➢ Create a time axis for the entire signal.
➢ Plot the signal and add labels to make it easy to interpret.
Step 1: Define the Binary Sequence
binary_sequence = [1 0 1 1 0 0 1 0]; % Example sequence
✓ This is the input sequence of bits you want to encode in the Unipolar NRZ format.
✓ Each 1 will be represented by a high signal (e.g., 1), and each 0 by a low signal (e.g., 0).
✓ Replace this array with your desired binary data.
✓ nrz_signal: This will store the final signal. Initially, it’s empty and will be filled bit by bit.
Step 4: Loop Through Each Bit to Generate the Signal
for bit = binary_sequence
if bit == 1
% For bit '1', the signal is at a high level (e.g., 1)
nrz_signal = [nrz_signal, ones(1, length(t_bit))];
else
% For bit '0', the signal is at a low level (e.g., 0)
nrz_signal = [nrz_signal, zeros(1, length(t_bit))];
end
End
✓ total_time: Calculate the total duration of the signal by multiplying the number of bits by bit_duration.
✓ time_axis: Create a time array that spans the entire signal, ensuring proper alignment for plotting.
Step 6: Plot the Signal
figure;
plot(time_axis, nrz_signal, 'LineWidth', 2);
ylim([-0.5, 1.5]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Unipolar Non-Return-to-Zero (NRZ) Signal');
grid on;
figure;
plot(time_axis, nrz_signal, 'LineWidth', 2);
ylim([-0.5, 1.5]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Unipolar Non-Return-to-Zero (NRZ) Signal');
grid on;
2. Set Parameters
bit_duration = 1;
sampling_rate = 1000;
t_bit = linspace(0, bit_duration, sampling_rate);
✓ Add text above each bit interval to show the corresponding binary value.
Complte Code:
clc;clear all;close all;
binary_sequence = [1 0 1 1 0 0 1 0];
bit_duration = 1;
sampling_rate = 1000;
t_bit = linspace(0, bit_duration, sampling_rate);
rz_signal = [];
figure;
plot(time_axis, rz_signal, 'LineWidth', 2);
ylim([-0.5, 1.5]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Unipolar Return-to-Zero (RZ) Signal');
grid on;