[Date Prev][Date Next][Date Index]
[ece333] Matlab program for encoding schemes.
All:
Below is a sample matlab program that will encode data to three different schemes.
Here I am using very simple logical functions to encode the data. Take a look.. I will explain my general approach to find the logical function for NRZ_I (which I tried to do in class today) in the next Lab session.
You can extend this sample code to include other encoding techniques as well.
Please DO NOT use this code AS IS. Convert every encoding scheme to appropriate function in matlab.
/shank
-----------------------------------------------
%data1 = [0 1 0 0 0 1 0 1 0 1]
data1 = [1 1 1 1 0 1 0 1 0 1]
subplot(4, 1, 1); stairs(data1)
axis([0 length(data1) -0.2 1.2]);
grid on;
%nrzl
nrzl_enc = not(data1)
subplot(4, 1, 2); stairs(nrzl_enc)
axis([0 length(data1) -0.2 1.2]);
grid on;
%nrzi
for i=1:length(data1)
if i == 1
data2(i) = xor(data1(i), 0);
else
data2(i) = xor(data1(i), data2(i-1));
end
end
data2;
nrzi_enc = data2;
nrzi_enc
subplot(4, 1, 3); stairs(nrzi_enc)
axis([0 length(data1) -0.2 1.2]);
grid on;
%stairs(data2);
%axis([0 length(data1) -0.2 1.2]);
%grid on;
%bipolar AMI:
% State 0 ==> -1, 1 ==> +1
state = 0;
for i=1:length(data1)
if data1(i) == 1
if state == 0
data3(i) = 1;
state = not(state);
elseif state == 1
data3(i) = -1;
state = not(state);
end
else
data3(i) = 0;
end
end
data3;
bipolar_ami = data3;
bipolar_ami
subplot(4, 1, 4); stairs(bipolar_ami)
axis([0 length(data1) -1.2 1.2]);
grid on;
-----------------------------------------------