1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
SUBROUTINE DF01MD( SICO, N, DT, A, DWORK, INFO )
C
C SLICOT RELEASE 5.0.
C
C Copyright (c) 2002-2009 NICONET e.V.
C
C This program is free software: you can redistribute it and/or
C modify it under the terms of the GNU General Public License as
C published by the Free Software Foundation, either version 2 of
C the License, or (at your option) any later version.
C
C This program is distributed in the hope that it will be useful,
C but WITHOUT ANY WARRANTY; without even the implied warranty of
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
C GNU General Public License for more details.
C
C You should have received a copy of the GNU General Public License
C along with this program. If not, see
C <http://www.gnu.org/licenses/>.
C
C PURPOSE
C
C To compute the sine transform or cosine transform of a real
C signal.
C
C ARGUMENTS
C
C Mode Parameters
C
C SICO CHARACTER*1
C Indicates whether the sine transform or cosine transform
C is to be computed as follows:
C = 'S': The sine transform is computed;
C = 'C': The cosine transform is computed.
C
C Input/Output Parameters
C
C N (input) INTEGER
C The number of samples. N must be a power of 2 plus 1.
C N >= 5.
C
C DT (input) DOUBLE PRECISION
C The sampling time of the signal.
C
C A (input/output) DOUBLE PRECISION array, dimension (N)
C On entry, this array must contain the signal to be
C processed.
C On exit, this array contains either the sine transform, if
C SICO = 'S', or the cosine transform, if SICO = 'C', of the
C given signal.
C
C Workspace
C
C DWORK DOUBLE PRECISION array, dimension (N+1)
C
C Error Indicator
C
C INFO INTEGER
C = 0: successful exit;
C < 0: if INFO = -i, the i-th argument had an illegal
C value.
C
C METHOD
C
C Let A(1), A(2),..., A(N) be a real signal of N samples.
C
C If SICO = 'S', the routine computes the sine transform of A as
C follows. First, transform A(i), i = 1,2,...,N, into the complex
C signal B(i), i = 1,2,...,(N+1)/2, where
C
C B(1) = -2*A(2),
C B(i) = {A(2i-2) - A(2i)} - j*A(2i-1) for i = 2,3,...,(N-1)/2,
C B((N+1)/2) = 2*A(N-1) and j**2 = -1.
C
C Next, perform a discrete inverse Fourier transform on B(i) by
C calling SLICOT Library Routine DG01ND, to give the complex signal
C Z(i), i = 1,2,...,(N-1)/2, from which the real signal C(i) may be
C obtained as follows:
C
C C(2i-1) = Re(Z(i)), C(2i) = Im(Z(i)) for i = 1,2,...,(N-1)/2.
C
C Finally, compute the sine transform coefficients S ,S ,...,S
C 1 2 N
C given by
C
C S = 0,
C 1
C { [C(k) + C(N+1-k)] }
C S = DT*{[C(k) - C(N+1-k)] - -----------------------},
C k { [2*sin(pi*(k-1)/(N-1))]}
C
C for k = 2,3,...,N-1, and
C
C S = 0.
C N
C
C If SICO = 'C', the routine computes the cosine transform of A as
C follows. First, transform A(i), i = 1,2,...,N, into the complex
C signal B(i), i = 1,2,...,(N+1)/2, where
C
C B(1) = 2*A(1),
C B(i) = 2*A(2i-1) + 2*j*{[A(2i-2) - A(2i)]}
C for i = 2,3,...,(N-1)/2 and B((N+1)/2) = 2*A(N).
C
C Next, perform a discrete inverse Fourier transform on B(i) by
C calling SLICOT Library Routine DG01ND, to give the complex signal
C Z(i), i = 1,2,...,(N-1)/2, from which the real signal D(i) may be
C obtained as follows:
C
C D(2i-1) = Re(Z(i)), D(2i) = Im(Z(i)) for i = 1,2,...,(N-1)/2.
C
C Finally, compute the cosine transform coefficients S ,S ,...,S
C 1 2 N
C given by
C
C S = 2*DT*[D(1) + A0],
C 1
C { [D(k) - D(N+1-k)] }
C S = DT*{[D(k) + D(N+1-k)] - -----------------------},
C k { [2*sin(pi*(k-1)/(N-1))]}
C
C
C for k = 2,3,...,N-1, and
C
C S = 2*DT*[D(1) - A0],
C N
C (N-1)/2
C where A0 = 2*SUM A(2i).
C i=1
C
C REFERENCES
C
C [1] Rabiner, L.R. and Rader, C.M.
C Digital Signal Processing.
C IEEE Press, 1972.
C
C [2] Oppenheim, A.V. and Schafer, R.W.
C Discrete-Time Signal Processing.
C Prentice-Hall Signal Processing Series, 1989.
C
C NUMERICAL ASPECTS
C
C The algorithm requires 0( N*log(N) ) operations.
C
C CONTRIBUTORS
C
C Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.
C Supersedes Release 2.0 routine DF01AD by F. Dumortier, and
C R.M.C. Dekeyser, State University of Gent, Belgium.
C
C REVISIONS
C
C V. Sima, Jan. 2003.
C
C KEYWORDS
C
C Digital signal processing, fast Fourier transform, complex
C signals.
C
C ******************************************************************
C
C .. Parameters ..
DOUBLE PRECISION ZERO, ONE, TWO, FOUR
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
$ FOUR = 4.0D0 )
C .. Scalar Arguments ..
CHARACTER SICO
INTEGER INFO, N
DOUBLE PRECISION DT
C .. Array Arguments ..
DOUBLE PRECISION A(*), DWORK(*)
C .. Local Scalars ..
LOGICAL LSICO, LSIG
INTEGER I, I2, IND1, IND2, M, MD2
DOUBLE PRECISION A0, PIBYM, W1, W2, W3
C .. External Functions ..
LOGICAL LSAME
EXTERNAL LSAME
C .. External Subroutines ..
EXTERNAL DG01ND, XERBLA
C .. Intrinsic Functions ..
INTRINSIC ATAN, DBLE, MOD, SIN
C .. Executable Statements ..
C
INFO = 0
LSICO = LSAME( SICO, 'S' )
C
C Test the input scalar arguments.
C
IF( .NOT.LSICO .AND. .NOT.LSAME( SICO, 'C' ) ) THEN
INFO = -1
ELSE
M = 0
IF( N.GT.4 ) THEN
M = N - 1
C WHILE ( MOD( M, 2 ).EQ.0 ) DO
10 CONTINUE
IF ( MOD( M, 2 ).EQ.0 ) THEN
M = M/2
GO TO 10
END IF
C END WHILE 10
END IF
IF ( M.NE.1 ) INFO = -2
END IF
C
IF ( INFO.NE.0 ) THEN
C
C Error return.
C
CALL XERBLA( 'DF01MD', -INFO )
RETURN
END IF
C
C Initialisation.
C
M = N - 1
MD2 = ( N + 1 )/2
PIBYM = FOUR*ATAN( ONE )/DBLE( M )
I2 = 1
DWORK(MD2+1) = ZERO
DWORK(2*MD2) = ZERO
C
IF ( LSICO ) THEN
C
C Sine transform.
C
LSIG = .TRUE.
DWORK(1) = -TWO*A(2)
DWORK(MD2) = TWO*A(M)
C
DO 20 I = 4, M, 2
I2 = I2 + 1
DWORK(I2) = A(I-2) - A(I)
DWORK(MD2+I2) = -A(I-1)
20 CONTINUE
C
ELSE
C
C Cosine transform.
C
LSIG = .FALSE.
DWORK(1) = TWO*A(1)
DWORK(MD2) = TWO*A(N)
A0 = A(2)
C
DO 30 I = 4, M, 2
I2 = I2 + 1
DWORK(I2) = TWO*A(I-1)
DWORK(MD2+I2) = TWO*( A(I-2) - A(I) )
A0 = A0 + A(I)
30 CONTINUE
C
A0 = TWO*A0
END IF
C
C Inverse Fourier transform.
C
CALL DG01ND( 'Inverse', MD2-1, DWORK(1), DWORK(MD2+1), INFO )
C
C Sine or cosine coefficients.
C
IF ( LSICO ) THEN
A(1) = ZERO
A(N) = ZERO
ELSE
A(1) = TWO*DT*( DWORK(1) + A0 )
A(N) = TWO*DT*( DWORK(1) - A0 )
END IF
C
IND1 = MD2 + 1
IND2 = N
C
DO 40 I = 1, M - 1, 2
W1 = DWORK(IND1)
W2 = DWORK(IND2)
IF ( LSIG ) W2 = -W2
W3 = TWO*SIN( PIBYM*DBLE( I ) )
A(I+1) = DT*( W1 + W2 - ( W1 - W2 )/W3 )
IND1 = IND1 + 1
IND2 = IND2 - 1
40 CONTINUE
C
IND1 = 2
IND2 = MD2 - 1
C
DO 50 I = 2, M - 2, 2
W1 = DWORK(IND1)
W2 = DWORK(IND2)
IF ( LSIG ) W2 = -W2
W3 = TWO*SIN( PIBYM*DBLE( I ) )
A(I+1) = DT*( W1 + W2 - ( W1 - W2 )/W3 )
IND1 = IND1 + 1
IND2 = IND2 - 1
50 CONTINUE
C
RETURN
C *** Last line of DF01MD ***
END
|