Changeset 11722 for trunk/doc/pslib/psLibSDRS.tex
- Timestamp:
- Feb 8, 2007, 3:19:43 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/doc/pslib/psLibSDRS.tex (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/pslib/psLibSDRS.tex
r11598 r11722 1 %%% $Id: psLibSDRS.tex,v 1.44 0 2007-02-03 00:13:08 eugene Exp $1 %%% $Id: psLibSDRS.tex,v 1.441 2007-02-09 01:19:43 price Exp $ 2 2 \documentclass[panstarrs,spec]{panstarrs} 3 3 … … 6435 6435 6436 6436 We require the ability to calculate the (fast) Fourier transforms of 6437 floating-point one-dimensional vectors and two-dimensional images. We6438 expect that these will be implemented through wrapping an external 6439 library. We define the following APIs to support FFT operations on vectors: 6440 6441 \begin{prototype} 6442 psVector *psVectorFFT(psVector *out, const psVector *in, psFFTFlags direction); 6443 psVector *psVectorReal(psVector *out, const psVector *in); 6444 psVector *psVectorImaginary(psVector *out, const psVector *in); 6445 psVector *psVectorComplex(psVector *out, const psVector *real, const psVector *imag);6446 psVector *psVectorConjugate(psVector *out, const psVector *in);6437 floating-point one-dimensional vectors and two-dimensional images. 6438 These will be implemented through wrapping an external library. We 6439 expect that we shall only want to deal with purely real vectors and 6440 images, rather than complex; this can save operations when performing 6441 the FFT (roughly a factor of 2). We define the following APIs to 6442 support FFT operations on vectors: 6443 6444 \begin{prototype} 6445 bool psVectorForwardFFT(psVector **real psVector **imag, const psVector *in); 6446 bool psVectorBackwardFFT(psVector **out, const psVector *real, const psVector *imag, int origNum); 6447 6447 psVector *psVectorPowerSpectrum(psVector *out, const psVector *in); 6448 \end{prototype} 6449 6450 The forward and reverse FFT is calculated using \code{psVectorFFT}, 6451 which takes as input the vector of interest (\code{in}) and the 6452 direction (\code{direction}), which is specified by an enumerated type 6453 defined below. The input vector may be of type \code{psF32} or 6454 \code{psC32}, the result is always \code{psC32}. If the input vector 6455 is \code{psF32}, the direction must be forward. Neither the forward 6456 or inverse transforms must multiply by $1/N$ (or $1/N^{1/2}$), and so 6457 it falls to the responsibility of the user to multiply a vector that 6458 has been forward- and reverse-transformed by $1/N$. 6459 6460 Conversions between complex and real vectors requires the functions 6461 \code{psVectorReal}, which returns the real part (\code{psF32}) of the 6462 complex vector \code{in}, \code{psVectorImaginary}, which returns the 6463 the magnitude of the imaginary part (\code{psF32}) of the complex 6464 vector \code{in}, and \code{psVectorComplex}, which constructs a 6465 complex vector (\code{psC32}) from the real and imaginary components 6466 \code{real} and \code{imag}, both of type \code{psF32}. 6467 6468 We also specify the additional utility functions 6469 \code{psVectorConjugate} and \code{psVectorPowerSpectrum} which 6470 construct the complex conjugate (\code{psC32}) and the magnitude 6471 (\code{psF32}) vectors of the input complex vector (\code{psC32}). 6472 6473 The direction of an FFT performed by \code{psVectorFFT} is specified 6474 by an enumerated type, \code{psFFTFlags}: 6475 6476 \begin{datatype} 6477 /** Specify direction of FFT, and if the result is real or not */ 6478 typedef enum { 6479 PS_FFT_FORWARD = 1, ///< psImageFFT/psVectorFFT should perform a forward FFT. 6480 PS_FFT_REVERSE = 2, ///< psImageFFT/psVectorFFT should perform a reverse FFT. 6481 PS_FFT_REAL_RESULT = 4 ///< psImageFFT/psVectorFFT should return a real image. This is valid 6482 ///< for only reverse FFT, i.e., the psImageFFT/psVectorFFT flag 6483 ///< parameter should appear as PS_FFT_REVERSE+PS_FFT_REAL_RESULT. 6484 } psFFTFlags; 6485 \end{datatype} 6486 6487 The entry \code{PS_FFT_REAL_RESULT} means that the output of an 6488 inverse FFT is to be purely real. An example of its use is: 6489 \begin{verbatim} 6490 out = psImageFFT(in, PS_FFT_REVERSE | PS_FFT_REAL_RESULT); 6491 \end{verbatim} 6492 6493 The output from a FFT must be of the same size as the input, and the 6494 size of the power spectrum equal to $N/2 + 1$, where $N$ is the number 6495 of elements in the input. In the future, if this adversely affects 6496 performance, this will be revised so that the redundant information 6497 will be neglected. 6448 bool psVectorComplexMultiply(psVector **outReal, psVector **outImag, 6449 const psVector *in1Real, const psVector *in1Imag, 6450 const psVector *in2Real, const psVector *in2Imag); 6451 \end{prototype} 6452 6453 We might have chosen to use the \code{complex} types that C99 6454 provides, but unfortunately this isn't implemented on all the systems 6455 that we would have desired. Instead, we use separate vectors 6456 to carry the real and imaginary parts. 6457 6458 The forward FFT (exponent $-1$) is calculated using 6459 \code{psVectorForwardFFT}, which takes as input the vector of interest 6460 (\code{in}) of type F32, returning the \code{real} and 6461 \code{imaginary} parts in separate vectors, which are allocated if 6462 required. 6463 6464 The backward FFT (exponent $+1$) is calculated using 6465 \code{psVectorBackwardFFT}, which takes as input the \code{real} and 6466 \code{imaginary} parts, each of type F32, and returns the purely real 6467 \code{out} vector, which is allocated if required. Due to the 6468 ambiguity in the size of the original vector when the purely real 6469 optimisation is made, this function also requires the number of 6470 elements, \code{origNum} in the original vector before FFT-ing with 6471 \code{psVectorForwardFFT}. 6472 6473 Note that the FFTs are not normalised, and so it falls to the 6474 responsibility of the user to multiply a vector that has been forward- 6475 and reverse-transformed by $1/N$. 6476 6477 \code{psVectorPowerSpectrum} calculates the power spectrum (magnitude 6478 of the fourier transform) from the \code{in} vector (of type F32. 6479 6480 Finally, for convenience, the function \code{psVectorComplexMultiply} 6481 is provided to multiply two vectors of complex numbers which are 6482 specified by their real and imaginary parts, and returning the real 6483 and imaginary parts separately. 6498 6484 6499 6485 In analogy with the vector FFT operations, we also define matching 6500 6486 image operations as follows: 6501 6487 \begin{prototype} 6502 psImage *psImageFFT(psImage *out, const psImage *image, psFFTFlags direction); 6503 psImage *psImageReal(psImage *out, const psImage *in); 6504 psImage *psImageImaginary(psImage *out, const psImage *in); 6505 psImage *psImageComplex(psImage *out, const psImage *real, const psImage *imag); 6506 psImage *psImageConjugate(psImage *out, const psImage *in); 6488 bool psImageForwardFFT(psImage **real psImage **imag, const psImage *in); 6489 bool psImageBackwardFFT(psImage **out, const psImage *real, const psImage *imag, int origCols); 6507 6490 psImage *psImagePowerSpectrum(psImage *out, const psImage *in); 6508 \end{prototype} 6491 bool psImageComplexMultiply(psImage **outReal, psImage **outImag, 6492 const psImage *in1Real, const psImage *in1Imag, 6493 const psImage *in2Real, const psImage *in2Imag); 6494 \end{prototype} 6495 6496 The only subtle difference is in \code{psImageBackwardFFT}, where the 6497 number of columns in the original image (before applying 6498 \code{psImageForwardFFT}) is required due to the ambiguity arising 6499 from the optimisation made for purely real data. Note that the number 6500 of rows need not be provided, because the FFT-ed image is shrunk in 6501 the columns but not the rows. 6509 6502 6510 6503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 6612 6605 \subsubsection{Convolve an image with the kernel} 6613 6606 6614 Given an input image and the convolution kernel, 6615 \code{psImageConvolve} shall convolve the input image, 6616 \code{in}, with the kernel, \code{kernel} and return the convolved 6617 image, \code{out}. The API shall be the following: 6618 \begin{prototype} 6619 psImage *psImageConvolve(psImage *out, const psImage *in, 6620 const psKernel *kernel, bool direct); 6621 \end{prototype} 6622 6623 Two methods shall be available for the convolution: if \code{direct} 6624 is \code{true}, then the convolution shall be performed in real space 6625 (appropriate for small kernels); otherwise, the convolution shall be 6626 performed using Fast Fourier Transforms (FFTs; appropriate for larger 6627 kernels). The latter option involves padding the input image, copying 6628 the kernel into an image of the same size as the padded input image, 6629 performing an FFT on each, multiplying the FFTs, and performing an 6630 inverse FFT before trimming the image back to the original size. 6607 Two methods are available for the convolution: direct and FFT. Given 6608 an input image and the convolution kernel, 6609 \code{psImageConvolveDirect} and \code{psImageConvolveFFT} shall 6610 convolve the input image, \code{in}, with the kernel, \code{kernel} 6611 and return the convolved image, \code{out}. The APIs shall be the 6612 following: 6613 \begin{prototype} 6614 psImage *psImageConvolveDirect(psImage *out, const psImage *in, 6615 const psKernel *kernel); 6616 psImage *psImageConvolveFFT(psImage *out, const psImage *in, 6617 const psKernel *kernel); 6618 \end{prototype} 6619 6620 \code{psImageConvolveDirect} shall perform the convolution in real 6621 space (appropriate for small kernels); \code{psImageConvolveFFT} shall 6622 perform the convolution using Fast Fourier Transforms (FFTs; 6623 appropriate for larger kernels). The latter option involves padding 6624 the input image, copying the kernel into an image of the same size as 6625 the padded input image, performing an FFT on each, multiplying the 6626 FFTs, and performing an inverse FFT before trimming the image back to 6627 the original size. 6631 6628 6632 6629 In the event that \code{out} is \code{NULL}, a new \code{psImage}
Note:
See TracChangeset
for help on using the changeset viewer.
