Followings are the code that I wrote in Octave to creates all the plots shown in this page. You may copy these code and play with these codes. Change variables and try yourself until you get your own intuitive understanding.
< Code 1 >
x = [0 0.4 0.4 0.4 0.4 0.4 0 0 0];
sf = 11; % samples per bit
p_x = x;
if sf > 1
for i = 2:sf
p_x= [p_x ; x];
end
p_x = reshape(p_x,[],1);
end
chan = 0.3*[0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0];
%chan(1) = 1;
%chan(30) = 0.5;
cs = 123;
hFig = figure(1,'Position',[300 300 700 600]);
subplot(4,2,1);
stem(p_x,'MarkerFaceColor',[0 0 1],'color','blue');
axis([1 length(p_x) -1.0 1.0]);
title("data");
box on;
set(gca,'xticklabel',[]);
set(gca,'yticklabel',[]);
set(gca,'xtick',[]);
set(gca,'ytick',[]);
subplot(4,2,2);
stem(chan,'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[1 0 0],'color','red');
axis([1 length(p_x) -1.0 1.0]);
title("kernel");
box on;
set(gca,'xticklabel',[]);
set(gca,'yticklabel',[]);
set(gca,'xtick',[]);
set(gca,'ytick',[]);
subplot(4,2,[3 8]);
hold on;
s = p_x;
for i = 0:100
if i < length(p_x)
line([i i],[5 5+s(i+1)],'color','blue');
plot(i,5+s(i+1),'bo');
end;
end;
line([-40 140],[5 5],'color','green');
k = flip(chan);
ks = length(k);
for i = 0:100
if i < length(k)
line([i-ks+cs i-ks+cs],[3 3+k(i+1)],'color','red');
plot(i-ks+cs,3+k(i+1),'ro');
end;
end;
line([-40 140],[3 3],'color','green');
y = conv(p_x(1:min([length(p_x) cs])),chan(1:min([length(chan) cs])));
y = y(1:cs);
for i = 0:200
if i < length(y)
line([i i],[1 1+y(i+1)],'color','black');
plot(i,1+y(i+1),'ko');
end;
end;
line([-40 140],[1 1],'color','green');
rdx = min(cs,length(k));
rdy = 3.0;
rx = cs-rdx;
ry = 2.9;
rectangle('Position',[rx ry rdx rdy]);
line([cs cs],[1 1+y(end)],'color','red','LineWidth',3, 'Marker','o');
line([cs cs],[1 1+2],'color','red','LineWidth',0.5);
hold off;
axis([-50 150 0 6]);
tStr = sprintf("step = %d",cs);
title(tStr);
box on;
set(gca,'xticklabel',[]);
set(gca,'yticklabel',[]);
set(gca,'xtick',[]);
set(gca,'ytick',[]);
|