Mercurial > hg > octave-lyh
diff scripts/signal/fftfilt.m @ 2303:5cffc4b8de57
[project @ 1996-06-24 09:15:24 by jwe]
author | jwe |
---|---|
date | Mon, 24 Jun 1996 09:15:24 +0000 |
parents | 5d29638dd524 |
children | 2b5788792cad |
line wrap: on
line diff
--- a/scripts/signal/fftfilt.m +++ b/scripts/signal/fftfilt.m @@ -1,39 +1,40 @@ -# Copyright (C) 1996 John W. Eaton -# -# This file is part of Octave. -# -# Octave is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; either version 2, or (at your option) any -# later version. -# -# Octave is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with Octave; see the file COPYING. If not, write to the Free -# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +### Copyright (C) 1996 John W. Eaton +### +### This file is part of Octave. +### +### Octave is free software; you can redistribute it and/or modify it +### under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 2, or (at your option) +### any later version. +### +### Octave is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +### General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with Octave; see the file COPYING. If not, write to the Free +### Software Foundation, 59 Temple Place - Suite 330, Boston, MA +### 02111-1307, USA. function y = fftfilt (b, x, N) -# usage: fftfilt (b, x [, N]) -# -# y = fftfilt (b, x) filters x with the FIR filter b using the FFT. -# y = fftfilt (b, x, N) uses the overlap-add method to filter x with -# b using an N-point FFT. + ## usage: fftfilt (b, x [, N]) + ## + ## y = fftfilt (b, x) filters x with the FIR filter b using the FFT. + ## y = fftfilt (b, x, N) uses the overlap-add method to filter x with + ## b using an N-point FFT. -# Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 3, 1994 + ## Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 3, 1994 -# Reference: Oppenheim & Schafer (1989). Discrete-time Signal -# Processing (Chapter 8). Prentice-Hall. + ## Reference: Oppenheim & Schafer (1989). Discrete-time Signal + ## Processing (Chapter 8). Prentice-Hall. -# If N is not specified explicitly, we do not use the overlap-add -# method at all because loops are really slow. Otherwise, we only -# ensure that the number of points in the FFT is the smallest power -# of two larger than N and length(b). This could result in length -# one blocks, but if the user knows better ... + ## If N is not specified explicitly, we do not use the overlap-add + ## method at all because loops are really slow. Otherwise, we only + ## ensure that the number of points in the FFT is the smallest power + ## of two larger than N and length(b). This could result in length + ## one blocks, but if the user knows better ... if (nargin < 2 || nargin > 3) usage (" fftfilt (b, x [, N])"); @@ -56,12 +57,12 @@ b = reshape (b, 1, l_b); if (nargin == 2) -# Use FFT with the smallest power of 2 which is >= length (x) + -# length (b) - 1 as number of points ... + ## Use FFT with the smallest power of 2 which is >= length (x) + + ## length (b) - 1 as number of points ... N = 2^(ceil (log (l_x + l_b - 1) / log(2))); y = ifft (fft (x, N) .* fft(b, N)); else -# Use overlap-add method ... + ## Use overlap-add method ... if !(is_scalar (N)) error ("fftfilt: N has to be a scalar"); endif @@ -81,8 +82,8 @@ y = reshape (y(1:l_x), r_x, c_x); -# Final cleanups: if both x and b are real respectively integer, y -# should also be + ## Final cleanups: if both x and b are real respectively integer, y + ## should also be if (! (any (imag (x)) || any (imag (b)))) y = real (y);