          do_whiten = 0;
          if(do_whiten),
             % compute psd of the whole file
             [x,fs]=wavread(wavfile1);
             nsamp = length(x);
             NFFT= 16 * round(512*fs/200/16);
             b = abs(specgram(x,NFFT)).^2;
             noise_psd = mean(b,2);

             % Design a whitening filter 
             h = 1./sqrt([noise_psd; noise_psd(end-1 : -1 : 2)]);
             whiten_filter = real(ifft(h));
             wts = hanning(NFFT);
             wts = wts/sum(wts) * sqrt(NFFT);
             % factor 3.52 chosen to give variance 1 noise.
             whiten_filter = fftshift(whiten_filter).*(wts*NFFT/3.52);
             % prewhiten snippet
             xw = conv(whiten_filter,x);
             xw = xw(NFFT/2+1 :  NFFT/2+nsamp);
             %figure(1);
             %subplot(121); specgram(x,NFFT);
             %subplot(122); specgram(xw,NFFT);
             %figure(2);
             %pause
          end;

