function [y,y1,y2,fs] = Chap2_filternoise(fs,cutoff)
  %% generates noise y
  %% cuts it in the frequency domain
  %% filters it
  pkg load ltfat
  pkg load signal

  nrepeats = 0;
  
  clf
  
  if(nargin < 2)
    cutoff = 2000;
    if(nargin < 1)
      fs = 8000;
    end
  end


  y = 10*noise(fs);
  n = length(y);
  nhalf = floor( n/2 );
  figure(1)
  sgram(y,fs,'dynrange',70);


  figure(2)
  fy = fft(y);
  semilogy([0:nhalf-1], abs(fy(1:nhalf))+1e-8,";fft(y);");
  hold
  
  fy1 = fy;
  fy1(cutoff:end - cutoff + 1) = 0.0;
  semilogy([0:nhalf-1], abs(fy1(1:nhalf))+1e-8,";fft(cut);");

 
  y1 = real(ifft(fy1));
 

  [b,a] = butter(5,2*cutoff/fs);
  y2 = filter(b,a,y);

  fy2 = fft(y2);
  semilogy([0:nhalf-1], abs(fy2(1:nhalf))+1e-16,";fft(filtered);");

  for i = 1:nrepeats,
    y2 = filter(b,a,y2);
  end
  fy2 = fft(y2);

  semilogy([0:nhalf-1], abs(fy2(1:nhalf))+1e-16);
  
