function gui(action)

%De globale variable initialiseres igen. Det har vist sig nødvendigt, 
%og vi tror det skyldes en fejl i MatLab

global savelyd
global lyd
global m
global n

% Alle typer støj defineres her. Det kan gøres her da denne variabel ikke 
% skal ændres
noise=['White  '
   'Pink-HF'
   'Pink-LF'];	     

% Sample raten bliver sat.  
Samples=8000;  

% HJÆLPE FUNKTIONEN
%Her starter vi med at undersøge om hjælp er aktiveret og derefter hvad brugeren trykker på.

info=findobj(gcf,'Tag','Radiobutton3');
infovalue = get(info,'Value');

%Tjekker om det er info der skal vises eller om  programmet skal bruges normalt.

if (infovalue==1) 
   
   box=findobj(gcf,'Tag','Listbox1');
   set(box,'Visible','on');
   set(box,'String',help);
   cleanHandle=findobj(gcf,'Tag','Pushbutton5');
   set(cleanHandle,'Enable','on');
      
   switch(action)
      
   case 'info'
      help={'Welcome to TSVD NoiseReduction!'
         'A program especially made for testing, the prospects of'
         'cleaning voice-signals with the TSVD-algorithm.'
         ''
			'You have the choice of several options. First, choose your'
         'preferred input sound, play it and adjust the volume.'
         ''
         'Second, select the type of noise, adjust and play. Then '
         'listen to the two combined. You are now ready to fine-tune'
         'the TSVD NoiseReduction, press clean and finally save'
         'the output.'};
         
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help );
           
   case 'cleanoff'
      gui playsound
      
   case 'cleanoff2'
	   gui playnoise
      
   case 'psave'
	   gui playoutput
     
   case 'tol'
      gui reltol
      
   case 'playsound' 
      help={'Choose a signal, set the volume. Play the input by pressing'
         'the play button. '
         ''
         'You can import your own *.wav files via the "Advanced'
         'Options" menu.'};
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help );  
      
   case 'playnoise'
      help={'Choose between the different types of noise, you would'
         'like to mix with the original signal: '
         ' '
         '· White - noise, randomly distributed over the full frequency'
         '  range.'
         '· Pink-LF - mostly the same as White noise, but strongest at '
         '  low frequencies.'
         '· Pink-HF - as Pink-LF, but strongest at high frequencies.'};
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help);  
      
   case 'playmix'
      help={'Play your combined choice of noise and input signal.'
         ' '
         'Important: You have to press this button before you can'
         'press the clean button.'};
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help);  
      
   case 'reltol'  
      relHandle=findobj(gcf,'Tag','Radiobutton1');
      reltolHandle = get(relHandle,'Value');
      numHandle=findobj(gcf,'Tag','Radiobutton2');
      
      if reltolHandle == 1
         set(numHandle,'Value',0);
      else
         set(numHandle,'Value',1);
      end   
      
      help={'Decide to what extent you would like to clean the mixed'
            'signal.  '
            ' '
            'Choose between relative tolerance or how many singular'
            'values there has to be taken into consideration. The num-'
            'ber of singular values determines how much of the signal,'
            'there is used for the cleaning. Where as, the relative tole-'
            'rance will be set for each 200 samples.'};
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help);  
      
   case 'numsvd'
      relHandle=findobj(gcf,'Tag','Radiobutton1');
      numHandle=findobj(gcf,'Tag','Radiobutton2');
      numsvdHandle = get(numHandle,'Value');
      
      if numsvdHandle == 1
         set(relHandle,'Value',0);
      else
         set(relHandle,'Value',1);
      end   
      
	 help={'Decide to what extent you would like to clean the mixed'
            'signal.  '
            ' '
            'Choose between relative tolerance or how many singular'
            'values there has to be taken into consideration. The num-'
            'ber of singular values determines how much of the signal,'
            'there is used for the cleaning. Where as, the relative tole-'
            'rance will be set for each 200 samples.'};

      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help);           
      
   case 'clean'    
      help={'TSVD NoiseReduction algorithm is now activated. Due to'
            'the complexity of the algorithm, this may take a while.'
            ''
            'Important: It cannot be activated, before you have pressed'
            'the mix button. When the algorithm is finished, you can see'
            'its effectiveness expressed with a grade and the signal to '
            'noise ratio before and after. '};

text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help);	   
      
   case 'playoutput' 
      help={'After cleaning the signal, you are automatically asked'
            'to save the cleaned signal. '
         ' '
           'You now have the option of comparing the result before'
           'and after the TSVD NoiseReduction.'};
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help);    
   end   
   
else 
   
   %boxen gøres usynelig
   box=findobj(gcf,'Tag','Listbox1');
   set(box,'Visible','off');
   
   % Vi er nu færdig med hjælpe funktionen og selve rense programmet bliver fremstillet.  
   
   switch(action)   
      
      %ABOUT KNAPPEN I MENUEN
   case 'About'
      Aboutf;
      
      %ENERGY UNDER SPECTRUM MENUEN
   case 'Energy'
      
      energyf
      
      pure=wavread('spure');
      noise=wavread('snoise');
      noisy=wavread('snoisy');
      clean=wavread('sclean');
      
      % Der laves Fast Fourier Transformation af alle lydsignalerne. For at de kan plottes.
      zpure=fft(pure);
      znoise=fft(noise);
      znoisy=fft(noisy);	
      zclean=fft(clean);
      zn=max(znoisy);
      
      leng=round(length(zpure)/2);
      
      %title(['Energy Spectrum of the Noise Signal, |Z|']);
      
      SUBPLOT(2,2,1)
      semilogy( (abs(zpure(1:(leng)))).^2 ),axis([0,leng,1e-5,1e5]), hold on,	
      title(['Input Sound']);
      xlabel('Low <- Frequency -> High'), ylabel('Amplitude');
      ax=findobj(gcf,'Tag','Axes4');
      set(ax,'xtick',[ ]);
     	set(ax,'ytick',[ ]);
      
      SUBPLOT(2,2,2)
      
      semilogy( (abs(znoise(1:(leng)))).^2 ),axis([0,leng,1e-5,1e5]),grid, hold on,
      title(['Input Noise']);
      xlabel('Low <- Frequency -> High'), ylabel('Amplitude');
      ax=findobj(gcf,'Tag','Axes3');
      set(ax,'xtick',[ ]);
     	set(ax,'ytick',[ ]);

      
      SUBPLOT(2,2,3), 
      semilogy( (abs(znoisy(1:(leng)))).^2 ),axis([0,leng,1e-5,1e5]),grid, hold on,	
      title(['Mixed Input Sound and Noise']);
      xlabel('Low <- Frequency -> High'), ylabel('Amplitude');
		ax=findobj(gcf,'Tag','Axes2');
      set(ax,'xtick',[ ]);
     	set(ax,'ytick',[ ]);
     
      SUBPLOT(2,2,4), 
      semilogy( (abs(zclean(1:(leng)))).^2 ),axis([0,leng,1e-5,1e5]),grid, hold on,
      title(['Cleaned Signal']);
      xlabel('Low <- Frequency -> High'), ylabel('Amplitude');
      ax=findobj(gcf,'Tag','Axes1');
      set(ax,'xtick',[ ]);
     	set(ax,'ytick',[ ]);

      %FREQ UNDER SPECTRUM MENUEN  
   case 'Freq'
      
      sinputf
      pure=wavread('spure');
      ymax=length(pure);
      plot(pure); axis([0,ymax,-1,1]);
      title(['Total time: ',(num2str(ymax/8000)), ' seconds']);
      xlabel('Samples'), ylabel('Amplitude');
      
      % IMPORT under Advanced menuen 
   case 'hent'   
      waveimpf
      
      %Import Kanppen under IMPOR fladen
   case 'hentgem'
      import1=findobj(gcf,'Tag','EditText1');    
      nvn=get(import1,'String');
      
      lgd=length(nvn);
      
      if (lgd>8)
         navn=nvn(1:8);
      else
         navn(1:lgd)=nvn;
         navn(lgd+1:8)=blanks(8-lgd);
         size(navn);
      end
      
      close(gcf)   
      
      if exist([deblank(navn),'.wav'],'file') 
         
         
         lyd(end+1,:)=navn; 
         inputHandle=findobj(gcf,'Tag','PopupMenu1');
         set(inputHandle,'String',lyd);
         
      else
         box=findobj(gcf,'Tag','Listbox1');
         set(box,'Visible','on');
         help={'File not found'};
         set(box,'String',help); 
         
      end      
      
      
      % LYD PLAY KNAPPEN
      %Afspiller det rene signal
      
   case 'playsound',
      
      inputHandle=findobj(gcf,'Tag','PopupMenu1');
      sound1Handle = get(inputHandle,'Value');
      sound1String = get(inputHandle,'String');
      
      file1=lyd(sound1Handle,:);
      file1(file1==' ')=[];
      wavfile=wavread([file1,'.wav']);
      
      Vol1Handle=findobj(gcf,'Tag','Slider1');
      Vol1 = get(Vol1Handle,'Value');
      Volwavfile=Vol1*wavfile(:,1);
      sound((Volwavfile),Samples);
      
      % STØJ PLAY KNAPPEN
      %Afspiller den rene støj 
   case 'playnoise',
      
      noiseHandle=findobj(gcf,'Tag','PopupMenu2');
      sound2Handle = get(noiseHandle,'Value');
      sound2String = get(noiseHandle,'String');
      file2=noise(sound2Handle,:);
      file2(file2==' ')=[];
      
      Vol2Handle=findobj(gcf,'Tag','Slider2');
      Vol2 = 0.5*get(Vol2Handle,'Value');
      
      inputHandle=findobj(gcf,'Tag','PopupMenu1');
      sound1Handle = get(inputHandle,'Value');
      sound1String = get(inputHandle,'String');
      file1=lyd(sound1Handle,:);
      file1(file1==' ')=[];
      wavfile=wavread([file1,'.wav']);
      wnoise=(rand(length(wavfile),1)*Vol2)-Vol2*0.5;
      
      switch(file2)   
         
         % Alle forskellige slags støj bliver fremstillet.   
      case 'White'
         noisefile=wnoise;
      case 'Pink-HF'
         l=length(wnoise);
         noisefile=zeros(l,1);
         noisefile(1)=wnoise(1);
         for i=2:l
            noisefile(i)=wnoise(i)-0.98*noisefile(i-1);
         end
      case 'Pink-LF'
         l=length(wnoise);
         noisefile=zeros(l,1);
         noisefile(1)=wnoise(1);
         for i=2:l
            noisefile(i)=wnoise(i)+0.98*noisefile(i-1);
         end
      case 'Car'
         
      end   
      
      mixs=noisefile; 
      mo=[abs(max(mixs)),abs(min(mixs))];
      ma=max(mo);
      
      if ma > 1
         noisefile=mixs/ma;
      else
         noisefile=mixs;
      end
      
      sound((noisefile),Samples);
      
      % MIX PLAY KNAPPEN
      %Afspiller det blandede signal
      
   case 'playmix'
      Figh = findobj(gcf,'Tag','Fig1');
      set(Figh,'HandleVisibility','on');
      
      %'input sound'
      inputHandle=findobj(gcf,'Tag','PopupMenu1');
      sound1Handle = get(inputHandle,'Value');
      sound1String = get(inputHandle,'String');
      
      file1=lyd(sound1Handle,:);
      file1(file1==' ')=[];
      wavfile=wavread([file1,'.wav']);
      
      Vol1Handle=findobj(gcf,'Tag','Slider1');
      Vol1 = get(Vol1Handle,'Value');
      Volwavfile=Vol1*wavfile(:,1);
      
      %'input noise'
      noiseHandle=findobj(gcf,'Tag','PopupMenu2');
      sound2Handle = get(noiseHandle,'Value');
      sound2String = get(noiseHandle,'String');
      file2=noise(sound2Handle,:);
      file2(file2==' ')=[];
      
      Vol2Handle=findobj(gcf,'Tag','Slider2');
      Vol2 = 0.5*get(Vol2Handle,'Value');
      
      wnoise=(rand(length(wavfile),1)*Vol2)-Vol2*0.5;
      
      % Alle forskellige slags støj bliver fremstillet igen. Dette er nemmere end at 
      %initialisere globale variable, og belaster ikke computeren.
      
      switch(file2)   
      case 'White'
         noisefile=wnoise;
      case 'Pink-HF'
         l=length(wnoise);
         noisefile=zeros(l,1);
         noisefile(1)=wnoise(1);
         for i=2:l
            noisefile(i)=wnoise(i)-0.98*noisefile(i-1);
         end
      case 'Pink-LF'
         l=length(wnoise);
         noisefile=zeros(l,1);
         noisefile(1)=wnoise(1);
         for i=2:l
            noisefile(i)=wnoise(i)+0.98*noisefile(i-1);
         end
         
      case 'Car'
         
      end   
      
      mixs=noisefile+Volwavfile(:,1); 
      ma=max([abs(max(mixs)),abs(min(mixs))]);
      
      if ma > 1
         mixsound=mixs/ma;
         snoise=noisefile/ma;
      else
         mixsound=mixs;
         snoise=noisefile;
      end
      
      q=max(mixsound);
      sound((mixsound),Samples);
      
      cleanHandle=findobj(gcf,'Tag','Pushbutton5');
      set(cleanHandle,'Enable','on');
      
      % Den relative tolerance slider
      
   case 'reltol'
      relHandle=findobj(gcf,'Tag','Radiobutton1');
      reltolHandle = get(relHandle,'Value');
      
      numHandle=findobj(gcf,'Tag','Radiobutton2');
      
      tolHandle=findobj(gcf,'Tag','Slider4');
      tol = get(tolHandle,'Value');
            
      reltHandle=findobj(gcf,'Tag','StaticText6');
      nsvHandle=findobj(gcf,'Tag','StaticText7');
      
      reltol=strcat(int2str(tol*100),' %');
      
      if reltolHandle == 1
         set(numHandle,'Value',0);
         set(nsvHandle,'Visible','off');
         set(reltHandle,'Visible','on');
         set(reltHandle,'String',reltol);
      else   
         set(numHandle,'Value',1);
      end   
      
      %Antal singulære værdier slideren fremstilles:
      
   case 'numsvd'   
      relHandle=findobj(gcf,'Tag','Radiobutton1');
      numHandle=findobj(gcf,'Tag','Radiobutton2');
      
      numsvdHandle = get(numHandle,'Value');
      
      reltHandle=findobj(gcf,'Tag','StaticText6');
      nsvHandle=findobj(gcf,'Tag','StaticText7');
      
      tolHandle=findobj(gcf,'Tag','Slider4');
      tol = get(tolHandle,'Value') ;
      
      antalsv=n-round(tol*n);
      
      if numsvdHandle == 1
         set(relHandle,'Value',0);
         set(nsvHandle,'Visible','on');
         set(reltHandle,'Visible','off');
         set(nsvHandle,'String',antalsv);
         
      else
         set(relHandle,'Value',1);
      end   
      % Den relative tolerance  
   case 'tol'
      tolHandle=findobj(gcf,'Tag','Slider4');
      tol = get(tolHandle,'Value');
            
      reltHandle=findobj(gcf,'Tag','StaticText6');
      nsvHandle=findobj(gcf,'Tag','StaticText7');
      
      antalsv=n-round(tol*n);
      reltol=strcat(int2str(tol*100),' %');
      
      relHandle=findobj(gcf,'Tag','Radiobutton1');
      numHandle=findobj(gcf,'Tag','Radiobutton2');  
      numsvdHandle = get(numHandle,'Value');
      reltolHandle = get(relHandle,'Value');
      
      if reltolHandle == 1
         
         set(nsvHandle,'Visible','off');
         set(reltHandle,'Visible','on');
         set(reltHandle,'String',reltol);
         
      elseif numsvdHandle == 1
         
         set(nsvHandle,'Visible','on');
         set(reltHandle,'Visible','off');
         set(nsvHandle,'String',antalsv);
      end
      
   case 'Slider'
      
      Hankelslider=findobj(gcf,'Tag','Slider1');
      
      a=(round(get(Hankelslider,'Value')*98)+2);
      HankelHandle1=findobj(gcf,'Tag','StaticText5');
      HankelHandle2=findobj(gcf,'Tag','StaticText6');
      set(HankelHandle1,'String',201-a);
      set(HankelHandle2,'String',a);
      
      %APPLY KNAPPEN UNDER Hankel Fladen
   case 'Apply'
      HankelHandle1=findobj(gcf,'Tag','StaticText5');
      HankelHandle2=findobj(gcf,'Tag','StaticText6');
      a=get(HankelHandle1,'String');
      b=get(HankelHandle2,'String');
      global m 
      m=str2num(a);
      global n
      n=str2num(b);
      close(gcf)
      
      % Til Hankel DIM. i advanced Menuen
   case 'Hankel'   
      
      hankelf
      
      HankelHandle1=findobj(gcf,'Tag','StaticText5');
      HankelHandle2=findobj(gcf,'Tag','StaticText6');
      Hankelslider=findobj(gcf,'Tag','Slider1');
      set(HankelHandle1,'String',m);
      set(HankelHandle2,'String',n);
      set(Hankelslider,'Value',((n-2)/98));
      inputHandle=findobj(gcf,'Tag','StaticText2');
      hm=num2str(m);
      hn=num2str(n);
      
      Text={strcat('The Hankel Matrix is currently set to ', hm,'x ',hn )
         'We recommend 180x21'
         'The sum of n+m is automaticly set to 201' };
      set(inputHandle,'String',Text);
      
      
      %  CLEAN KNAPPEN 
      % Dette er den vigtigste del af hele programmet.
      
   case 'clean'
      
      % Alle nødvendige informationer hentes fra fladen, herfra til linje 565
      
      inputHandle=findobj(gcf,'Tag','PopupMenu1');
      sound1Handle = get(inputHandle,'Value');
      sound1String = get(inputHandle,'String');
      
      file1=lyd(sound1Handle,:);
      file1(file1==' ')=[];
      wavfile=wavread([file1,'.wav']);
      
      Vol1Handle=findobj(gcf,'Tag','Slider1');
      Vol1 = get(Vol1Handle,'Value');
      Volwavfile=Vol1*wavfile;
      
      %'input noise'
      noiseHandle=findobj(gcf,'Tag','PopupMenu2');
      sound2Handle = get(noiseHandle,'Value');
      sound2String = get(noiseHandle,'String');
      file2=noise(sound2Handle,:);
      file2(file2==' ')=[];
      
      Vol2Handle=findobj(gcf,'Tag','Slider2');
      Vol2 = 0.5*get(Vol2Handle,'Value');
      
      wnoise=(rand(length(wavfile),1)*Vol2)-Vol2*0.5;
      
      switch(file2)   
      case 'White'
         noisefile=wnoise;
      case 'Pink-HF'
         l=length(wnoise);
         noisefile=zeros(l,1);
         noisefile(1)=wnoise(1);
         for i=2:l
            noisefile(i)=wnoise(i)-0.98*noisefile(i-1);
         end
      case 'Pink-LF'
         l=length(wnoise);
         noisefile=zeros(l,1);
         noisefile(1)=wnoise(1);
         for i=2:l
            noisefile(i)=wnoise(i)+0.98*noisefile(i-1);
         end
      case 'Car'
         
      end   
      
      mixs=noisefile+Volwavfile(:,1); 
      ma=max([abs(max(mixs)),abs(min(mixs))]);
      
      if ma > 1
         mixsound=mixs/ma;
         snoise=noisefile/ma;
      else
         mixsound=mixs;
         snoise=noisefile;
      end
      
      q=max(mixsound);
      
      wavwrite(mixsound,'snoisy');
      wavwrite(snoise,'snoise');
      wavwrite(Volwavfile,'spure');
      
      tolHandle=findobj(gcf,'Tag','Slider4');
      tol = get(tolHandle,'Value');
      
      relHandle=findobj(gcf,'Tag','Radiobutton1');
      reltolHandle = get(relHandle,'Value');
      
      cleanHandle=findobj(gcf,'Tag','Pushbutton5');
      set(cleanHandle,'Enable','off');
      
      input=mixsound;
      lng=length(input); %lænden af den fil der arbejdes på;
      output=zeros(1,lng); % output filen dannes
      output1=zeros(1,m);
      henkel=zeros(m,n);
      antalsv=n-round(tol*n);
      
      
      %POP UP vindue laves, 
      
      %Det der viser hvor langt man er nået med rensingen.
      % her skrives information, alle nødvendige ting findes først før
      %fladen tændes
      
      inputHandle=findobj(gcf,'Tag','PopupMenu1');
      sound1Handle = get(inputHandle,'Value');
      file1=lyd(sound1Handle,:);
      
      noiseHandle=findobj(gcf,'Tag','PopupMenu2');
      sound2Handle = get(noiseHandle,'Value');
      sound2String = get(noiseHandle,'String');
      file2=noise(sound2Handle,:);
      
      Vol2Handle=findobj(gcf,'Tag','Slider2');
      Vol2 = 0.5*get(Vol2Handle,'Value');    
      
      numHandle=findobj(gcf,'Tag','Radiobutton2');
      
      %Nu startes fladen     
      
      cleanf
      
      % Informationer sættes på fladen.
      
      % Filnavn
      popup=findobj(gcf,'Tag','StaticText4');
      set(popup,'String', file1);
      
      % Type støj
      popup=findobj(gcf,'Tag','StaticText6');
      set(popup,'String', file2);
      
      %Hankel dim
      
      popup=findobj(gcf,'Tag','StaticText12');
      set(popup,'String',strcat(num2str(m),'x',num2str(n)));
      
      %Type af rensning
      popup=findobj(gcf,'Tag','StaticText10');
      
      if reltolHandle == 1
         set(popup,'String', 'Relative tolerance');
      else   
         set(popup,'String', 'Singular values');
      end   
      
      plotHandle=findobj(gcf,'Tag','Axes1');
      
      % HER STARTES SELVE RENSNIGEN AF SIGNALET
      
      for t=0:200:(lng-200); %store løkke derkøres for 200 samples ad gangen.
         
         %POP OP Vinduets afdeling    
         getframe;
         p=t/lng*100;
         fill([p,p,0,0],[0,1,1,0],'r')%,
         set(plotHandle,'XLim',[0 100]);
         set(plotHandle,'YTick',[ ]);
         % Den stopper så her.........   		
         
         wav=input(t+1:t+200)';
         
         for i=1:m
            henkel(i,:)=wav((i):((n-1)+i));
         end	   	  
         
         [u,singul,v]=svd(henkel,0);   
         
         if reltolHandle == 1
            firstsingul=singul(1,1); % største singulær værdi
            reltol=tol*firstsingul ; %relativtolerance
         else
            reltol=singul(antalsv,antalsv);
         end   
         
         %Sætter tolerance, således at tol=15 ud af 21 værdier bibeholdes
         
         % Nu trunkeres de singulære værdier
         
         tsingul=zeros(n,n); %%%%%%%%(m,n)
         for j=1:n  
            if (singul(j,j)< reltol);
               tsingul(j,j)=0;
            else
               tsingul(j,j)=singul(j,j);
            end 
         end
         
         
         %laver nu TSVD som ny hankel
         
         hk=u*tsingul*v';
         
         for (i=1:m);					 	% algoritme der spejler en matrice om x- og y-aksenerne.
            for (j=1:n);					% til brug for vores sum af antidiagonal
               henkel((m+1)-i,(n+1)-j)=hk(i,j);
            end;
         end;
         
         output(1,t+1:t+m)=average(hk,1);			%giver de første 180 elementer
         output(1,t+(m+1):t+200)=average(henkel,0);	%giver de 20 sidste elementer
         
      end % slut på den store løkke
      
      % Rense fladen lukkes da rensningen nu er færdig.
      close(gcf)
      
      %Umiddelbart efter tvinges brugeren til at gemme. Dvs. Savefladen startes.
      savef
      
      mixs=output; 
      g=[abs(max(mixs)),abs(min(mixs))];
      ma=max(g);
      
      if ma > 1
         output=mixs/ma;
      else
         output=mixs;
      end
      
      wavwrite(output,'sclean'); %outsput
      sound(wavread('sclean'),Samples);
      
      file1=lyd(sound1Handle,:);
      file1(file1==' ')=[];
      wavfile=wavread([file1,'.wav']);   
      
      % KNAPPEN SAVE AND PLAY INDE I SAVE FLADEN
   case 'save'
      output=wavread('sclean');
      
      save1=findobj(gcf,'Tag','EditText1');    
      nvn=get(save1,'String');
      lgd=length(nvn);
      if (lgd>8)
         navn=nvn(1:8);
      else
         navn(1:lgd)=nvn;
         navn(lgd+1:8)=blanks(8-lgd);
      end
      
      Figh = findobj(gcf,'Tag','Fig1');
      set(Figh,'HandleVisibility','on');
      Figh = findobj(gcf,'Tag','Fig1');
      set(Figh,'HandleVisibility','on');
      
      if savelyd(1,:)==['       1']
         savelyd=[navn];
      else
         savelyd(end+1,:)=[navn];
      end
      wavwrite(output,deblank(navn));
      %Fladen lukkes da brugeren nu har gemt sit lydsignal.
      close(gcf)
      
      % Nu opdateres alle ting på hovedfladen:
      
      input1Handle=findobj(gcf,'Tag','PopupMenu3');
      navn(navn==' ')=[];
      set(input1Handle,'String',savelyd);
      sound(wavread('sclean'),Samples);
      love=size(savelyd);
      set(input1Handle,'Value',love(1));
      
      % Karaktererene for rensnignen laves og sættes på hovedfladen:
      pure=wavread('spure');
      noise=wavread('snoise');
      noisy=wavread('snoisy');
      clean=wavread('sclean');
      snoriginal=20*log10(norm(pure)/norm(noise)); 
      snrens= 20*log10(norm(clean)/norm(clean-pure));
      karakter=(abs((snrens/snoriginal)-1))*100;
      
      box=findobj(gcf,'Tag','Listbox1');
      set(box,'Visible','on'); 
      help={    'TSVD-NoiseReduction' 
                'Has improved the Signal/Noise ratio by:'
         strcat( num2str(karakter), ' %')
         	   ('  ')
                'Signal/Noise ratio - Input Sound:'
         strcat( num2str(snoriginal),' dB')
               ('  ')
                'Signal/Noise ratio - Cleaned Sound:'
   		strcat( num2str(snrens),' dB')};
      
      text=findobj(gcf,'Tag','Listbox1');    
      set(text,'String',help); 
      
      energyHandle=findobj(gcf,'Tag','Subuimenu1');
      set(energyHandle,'Enable','on');
      freHandle=findobj(gcf,'Tag','Spectrumuimenu1');
      set(freHandle,'Enable','on');
      
      %Cancel Knappen i alle flader.  
   case 'cancel'   
      close(gcf);
      
      %PLAY KNAPPEN I SAVE BOKSEN   
   case 'playoutput'
      
      inputHandle=findobj(gcf,'Tag','PopupMenu3');
      sound1Handle = get(inputHandle,'Value');
      sound1String = get(inputHandle,'String');
      
      file1=savelyd(sound1Handle,:);
      file1(file1==' ')=[];
      deblank(file1);
      wavfile=wavread([file1,'.wav']);
      
      Vol1Handle=findobj(gcf,'Tag','Slider3');
      Vol1 = get(Vol1Handle,'Value');
      Volwavfile=Vol1*wavfile;
      sound((Volwavfile),Samples);
      
      %GØR AT CLEAN KNAPPEN IKKE KAN BRUGES NÅR DER IKKE ER MIXET FØRST.     
   case 'cleanoff'
      
      cleanHandle=findobj(gcf,'Tag','Pushbutton5');
      set(cleanHandle,'Enable','off');
	case 'cleanoff2'
      
      cleanHandle=findobj(gcf,'Tag','Pushbutton5');
      set(cleanHandle,'Enable','off');
      
   case 'Visible'
      
      box=findobj(gcf,'Tag','Listbox1');
      set(box,'Visible','on');
      
      % QUIT knappen på hovedfladen   
   case 'quit1'
      %Fjerner den globale variabel savelyd.
      clear savelyd;
      close('TSVD-NoiseReduction')
      
   end   
   
end