NAME zcnvcor - compute the convolution or correlation of double precision complex vectors SUBROUTINE ZCNVCOR (CNVCOR, FOUR, NX, X, IFX, INCX, NY, NPRE, M, Y, IFY, INC1Y, INC2Y, NZ, K, Z, IFZ, INC1Z, INC2Z, WORK, LWORK) CHARACTER CNVCOR, FOUR INTEGER IFX, IFY, IFZ, INCX, INC1Y, INC2Y, INC1Z, INC2Z, K, LWORK, NPRE, NX, NY, M, NZ DOUBLE COMPLEX X(*), Y(*), Z(*) DOUBLE COMPLEX WORK(*) #include <sunperf.h> void zcnvcor(char cnvcor, char four, int nx, doublecomplex *x, int ifx, int incx, int ny, int npre, int m, doublecomplex *y, int ify, int inc1y, int inc2y, int nz, int k, doublecomplex *z, int ifz, int inc1z, int inc2z, doublecomplex *work, int lwork); PURPOSE ZCNVCOR computes the convolution or correlation of double precision complex vectors. ARGUMENTS CNVCOR (input) CHARACTER 'V' or 'v' if convolution is desired, 'R' or 'r' or correlation is desired. FOUR (input) CHARACTER 'T' or 't' if the Fourier transform method is to be used, 'D' or 'd' if the computation should be done directly from the definition. The Fourier transform method is generally faster, but it may introduce noticeable errors into certain results, notably when both the real and imaginary parts of the filter and data vectors consist entirely of integers or vectors where elements of either the filter vector or a given data vector differ signi- ficantly in magnitude from the 1-norm of the vec- tor. NX (input) INTEGER Length of the filter vector. NX >= 0. ZCNVCOR will return immediately if NX = 0. X (input) DOUBLE COMPLEX(*) Filter vector. IFX (input) DOUBLE COMPLEX(*) Index of the first element of X. NX >= IFX >= 1. INCX (input) INTEGER Stride between elements of the filter vector in X. INCX > 0. NY (input) INTEGER Length of the input vectors. NY >= 0. ZCNVCOR will return immediately if NY = 0. NPRE (input) INTEGER The number of implicit zeros prepended to the Y vectors. NPRE >= 0. Y (input) DOUBLE COMPLEX(*) Input vectors. IFY (input) DOUBLE COMPLEX(*) Index of the first element of Y. NY >= IFY >= 1. INC1Y (input) INTEGER Stride between elements of the input vectors in Y. INC1Y > 0. INC2Y (input) INTEGER Stride between the input vectors in Y. INC2Y > 0. NZ (input) INTEGER Length of the output vectors. NZ >= 0. ZCNVCOR will return immediately if NZ = 0. See the Notes section below for information about how this argu- ment interacts with NX and NY to control circular versus end-off shifting. K (input) INTEGER Number of Z vectors. K >= 0. If K = 0 then ZCNVCOR will return immediately. If K < M then only the first K input vectors will be processed. If K > M then all input vectors will be processed and the last M-K output vectors will be set to zero on exit. Z (output) DOUBLE COMPLEX(*) Result vectors. IFZ (input) DOUBLE COMPLEX(*) Index of the first element of Z. NZ >= IFZ >= 1. INC1Z (input) INTEGER Stride between elements of the output vectors in Z. INC1Z > 0. INC2Z (input) INTEGER Stride between the output vectors in Z. INC2Z > 0. WORK (input/scratch) DOUBLE COMPLEX(LWORK) Scratch space. Before the first call to ZCNVCOR with particular values of the integer arguments the first element of WORK must be set to zero. If WORK is written between calls to ZCNVCOR or if ZCNVCOR is called with different values of the integer arguments then the first element of WORK must again be set to zero before each call. If WORK has not been written and the same values of the integer arguments are used then the first ele- ment of WORK to zero. This can avoid certain ini- tializations that store their results into WORK, and avoiding the initialization can make ZCNVCOR run faster. LWORK (input) INTEGER Length of WORK. LWORK >= 2*MAX(NX,NY,NZ)+8. NOTES If any vector overlaps a writable vector, either because of argument aliasing or ill-chosen values of the various INC arguments, the results are undefined and may vary from one run to the next. The most common form of the computation, and the case that executes fastest, is applying a filter vector X to a series of vectors stored in the columns of Y with the result placed into the columns of Z. In that case, INCX = 1, INC1Y = 1, INC2Y >= NY, INC1Z = 1, INC2Z >= NZ. Another common form is applying a filter vector X to a series of vectors stored in the rows of Y and store the result in the row of Z, in which case INCX = 1, INC1Y >= NY, INC2Y = 1, INC1Z >= NZ, and INC2Z = 1. A common use of convolution is to compute the products of polynomials. The following code uses SCNVCOR to compute the product of 1 + 2x + 3x**2 and 4 + 5x + 6x**2: PROGRAM TEST IMPLICIT NONE C INTEGER LWORK, NX, NY, NZ PARAMETER (NX = 3) PARAMETER (NY = NX) PARAMETER (NZ = 2*NY-1) PARAMETER (LWORK = 4*NZ+32) C REAL X(NX), Y(NY), Z(NZ), WORK(LWORK) C DATA X / 1, 2, 3 /, Y / 4, 5, 6 /, WORK / LWORK*0 / C PRINT 1000, 'X' PRINT 1010, X PRINT 1000, 'Y' PRINT 1010, Y CALL SCNVCOR ('V', 'T', NX, X, 1, 1, $ NY, 0, 1, Y, 1, 1, 1, $ NZ, 1, Z, 1, 1, 1, WORK, LWORK) PRINT 1020, 'Z' PRINT 1010, Z C 1000 FORMAT (1X, 'Input vector ', A1) 1010 FORMAT (1X, 300F5.0) 1020 FORMAT (1X, 'Output vector ', A1) C END The program above produces the following output: Input vector X 1. 2. 3. Input vector Y 4. 5. 6. Output vector Z 4. 13. 28. 27. 18. Making the output vector longer than the input vectors, as in the example above, implicitly adds zeros to the end of the input. No zeros are actually required in any of the vectors, and none are used in the example, but the padding provided by the implied zeros has the effect of an end-off shift rather than an end-around shift of the input vectors. The following code will compute the product between the vec- tor [ 1, 2, 3 ] and the circulant matrix defined by the initial column vector [ 4, 5, 6 ]: PROGRAM TEST IMPLICIT NONE C INTEGER LWORK, NX, NY, NZ PARAMETER (NX = 3) PARAMETER (NY = NX) PARAMETER (NZ = NY) PARAMETER (LWORK = 4*NZ+32) C REAL X(NX), Y(NY), Z(NZ), WORK(LWORK) C DATA X / 1, 2, 3 /, Y / 4, 5, 6 /, WORK / LWORK*0 / C PRINT 1000, 'X' PRINT 1010, X PRINT 1000, 'Y' PRINT 1010, Y CALL SCNVCOR ('V', 'T', NX, X, 1, 1, $ NY, 0, 1, Y, 1, 1, 1, $ NZ, 1, Z, 1, 1, 1, WORK, LWORK) PRINT 1020, 'Z' PRINT 1010, Z C 1000 FORMAT (1X, 'Input vector ', A1) 1010 FORMAT (1X, 300F5.0) 1020 FORMAT (1X, 'Output vector ', A1) C END The program above produces the following output: Input vector X 1. 2. 3. Input vector Y 4. 5. 6. Output vector Z 31. 31. 28. The difference between this example and the previous example is that the length of the output vector is the same as the length of the input vectors, so there are no implied zeros on the end. With no implied zeros to shift into, the effect of an end-off shift from the previous example does not occur and the end-around shift results in a circulant matrix pro- duct.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |