Showing posts with label Pseudo Ternary Encoding. Show all posts
Showing posts with label Pseudo Ternary Encoding. Show all posts

Friday, 23 May 2014

Simulation of Line Coding Schemes in Matlab


Objectives
How to write Matlab code that encodes a digital data into digital signal?
Study sample Matlab program for unipolar NRZ, NRZ-L, and Bipolar AMI
Program Code
Unipolar NRZ
 A positive voltage represents a binary 1, and zero volts indicates a binary 0. It is the simplest line code.
% Unipolar NRZ
clc
message = [0 1 1 0 1 0 1];
data = [0 0 1 0 1 0 0 0 1 0 0 0 1 0];
i = 1 : 7;
j = 1.99 : 7.99;
time = [ ];
for k = 1 : 7
time = [time i(k), j(k)];
end
% Digital Signal Generation:
signal = [ ];
for t=1:2:13
    if (data(t) == 0)
        signal (t : t+1) = 0;
    else
        signal (t : t+1) = -1;
    end
end
subplot(2,1,1);
plot (time, signal)      % Plotting PCM Signal
xlabel ('Time (t)')
ylabel ('Amplitude (A)')
title('Digital Signal')

Simulation Results
 
NRZ-L
In this encoding schemes, 0 is represented by +ve volt and 1 is represented by negative volt.
Program Code
% NRZ-L
 
message = [0 1 0 1 1 1 0 0 1 1 1 1 ];
data = message;
i = 1:length(messgae);
j=1.99:length(message+0.99);
time = []
for (k = 1 : length(message))
    time= [time i(k) j(k)]
end
 
% Generating signal 
signal = [];
N = length(data);
for (t=1:2:N)
    if(data(t)==1)
        signal(t:t+1)=1;
    else
        signal(t:t+1)=-1;
    end
end
% display the signal
 
figure(1);
plot(time,signal,'linewidth',2)
title('NRZ-LZ')
xlabel('time')
ylabel('voltage level')
 
axis([1 8 -0.5 1.5 ])

Simulation Results
 


 
Pseudo Ternary Encoding
A multilevel binary encoding that complements the bipolar-AMI encoding: binary 1 is represented by a lack of pulse, and a binary 0 is represented by a positive or a negative pulse. The binary 0 pulses must alternate in polarity.

Program Code
clc
message = [0 1 1 0 1 1 1 0 0 0 1];   
data = zeros(1,2*length(message)-1);           
data (1 : 2 : end) = message;
i = 1 : 11;
j = 1.99 : 11 + 0.99;
time = [ ];
for (k = 1 : length(message));
    time = [time i(k), j(k)];   
end
% Gnerating Signal
signal = [ ];            
n = length(data);
prebit = 1;
for t = 1 : 2 : n                  
    if (data(t) == 0)
        signal(t : t+1) = 0;
    else if (data(t) == 1 & prebit == 1)
            signal (t : t+1) = 1;
            prebit = -1;
        else
            signal (t : t+1) = -1;
            prebit = 1;
        end
    end
end
subplot(2,1,1)
plot (time, signal)            % Plotting …
title ('Digital Signal')
xlabel ('Time')
ylabel ('Amplitude')