CFIR2D(3S)CFIR2D(3S)NAME
CFIR2D, ZFIR2D, SFIR2D, DFIR2D - Compute the two-dimensional (2D)
convolution of two 2D arrays
SYNOPSIS
Single precision complex
Fortran:
CALL CFIR2D (x, incx, ldx, i1x0, nx1, i2x0, nx2, h, inch, ldh,
i1h0, nh1, i2h0, nh2, y, incy, ldy, i1y0, ny1, i2y0, ny2,
alpha, beta)
C/C++:
#include <scsl_fft.h>
void cfir2d( scsl_complex *x, int incx, int ldx, int i1x0, int
nx1, int i2x0, int nx2, scsl_complex h, int inch, int ldh, int
i1h0, int nh1, int i2h0, int nh2, scsl_complex y, int incy, int
ldy, int i1y0, int ny1, int i2y0, int ny2, scsl_complex *alpha,
scsl_complex *beta);
C++ STL:
#include <complex.h>
#include <scsl_fft.h>
void cfir2d( complex<float> *x, int incx, int 1dx, int i1x0,
int nx1, int i2x0, int nx2, complex<float> h, int inch, int
ldh, int i1h0, int nh1, int i2h0, int nh2, complex<float> y,
int incy, int ldy, int i1y0, int ny1, int i2y0, complex<float>
*alpha, complex<float> *beta);
Double precision complex
Fortran:
CALL ZFIR2D (x, incx, ldx, i1x0, nx1, i2x0, nx2, h, inch, ldh,
i1h0, nh1, i2h0, nh2, y, incy, ldy, i1y0, ny1, i2y0, ny2,
alpha, beta)
C/C++:
#include <scsl_fft.h>
void cfir2d( scsl_zomplex *x, int incx, int ldx, int i1x0, int
nx1, int i2x0, int nx2, scsl_zomplex h, int inch, int ldh, int
i1h0, int nh1, int i2h0, int nh2, scsl_zomplex y, int incy, int
ldy, int i1y0, int ny1, int i2y0, scsl_zomplex *alpha,
scsl_zomplex *beta);
C++ STL:
#include <complex.h>
#include <scsl_fft.h>
void cfir2d( complex<double> *x, int incx, int ldx, int i1x0,
int nx1, int i2x0, int nx2, complex<double> h, int inch, int
ldh, int i1h0, int nh1, int i2h0, int nh2, complex<double> y,
int incy, int ldy, int i1y0, int ny1, int i2y0, complex<double>
*alpha, complex<double> *beta);
Page 1
CFIR2D(3S)CFIR2D(3S)
Single precision
Fortran:
CALL SFIR2D (x, incx, ldx, i1x0, nx1, i2x0, nx2, h, inch, ldh,
i1h0, nh1, i2h0, nh2, y, incy, ldy, i1y0, ny1, i2y0, ny2,
alpha, beta)
C/C++:
#include <scsl_fft.h>
void sfir2d( float *x, int incx, int ldx, int i1x0, int nx1,
int i2x0, int nx2, float h, int inch, int ldh, int i1h0, int
nh1, int i2h0, int nh2, float y, int incy, int ldy, int i1y0,
int ny1, int i2y0, float alpha, float beta);
Double precision
Fortran:
CALL DFIR2D (x, incx, ldx, i1x0, nx1, i2x0, nx2, h, inch, ldh,
i1h0, nh1, i2h0, nh2, y, incy, ldy, i1y0, ny1, i2y0, ny2,
alpha, beta)
C/C++:
#include <complex.h>
#include <scsl_fft.h>
void dfir2d( double *x, int incx, int ldx, int i1x0, int nx1,
int i2x0, int nx2, double h, int inch, int ldh, int i1h0, int
nh1, int i2h0, int nh2, double y, int incy, int ldy, int i1y0,
int ny1, int i2y0, double alpha, double beta);
IMPLEMENTATION
These routines are part of the SCSL Scientific Library and can be loaded
using either the -lscs or the -lscs_mp option. The -lscs_mp option
directs the linker to use the multi-processor version of the library.
When linking to SCSL with -lscs or -lscs_mp, the default integer size is
4 bytes (32 bits). Another version of SCSL is available in which integers
are 8 bytes (64 bits). This version allows the user access to larger
memory sizes and helps when porting legacy Cray codes. It can be loaded
by using the -lscs_i8 option or the -lscs_i8_mp option. A program may use
only one of the two versions; 4-byte integer and 8-byte integer library
calls cannot be mixed.
The C and C++ prototypes shown above are appropriate for the 4-byte
integer version of SCSL. When using the 8-byte integer version, the
variables of type int become long long and the <scsl_fft_i8.h> header
file should be included.
DESCRIPTION
These routines compute the convolution of a 2D filter array h with the 2D
array x, producing the output 2D array y:
Page 2
CFIR2D(3S)CFIR2D(3S)
y = beta * y + alpha * h * x
Let the following be the filter and data matrices:
H = hi, j 0 <=i <=nh1, 1<= j <=nh2
X = xi, j 0<= i <=nx1, 1 <=j < nx2
The convolution operation is defined as:
Y(i,j) = Sum Sum H(k,l) * x(i+k, j+l)
k l
The matrix Y has values defined for 0<= i<(nx1+nh1-1) and 0 <= j < (nx2 +
nh2 - 1). In the *FIR2D routines, the number of terms in the output array
is specified by the arguments ny1 and ny2. If ny1 < (nx1 + nh1 - 1) or
ny2 < (nx2 + nh2 - 1), the output array y is truncated. If ny1 < (nx1 +
nh1 - 1) or ny2 < (nx2 + nh2 - 1), the terms beyond i = (nx1 + nh1 - 2)
and j = (nx2 + nh2 - 2) are set to 0.
Generally, the arrays x, h and y represent signals sampled at equal
intervals in two dimensions, and the indexes of the arrays denote the
samples. If all three signals are aligned, we may, without loss of
generality, set the initial samples to 0 in both dimensions, as in the
formulas above.
The *FIR2D routines, however, permit more generality than this. The
signals may be shifted from each other using input parameters specifiying
the initial samples in each dimension. This can be useful in several
situations. For example, if the input array has leading zero values that
one does not wish to store, i1x0 and i2x0 may be set to the sample
corresponding to the first non-zero element in the input array, and
previous samples are treated as 0. Another use is to limit the output to
just the "fully engaged" terms of the convolution.
When nx1 >= nh1 and nx2 >= nh2, the convolution defined above has ramp-up
and ramp-down regions in which fewer than all nh1*nh2 filter values
contribute to the output value, Y(i,j). Setting i1y0 to nh1-1 and i2y0 to
nh2-1 causes the first value output to correspond to sample (nh1-1, nh2-
1), thus skipping the ramp up region. Setting ny1 to nx1-nh1+1 and ny2 to
nx2-nh2+1 then drops the ramp-down terms, limiting the output to just the
fully engaged part.
Note that, instead of (0,0), the initial sample could just as easily have
been labeled (1,1) or (10,1) or (0,-78); the relevant point is that the
first elements of each of the x, h and y arrays are defined to be the
same sample as long as i1x0 = i1h0 = i1y0 and i2x0 = i2h0 = i2y0.
Page 3
CFIR2D(3S)CFIR2D(3S)
See the NOTES section of this man page for information about the
interpretation of the data types described in the following arguments.
These routines have the following arguments:
x Array of dimension (ldx, nx2). (input).
CFIR2D: Single precision complex array.
ZFIR2D: Double precision complex array.
SFIRC2D: Single precision array.
DFIR2D: Double precision array.
Input array containing the data to be convolved with h.
incx Integer. (input)
Increment between two successive values of x. incx must not be
0.
ldx Integer. (input)
The number of rows in the x array, as it was declared in the
calling program (the leading dimension of x). ldx >= MAX (nx1
* incx, 1)
i1x0 Integer. (input)
Sample corresponding to the first element of each column of x.
nx1 Integer. (input)
The number of elements in each column of x. nx1 >= 0.
i2x0 Integer. (input).
Sample corresponding to the first element of each row of x.
nx2 Integer. (input).
Number of elements in each row of x. nx2 >= 0.
h Array of dimension (ldh, nh2). (input).
CFIR2D: Single precision complex array.
ZFIR2D: Double precision complex array.
SFIR2D: Single precision array.
DFIR2D: Double precision array.
Input array containing the filter matrix to be convolved with
x.
inch Integer. (input)
Increment between two successive values of h. inch must not be
0.
ldh Integer. (input)
The number of rows in the h array, as it was declared in the
calling program (the leading dimension of h). ldh >= MAX(nh1 *
inch, 1).
Page 4
CFIR2D(3S)CFIR2D(3S)
i1h0 Integer. (input)
Sample corresponding to the first element of each column of h.
nh1 Integer. (input)
The number of elements in each column of h. nh1 >= 0.
i2h0 Integer. (input)
Sample corresponding to the first element of each row of h.
nh2 Integer. (input)
Specifies the number of elements in each row of h. nh2 >= 0.
y Array of dimension (ldy, ny2). (input and output)
CFIR2D: Single precision complex array.
ZFIR2D: Double precision complex array.
SFIR2D: Single precision array.
DFIR2D: Double precision array.
Output of FIR filter. On entry the array y must have been
initialized, except when beta is zero. In that case, y need
not be initialized. On exit, the result overwrites y.
incy Integer. (input)
Increment between two successive values of y. incy must not be
0.
ldy Integer. (input)
The number of rows in the y array, as it was declared in the
calling program (the leading dimension of y). ldy >= MAX( ny1 *
incy, 1).
i1y0 Integer. (input)
Sample corresponding to the first element of each column of y.
ny1 Integer. (input)
Number of elements in each column of y. ny1 >= 0.
i2y0 Integer. (input)
Index of the first element of each row of y.
ny2 Integer. (input)
Number of elements in each row of y. ny2 >= 0.
alpha Scale factor for the convolution. (input).
CFIR2D: Single precision Complex.
ZFIR2D: Double precision complex.
SFIR2D: Single precision.
DFIR2D: Double precision.
For C/C++, a pointer to this value is passed.
beta Scale factor for the output y. (input)
CFIR1D: Complex.
ZFIR1D: Double complex.
Page 5
CFIR2D(3S)CFIR2D(3S)
SFIR1D: Real.
DFIR1D: Double precision.
When beta is zero, y need not be set on input. For C/C++, a
pointer to this value is passed.
NOTES
The following data types are described in this documentation:
Term Used Data type
Fortran:
Array dimensioned 0..n-1 x(0:n-1)
Array of dimensions (m,n) x(m,n)
Array of dimensions (m,n,p) x(m,n,p)
Integer INTEGER (INTEGER*8 for -lscs_i8[_mp])
Single precision REAL
Double precision DOUBLE PRECISION
Single precision complex COMPLEX
Double precision complex DOUBLE COMPLEX
C/C++:
Array dimensioned 0..n-1 x[n]
Array of dimensions (m,n) x[m*n] or x[n][m]
Array of dimensions (m,n,p) x[m*n*p] or x[p][n][m]
Integer int (long long for -lscs_i8[_mp])
Single precision float
Double precision double
Single precision complex scsl_complex
Double precision complex scsl_zomplex
C++ STL:
Array dimensioned 0..n-1 x[n]
Page 6
CFIR2D(3S)CFIR2D(3S)
Array of dimensions (m,n) x[m*n] or x[n][m]
Array of dimensions (m,n,p) x[m*n*p] or x[p][n][m]
Integer int (long long for -lscs_i8[_mp])
Single precision float
Double precision double
Single precision complex complex<float>
Double precision complex complex<double>
CAUTIONS
The arrays x, h and y must be non-overlapping.
EXAMPLES
The following example computes the convolution of a 4x4-sample array x
with a filter h containing 3x3 samples:
Fortran:
REAL X(0:3,0:3), H(0:2,0:2), Y(0:5,0:5)
REAL ALPHA, BETA
ALPHA = 1.0
BETA = 0.0
DO J = 0, 3
DO I = 0, 3
X(I,J) = -1.0
ENDDO
ENDDO
X(0,0) = 1.0
DO J = 0, 2
DO I = 0, 2
H(i,j) = 1.0/(i+j+1)
ENDDO
ENDDO
CALL SFIR2D(X(0,0), 1, 4, 0, 4, 0, 4,
& H(0,0), 1, 3, 0, 3, 0, 3,
& Y(0,0), 1, 6, 0, 6, 0, 6, ALPHA, BETA)
C/C++:
#include <scsl_fft.h>
float x[4][4], h[3][3], y[6][6];
float alpha = 1.0f;
float beta = 0.0f;
int i, j;
Page 7
CFIR2D(3S)CFIR2D(3S)
for (j=0; j<4; j++) {
for (i=0; i<4; i++) {
x[j][i] = -1.0f;
}
}
x[0][0] = 1.0f;
for (j=0; j<3; j++) {
for (i=0; i<3; i++) {
h[i] = 1.0f/(i+j+1);
}
}
sfir2d((float *) x, 1, 4, 0, 4, 0, 4,
(float *) h, 1, 3, 0, 3, 0, 3,
(float *) y, 1, 6, 0, 6, 0, 6, alpha, beta);
The output is
Y(*,0) Y(*,1) Y(*,2) Y(*,3) Y(*,4) Y(*,5)
Y(0,*) 1.0000 -0.5000-1.1667 -1.8333 -0.8333-0.3333
Y(1,*) -0.5000-1.6667-2.4167 -2.9167 -1.4167-0.5833
Y(2,*) -1.1667-2.4167-3.3000 -3.7000 -1.8667-0.7833
Y(3,*) -1.8333-2.9167-3.7000 -3.7000 -1.8667-0.7833
Y(4,*) -0.8333-1.4167-1.8667 -1.8667 -1.0333-0.4500
Y(5,*) -0.3333-0.5833-0.7833 -0.7833 -0.4500-0.2000
Changing i1x0 to 1 produces the following shift in the output:
Y(*,0) Y(*,1) Y(*,2) Y(*,3) Y(*,4) Y(*,5)
Y(0,*) 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Y(1,*) 1.0000 -0.5000-1.1667 -1.8333 -0.8333-0.3333
Y(2,*) -0.5000-1.6667-2.4167 -2.9167 -1.4167-0.5833
Y(3,*) -1.1667-2.4167-3.3000 -3.7000 -1.8667-0.7833
Y(4,*) -1.8333-2.9167-3.7000 -3.7000 -1.8667-0.7833
Y(5,*) -0.8333-1.4167-1.8667 -1.8667 -1.0333-0.4500
Changing i2h0 to -1 produces the following shift in the output:
Y(*,0) Y(*,1) Y(*,2) Y(*,3) Y(*,4) Y(*,5)
Y(0,*) -0.5000-1.1667-1.8333 -0.8333 -0.3333 0.0000
Y(1,*) -1.6667-2.4167-2.9167 -1.4167 -0.5833 0.0000
Y(2,*) -2.4167-3.3000-3.7000 -1.8667 -0.7833 0.0000
Y(3,*) -2.9167-3.7000-3.7000 -1.8667 -0.7833 0.0000
Y(4,*) -1.4167-1.8667-1.8667 -1.0333 -0.4500 0.0000
Y(5,*) -0.5833-0.7833-0.7833 -0.4500 -0.2000 0.0000
Page 8
CFIR2D(3S)CFIR2D(3S)
Changing i1y0 to +1 and i2y0 to -1 produces the following shift in the
output:
Y(*,0) Y(*,1) Y(*,2) Y(*,3) Y(*,4) Y(*,5)
Y(0,*) 0.0000 -0.5000-1.6667 -2.4167 -2.9167-1.4167
Y(1,*) 0.0000 -1.1667-2.4167 -3.3000 -3.7000-1.8667
Y(2,*) 0.0000 -1.8333-2.9167 -3.7000 -3.7000-1.8667
Y(3,*) 0.0000 -0.8333-1.4167 -1.8667 -1.8667-1.0333
Y(4,*) 0.0000 -0.3333-0.5833 -0.7833 -0.7833-0.4500
Y(5,*) 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
SEE ALSOCFIR1D(3S), CFIRM1D(3S), INTRO_FFT(3S), INTRO_SCSL(3S)
Page 9