%  Plot foldningsresultat for bestemt tidspunkt
%
%  version 2.0, 26/1-1998

function ans = fold_res (sig_data1,sig_data2,hp1,hp2,position)

%  Find signallaengder

N1=max(size(sig_data1));
N2=max(size(sig_data2));
N=max([N1 N2]);

%  Set up the different axis

axes(hp1)
cla
plot(sig_data1,'b')
axis([0 N-1 1.1*min([sig_data1 sig_data2]) 1.1*max([sig_data1 sig_data2])])
hold on
signal1 = line('color','r','linestyle','--','erase','xor','xdata',[],'ydata',[]);

max_value=max(conv(sig_data1,sig_data2))*1.1;
min_value=min(conv(sig_data1,sig_data2))*1.1;

axes(hp2)
cla
plot(conv(sig_data1,sig_data2),'b') 
axis([0 N-1 min_value max_value])
hold on
signal2 = line('color','b','linestyle','-','erase','none','xdata',[],'ydata',[]);

%  Plot filteret oven på dataene

i=position;

  if (i<N2)
    N1val=(1:i);
    N2val=(i:-1:1);
  elseif (i<N1)
    N1val=(1:N2)+i-N2;
    N2val=(N2:-1:1);
  else
    N1val=(1+i-N2:N1);
    N2val=(N2:-1:i-N1+1);
  end

  % Opdater plottet

  axes(hp1)
  set(signal1,'xdata',N1val,'ydata',sig_data2(N2val))
  set(hp1,'Xticklabel','','Yticklabel','')
  title('Ingangssignal')
  axes(hp2)
  plot([position position],[min_value max_value],'r--')
  set(hp2,'Xticklabel','','Yticklabel','')
  title('Resultat')
