%  Foldningsdemo for 49415
%
%  Kode rettet for kørsel under Matlab 5.0
%
%  Version 3.3, Jørgen Arendt Jensen, 7/2-2000

%  Lav vindue for resultat, filter og indgangssignal

clf
hp1=axes('position',[0.25 0.56 0.65 0.35]);  %  Vindue for foldning
set(hp1,'NextPlot','replace');
set(hp1,'Xticklabel','','Yticklabel','')
hp2=axes('position',[0.25 0.05 0.4 0.4]);  %  Vindue for resultat
set(hp2,'NextPlot','replace');
set(hp2,'Xticklabel','','Yticklabel','')
hp3=axes('position',[0.7 0.05 0.25 0.4]);   %  Vindue for filterresponse
set(hp3,'Xticklabel','','Yticklabel','')

%  Sæt hastigheden for foldningen ved hjælp af en måling

disp('Måler computerens hastighed...')
hastighed=0;
tic;
while (toc<2)
   for i=1:100
     hastighed=hastighed+1;
     a=sin(23);
     end
   end
hastighed=hastighed/40;

%  Lav signaler

sig_data1=randn(1,200);
sig_stoej=sig_data1/(3*std(sig_data1));
sig_firkant=[zeros([1 60]) ones(1,25) zeros([1 60])];
sig_trekant=[zeros([1 60]) (25:-1:1)/25 zeros([1 60])];
sig_sin1=[zeros([1 60]) sin(2*pi*(1/25)*(1:100)) zeros([1 60])];
sig_sin2=[zeros([1 60]) sin(2*pi*(1/15)*(1:6*15)) zeros([1 70])];
sig_reflec=zeros([1 300]);
sig_reflec(40)=1;
sig_reflec(120)=-0.4;
sig_reflec(180)=0.7;
sig_reflec(200)=0.81;
sig_reflec(240)=1.4;

firkant_filter=[0 ones(1,25)*1.01 0];
trekant_filter=[0 (25:-1:1)/25 0];
RC=5;
RC_filter=[zeros(1,5) exp(-(1:50)/RC)];
puls=sin(2*pi*(1:30)*0.1).*hanning(30)';

%  Sæt startsignaler

impuls=firkant_filter;
signal=sig_firkant;

%  Knapper for forskellige signaler

tf1=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.9 0.15 0.08],...
              'Callback','foldning(signal,impuls,hp1,hp2,hastighed);',...
              'String','Fold');

tf2=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.8 0.15 0.08],...
              'Callback','plot_sig(signal,impuls,hp1,hp2,''b'',tf3);',...
              'String','Resultat');

tf4=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.7 0.15 0.08],...
              'Callback','plot_spektre(signal,impuls,hp1,hp2,hp3);',...
              'String','Spektre');

tf3=uicontrol('Style','slider',...
              'Units','normalized','Position',[0.22 0.5 0.72 0.04],'Value',0,...
              'Max',max([max(size(signal)) max(size(impuls))]),'Min',0,...
              'Callback','fold_res(signal,impuls,hp1,hp2,get(tf3,''value''));');

ts1=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.3 0.95 0.1 0.04],...
              'Callback','signal=sig_sin1; plot_sig(signal,impuls,hp1,hp2,''w'',tf3);',...
              'String','Sinus 1');

ts2=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.45 0.95 0.1 0.04],...
              'Callback','signal=sig_sin2; plot_sig(signal,impuls,hp1,hp2,''w'',tf3);',...
              'String','Sinus 2');

ts3=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.6 0.95 0.1 0.04],...
              'Callback','signal=sig_firkant; plot_sig(signal,impuls,hp1,hp2,''w'',tf3);',...
              'String','Firkant');

ts4=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.75 0.95 0.1 0.04],...
              'Callback','signal=sig_trekant; plot_sig(signal,impuls,hp1,hp2,''w'',tf3);',...
              'String','Trekant');

ts5=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.90 0.95 0.1 0.04],...
              'Callback','signal=sig_reflec; plot_sig(signal,impuls,hp1,hp2,''w'',tf3);',...
              'String','Reflec');

ti0=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.53 0.15 0.08],...
              'Callback','plot_ovr(impuls,hp3);',...
              'String','Overfoer.');

ti1=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.41 0.15 0.08],...
              'Callback','impuls=RC_filter; plot_imp(impuls,signal,hp2,hp3,tf3);',...
              'String','RC filt.');

ti2=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.29 0.15 0.08],...
              'Callback','impuls=firkant_filter; plot_imp(impuls,signal,hp2,hp3,tf3);',...
              'String','Firkant');

ti2=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.17 0.15 0.08],...
              'Callback','impuls=trekant_filter; plot_imp(impuls,signal,hp2,hp3,tf3);',...
              'String','Trekant');

ti3=uicontrol('Style','Pushbutton',...
              'Units','normalized','Position',[0.02 0.05 0.15 0.08],...
              'Callback','impuls=puls; plot_imp(impuls,signal,hp2,hp3,tf3);',...
              'String','Puls');

