0% found this document useful (0 votes)
4 views7 pages

line_coding

The document presents various line coding techniques for digital data representation, including Unipolar NRZ, Unipolar RZ, Polar NRZ, Polar RZ, Manchester, Differential Manchester, and Bipolar AMI. It also introduces M-ary encoding with an example of M=4. Each technique is visualized through plots showing their respective waveforms over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

line_coding

The document presents various line coding techniques for digital data representation, including Unipolar NRZ, Unipolar RZ, Polar NRZ, Polar RZ, Manchester, Differential Manchester, and Bipolar AMI. It also introduces M-ary encoding with an example of M=4. Each technique is visualized through plots showing their respective waveforms over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

data = [1 0 1 1 0];

bitrate = 1;
T = length(data)/bitrate;
n = 1000;
N = n * length(data);
dt = T / N;
t = 0:dt:T;

% Unipolar NRZ
x_unipolar_nrz = zeros(1, length(t));
for i = 1:length(data)
if data(i) == 1
x_unipolar_nrz((i-1)*n+1:i*n) = 1;
end
end
% Unipolar RZ
x_unipolar_rz = zeros(1, length(t));
for i = 1:length(data)
if data(i) == 1
x_unipolar_rz((i-1)*n+1:(i-0.5)*n) = 1; % Return to zero in the middle
end
end

% Polar NRZ
x_polar_nrz = zeros(1, length(t));
for i = 1:length(data)
if data(i) == 1
x_polar_nrz((i-1)*n+1:i*n) = 1;
else
x_polar_nrz((i-1)*n+1:i*n) = -1;
end
end

% Polar RZ
x_polar_rz = zeros(1, length(t));
for i = 1:length(data)
if data(i) == 1
x_polar_rz((i-1)*n+1:(i-0.5)*n) = 1; % Positive pulse for 1
else
x_polar_rz((i-1)*n+1:(i-0.5)*n) = -1; % Negative pulse for 0
end
end

% Manchester
x_manchester = zeros(1, length(t));
for i = 1:length(data)
if data(i) == 1
x_manchester((i-1)*n+1:(i-0.5)*n) = 1;
x_manchester((i-0.5)*n+1:i*n) = -1;
else
x_manchester((i-1)*n+1:(i-0.5)*n) = -1;
x_manchester((i-0.5)*n+1:i*n) = 1;
end
end

% Differential Manchester
x_diff_manchester = zeros(1, length(t));
last = -1;
for i = 1:length(data)
if data(i) == 0
x_diff_manchester((i-1)*n+1:(i-0.5)*n) = last;
last = -last;
x_diff_manchester((i-0.5)*n+1:i*n) = last;
else
x_diff_manchester((i-1)*n+1:(i-0.5)*n) = -last;
x_diff_manchester((i-0.5)*n+1:i*n) = last;
end
end

% Bipolar AMI
x_bipolar_ami = zeros(1, length(t));
last = 1;
for i = 1:length(data)
if data(i) == 1
x_bipolar_ami((i-1)*n+1:i*n) = last;
last = -last;
end
end

% M-ary Encoding (for M=4 as example)


M = 4; % 4 levels
levels = linspace(-1, 1, M); % Generate M levels between -1 and 1
x_m_ary = zeros(1, length(t));
for i = 1:length(data)
x_m_ary((i-1)*n+1:i*n) = levels(mod(i, M) + 1); % Assign a level based on data
bit
end

% Plotting all line coding techniques


figure;

subplot(3,1,1);
plot(t, x_unipolar_nrz, 'LineWidth', 2);
title('Unipolar NRZ');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -0.5 1.5]);

subplot(3,1,2);
plot(t, x_unipolar_rz, 'LineWidth', 2);
title('Unipolar RZ');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -0.5 1.5]);
subplot(3,1,3);
plot(t, x_polar_nrz, 'LineWidth', 2);
title('Polar NRZ');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -1.5 1.5]);

figure;
subplot(2,2,1);
plot(t, x_polar_rz, 'LineWidth', 2);
title('Polar RZ');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -1.5 1.5]);

subplot(2,2,2);
plot(t, x_manchester, 'LineWidth', 2);
title('Manchester');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -1.5 1.5]);

subplot(2,2,3);
plot(t, x_diff_manchester, 'LineWidth', 2);
title('Differential Manchester');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -1.5 1.5]);
subplot(2,2,4);
plot(t, x_bipolar_ami, 'LineWidth', 2);
title('Bipolar AMI');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -1.5 1.5]);

figure;
plot(t, x_m_ary, 'LineWidth', 2);
title('M-ary Encoding (M=4)');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 T -1.5 1.5]);

You might also like