Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1)can someone please explain what each line of code is doing , i cant quite unde

ID: 3832012 • Letter: 1

Question

1)can someone please explain what each line of code is doing , i cant quite understand it.

2)is there any way instead of plotting we can just output high pulse as +A and negitive pulse as -A and zero as A in a vector

clear all; close all; clc;
h=[1 1 1 0 1 1 0 1 0 0 0];


%AMINRZ(h)
clf;
n=1;
l=length(h);
h(l+1)=1;
ami=-1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
if ami==1
y=-(t==n);
else
y=(t==n);
end
end
d=plot(t,y);grid on;
title('Line code AMI NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('zero');
else
ami=ami*-1;
if h(n+1)==0
if ami==1
y=(t else
y=-(t end
else
if ami==1
y=(t else
y=-(t end
  
end
%y=(t>n-1)+(t==n-1);
d=plot(t,y);grid on;
title('Line code AMI NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('one');
end
n=n+1;
%pause;
end

Explanation / Answer

%AMINRZ(h)
clf;
n=1;
l=length(h);
h(l+1)=1;
ami=-1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
if ami==1
y=-(t==n);
else
y=(t==n);
end
end
d=plot(t,y);grid on;
title('Line code AMI NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('zero');
else
ami=ami*-1;
if h(n+1)==0
if ami==1
y=(t else
y=-(t end
else
if ami==1
y=(t else
y=-(t end
  
end
%y=(t>n-1)+(t==n-1);
d=plot(t,y);grid on;
title('Line code AMI NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('one');
end
n=n+1;
%pause;
end