Matlab Simulation: Point (symbol) Moving from star

2019-02-15 19:35发布

I would like to create an animation to demonstrate LDPC coding which is based on Sum-Product Algorithm

So far I have created a graph which shows the connections between symbol nodes (left) and parity nodes (right)alt text http://img29.imageshack.us/img29/9780/ldpc.jpg and would like to animate points travelling from symbol to parity nodes and back.

The figure is drawn by executing the following method:

function drawVertices(H)
hold on;
nodesCount = size(H);
parityNodesCount = nodesCount(1);
symbolNodesCount = nodesCount(2);
symbolPoints = zeros(symbolNodesCount, 2);
symbolPoints(:, 1) = 0;
for i = 0 : symbolNodesCount - 1
    ji = symbolNodesCount - i;
    scatter(0, ji)
    symbolPoints(i + 1, 2) = ji;

end;
parityPoints = zeros(parityNodesCount, 2);
parityPoints(:, 1) = 10;
for i = 0 : parityNodesCount - 1
    ji = parityNodesCount - i;
    y0 = symbolNodesCount/2 - parityNodesCount/2;
    scatter(10, y0 + ji)
    parityPoints(i + 1, 2) = y0 + ji;
end;
axis([-1 11 -1 symbolNodesCount + 2]);
axis off

%connect vertices
d = size(H);
for i = 1 : d(1)
    for j = 1 : d(2)
        if(H(i, j) == 1)
            plot([parityPoints(i, 1) symbolPoints(j, 1)], [parityPoints(i, 2) symbolPoints(j, 2)]);
        end;
    end;
end;

So what I would like to do here is to add another method which takes start point (x and y) and end point as arguments and animates a travelling circle (dot) from start to end and back along the displayed lines.

I would appreciate if anyone of you could show the solution or suggest any useful tutorial about matlab simulations.

Thank you!

2条回答
Melony?
2楼-- · 2019-02-15 20:07

I believe the best way to learn is by example. So I suggest you look at the demo lorenz which comes with MATLAB:

edit lorenz

For other cool animations, look for orbits.m and swinger.m demos part of Cleve Moler's book: Experiments with MATLAB


I show here a simple animation of a point moving along a circular path. The hold idea boils down to using EraseMode set to xor, and updating XData and YData of the point for each iteration:

%# coordinates
t = (0:.01:2*pi)';         %# 'fix SO syntax highlight
D = [cos(t) -sin(t)];

%# setup a figure and axis
hFig = figure('Backingstore','off', 'DoubleBuffer','on');
hAx = axes('Parent',hFig, 'XLim',[-1 1], 'YLim',[-1 1], ...
          'Drawmode','fast', 'NextPlot','add');
axis(hAx, 'off','square')

%# draw circular path
line(D(:,1), D(:,2), 'Color',[.3 .3 .3], 'LineWidth',1);

%# initialize point
h = line('XData',D(1,1), 'YData',D(1,2), 'EraseMode','xor',  ...
        'Color','r', 'marker','.', 'MarkerSize',50);
%# init text
hTxt = text(0, 0, num2str(t(1)), 'FontSize',12, 'EraseMode','xor');

i=0;
while true
    i = rem(i+1,numel(t)) + 1;               %# circular increment
    set(h,'XData',D(i,1), 'YData',D(i,2))    %# update X/Y data
    set(hTxt,'String',num2str(t(i)))         %# update angle text
    drawnow                                  %# force refresh
    if ~ishandle(h), return; end             %# in case you close the figure
end

For a detailed explanation of the parameters used (EraseMode, Backingstore, DoubleBuffer, ..), refer to this animation guide

查看更多
Fickle 薄情
3楼-- · 2019-02-15 20:21

From the documentation for comet.m

t = 0:.01:2*pi;
x = cos(2*t).*(cos(t).^2);
y = sin(2*t).*(sin(t).^2);
comet(x,y);
查看更多
登录 后发表回答