Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvfft.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * An FFT abstraction.
00006  */
00007 #ifndef __WVFFT_H
00008 #define __WVFFT_H
00009 
00010 #include "wvtypedencoder.h"
00011 #include "wvbuf.h"
00012 
00013 struct fftw_plan_struct;
00014 
00015 /**
00016  * Computes the forward FFT transformation of real valued input
00017  * to unnormalized complex output.
00018  * 
00019  * Input buffer must contain a sequence of 'double' type
00020  * values in machine order representing samples in the time domain.
00021  * 
00022  * Output buffer will contain a sequence of 'double' type
00023  * values in machine order representing data in the frequency domain.
00024  * The data is ordered as follows:
00025  *    Let 'n' be the total number of values.
00026  *    Let 'i' be an index into the buffer.
00027  *
00028  *    buf[0]   : the DC coefficient
00029  *    buf[i]   : the real component of the i'th frequency band
00030  *    buf[n-i] : the complex component of the i'th frequency band
00031  * 
00032  *
00033  * Hence data for only n/2 of the n frequency bands is output.
00034  * This is because the latter bands are merely the complex conjugate
00035  * of the former.
00036  * 
00037  * Supports reset().
00038  * 
00039  */
00040 class WvRealToComplexFFTEncoder :
00041     public WvTypedEncoder<double, double>
00042 {
00043 public:
00044     enum WindowFunction {
00045         WND_NONE,  /*!< No windowing */
00046         WND_BOXCAR /*!< After each FFT step, returns half of the sample
00047                         to the input buffer to be processed again in
00048                         the next step. */
00049     };
00050 
00051     /**
00052      * Creates a forward real-to-complex FFT encoder.
00053      *
00054      * "n" is the number of values per block
00055      * "wnd" is the window function
00056      */
00057     WvRealToComplexFFTEncoder(size_t n,
00058         WindowFunction wnd = WND_NONE);
00059     virtual ~WvRealToComplexFFTEncoder();
00060 
00061 protected:
00062     /** If not flushing, only processes at most one block of data. */
00063     virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush);
00064     virtual bool _reset();
00065 
00066 private:
00067     struct fftw_plan_struct *plan;
00068     size_t n;
00069     WindowFunction wnd;
00070 };
00071 
00072 
00073 /**
00074  * Computes the inverse FFT transformation of complex valued input
00075  * to unnormalized real output.
00076  * 
00077  * Input buffer must contain a sequence of 'double' type
00078  * values in machine order representing data in the frequency domain.
00079  * The data must be organized in the same fashion as that output
00080  * by WvRealToComplexFFTEncoder.
00081  * 
00082  * Output buffer will contain a sequence of 'double' type
00083  * values in machine order representing samples in the time domain.
00084  * 
00085  * Supports reset().
00086  * 
00087  */
00088 class WvComplexToRealFFTEncoder :
00089     public WvTypedEncoder<double, double>
00090 {
00091     struct fftw_plan_struct *plan;
00092     size_t n;
00093     WvInPlaceBufBase<double> tmpbuf;
00094     
00095 public:
00096     /**
00097      * Creates an inverse complex-to-real FFT encoder encoder.
00098      *
00099      * "n" is the number of values per block
00100      */
00101     WvComplexToRealFFTEncoder(size_t n);
00102     virtual ~WvComplexToRealFFTEncoder();
00103 
00104 protected:
00105     /** If not flushing, only processes at most one block of data. */
00106     virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush);
00107     virtual bool _reset();
00108 };
00109 
00110 
00111 /**
00112  * Computes a power spectrum from complex values input.
00113  * 
00114  * Input buffer must contain a sequence of 'double' type
00115  * values in machine order representing data in the frequency domain.
00116  * The data must be organized in the same fashion as that output
00117  * by WvRealToComplexFFTEncoder.
00118  * 
00119  * Output buffer will contain a sequence of 'double' type
00120  * values in machine order representing the power spectrum.
00121  * Only the power coefficients for (n/2)+1 bands are output.
00122  * The data is ordered as follows:
00123  *   Let 'n' be the total number of values.
00124  *   Let 'i' be an index into the buffer.
00125  *
00126  *   buf[0] : the squared DC coefficient
00127  *   buf[i] : the squared power of the i'th band
00128  * 
00129  * 
00130  * Supports reset().
00131  * 
00132  */
00133 class WvPowerSpectrumEncoder :
00134     public WvTypedEncoder<double, double>
00135 {
00136     size_t n, half, mid;
00137 
00138 public:
00139     /**
00140      * Creates a power spectrum encoder.
00141      *
00142      * "n" is the number of values per block
00143      */
00144     WvPowerSpectrumEncoder(size_t n);
00145 
00146 protected:
00147     /** If not flushing, only processes at most one block of data. */
00148     virtual bool _typedencode(IBuffer &inbuf, OBuffer &outbuf, bool flush);
00149     virtual bool _reset();
00150 };
00151 
00152 #endif // __WVFFT_H

Generated on Sat Feb 21 21:05:27 2004 for WvStreams by doxygen 1.3.5