home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 8.ddi / SIGNAL.DI$ / FFTFILT.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.2 KB  |  53 lines

  1. function y = fftfilt(b,x,nfft)
  2. %FFTFILT Overlap-add method of filtering using FFT.
  3. %    Y = FFTFILT(B,X) filters X with the FIR filter B using
  4. %    the overlap/add method.
  5. %    Y = FFTFILT(B,X,N) uses to overlap/add method to filter
  6. %    X with B using an N-point FFT.
  7. %    See also FILTER.
  8.  
  9. %    Author: L. Shure 7-27-88
  10. %    Revised: LS, 4-25-90
  11. %    (c) Copyright 1987-90, by The MathWorks, Inc.
  12.  
  13. %    Reference:
  14. %       A.V. Oppenheim and R.W. Schafer, Digital Signal 
  15. %          Processing, Prentice-Hall, 1975.
  16.  
  17.  
  18. if nargin < 3
  19.     nfft = 512;
  20. end
  21. [m,n] = size(x);
  22. y = zeros(m,n);
  23. nx = max(m,n);
  24. if m > n
  25.     b = b(:);
  26. end
  27. nb = length(b);
  28. if nb > nfft
  29.     nfft = nb;
  30. end
  31. nfft = 2.^(ceil(log(nfft)/log(2))); % force this to a power of 2 for speed
  32. if nx < nfft    % see if we can make this less than 512 or nfft
  33.     powerof2 = 2.^(ceil(log(nx)/log(2)));
  34.     if (powerof2 < nfft) & (nargin < 3) & (nb <= nx)
  35.         nfft = powerof2;
  36.     end
  37. end
  38. B = fft(b,nfft);
  39. L = nfft - nb + 1;
  40. istart = 1;
  41. while istart <= nx
  42.     iend = min(istart+L-1,nx);
  43.     X = fft(x(istart:iend),nfft);
  44.     Y = ifft(X.*B);
  45.     yend = min(nx,istart+nfft-1);
  46.     y(istart:yend) = y(istart:yend) + Y(1:(yend-istart+1));
  47.     istart = istart + L;
  48. end
  49. if ~any(imag(b)) & ~any(imag(x))
  50.     y = real(y);
  51. end
  52.  
  53.