PDA

View Full Version : Algorithm implementation


Black Adder
04-24-2008, 10:14 AM
Hi,

Tried to implement this algorithm in section 4 in this paper :
www.stromhaug.no/text.pdf
but i am not sure if it works correctly because i get very high(up to 10^6)
values for A(t) even with a good match. Could anyone please check my code ?

function mini=cdp(ref, stream);



clear P;



tau=1;

mini=inf;

P=zeros(numel(ref),numel(stream));





P(:,1)=inf;

P(:,2)=inf;


for t=1:numel(stream),


while(tau<numel(ref)+1)

if (tau==1)

P(1,t+2)=3*abs(stream(t)-ref(1));

end


if (tau==2)

if(t==1)

P(2,t+2)=
min(P(1,t+1)+3*abs(stream(t)-ref(2)),P(1,t+2)+3*abs(stream(t)-ref(2)));


else

temp=min(P(1,t)+2*abs(stream(t-1)-ref(2))+abs(stream(t)-ref(2)),P(1,t+1)+3*abs(stream(t)-ref(2)));

P(2,t+2)= min(temp,P(1,t+2)+3*abs(stream(t)-ref(2)));

end

end




if(tau>2)

if(t==1)

P(tau,t+2)=
min(P(tau-1,t+1)+3*abs(stream(t)-ref(tau)),P(tau-2,t+1)+3*abs(stream(t)-ref(tau-1))+3*abs(stream(t)-ref(tau)));


else

temp=min(P(tau-1,t)+2*abs(stream(t-1)-ref(tau))+abs(stream(t)-ref(tau)),P(tau-1,t+1)+3*abs(stream(t)-ref(tau)));

P(tau,t+2)=
min(temp,P(tau-2,t+1)+3*abs(stream(t)-ref(tau-1))+3*abs(stream(t)-ref(tau)));



end

end

tau=tau+1;

end



if((1/3*(tau-1))*P(tau-1,t+2)<mini)

mini=(1/3*(tau-1))*P(tau-1,t+2);

end

p(t)=(1/3*(tau-1))*P(tau-1,t+2);


tau=1;




end


plot(p)