Skip to content

Commit 45161fd

Browse files
committed
add (i)dct/dcosti/dcost interfaces.
1 parent ac5fecf commit 45161fd

File tree

10 files changed

+401
-14
lines changed

10 files changed

+401
-14
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# FFTPACK
2+
3+
[![Actions Status](https://github.com/fortran-lang/fftpack/workflows/fpm/badge.svg)](https://github.com/fortran-lang/fftpack/actions)
4+
25
A package of fortran subprograms for the fast fourier transform of periodic and other symmetric sequences.
36

47
## Getting started

doc/specs/fftpack.md

Lines changed: 221 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Experimental.
2121

2222
#### Class
2323

24-
Pure function.
24+
Pure subroutine.
2525

2626
#### Syntax
2727

@@ -73,7 +73,7 @@ Experimental.
7373

7474
#### Class
7575

76-
Pure function.
76+
Pure subroutine.
7777

7878
#### Syntax
7979

@@ -143,7 +143,7 @@ Experimental.
143143

144144
#### Class
145145

146-
Pure function.
146+
Pure subroutine.
147147

148148
#### Syntax
149149

@@ -296,7 +296,7 @@ Experimental.
296296

297297
#### Class
298298

299-
Pure function.
299+
Pure subroutine.
300300

301301
#### Syntax
302302

@@ -346,7 +346,7 @@ Experimental.
346346

347347
#### Class
348348

349-
Pure function.
349+
Pure subroutine.
350350

351351
#### Syntax
352352

@@ -428,7 +428,7 @@ Experimental.
428428

429429
#### Class
430430

431-
Pure function.
431+
Pure subroutine.
432432

433433
#### Syntax
434434

@@ -638,7 +638,7 @@ Experimental
638638

639639
#### Class
640640

641-
Pure function.
641+
Pure subroutine.
642642

643643
#### Syntax
644644

@@ -712,7 +712,7 @@ Experimental
712712

713713
#### Class
714714

715-
Pure function.
715+
Pure subroutine.
716716

717717
#### Syntax
718718

@@ -824,7 +824,7 @@ Experimental
824824

825825
#### Class
826826

827-
Pure function.
827+
Pure subroutine.
828828

829829
#### Syntax
830830

@@ -873,7 +873,7 @@ Experimental
873873

874874
#### Class
875875

876-
Pure function.
876+
Pure subroutine.
877877

878878
#### Syntax
879879

@@ -943,7 +943,7 @@ Experimental
943943

944944
#### Class
945945

946-
Pure function.
946+
Pure subroutine.
947947

948948
#### Syntax
949949

@@ -1087,6 +1087,216 @@ program demo_iqct
10871087
end program demo_iqct
10881088
```
10891089

1090+
## Cosine transform of a real even sequence
1091+
1092+
### `dcosti`
1093+
1094+
#### Description
1095+
1096+
Initializes the array `wsave` which is used in subroutine `dcost`.
1097+
The prime factorization of `n` together with a tabulation of the trigonometric functions are computed and stored in `wsave`.
1098+
1099+
#### Status
1100+
1101+
Experimental
1102+
1103+
#### Class
1104+
1105+
Pure subroutine.
1106+
1107+
#### Syntax
1108+
1109+
`call [[fftpack(module):dcosti(interface)]](n , wsave)`
1110+
1111+
#### Arguments
1112+
1113+
`n`: Shall be a `integer` scalar.
1114+
This argument is `intent(in)`.
1115+
The length of the sequence to be transformed.
1116+
The method is most efficient when n-1 is a product of small primes.
1117+
1118+
`wsave`: Shall be a `real` and rank-1 array.
1119+
This argument is `intent(out)`.
1120+
A work array which must be dimensioned at least `3*n+15`.
1121+
Different `wsave` arrays are required for different values of `n`.
1122+
The contents of `wsave` must not be changed between calls of `dcost`.
1123+
1124+
#### Example
1125+
1126+
```fortran
1127+
program demo_dcosti
1128+
use fftpack, only: dcosti
1129+
real(kind=8) :: w(3*4 + 15)
1130+
call dcosti(4, w) !! Initializes the array `w` which is used in subroutine `dcost`.
1131+
end program demo_dcosti
1132+
```
1133+
1134+
### `dcost`
1135+
1136+
#### Description
1137+
1138+
Computes the discrete fourier cosine transform of an even sequence `x(i)`.
1139+
The transform is defined below at output parameter `x`.
1140+
1141+
`dcost` is the unnormalized inverse of itself since a call of `dcost` followed by another call of `dcost` will multiply the input sequence `x` by `2*(n-1)`.
1142+
The transform is defined below at output parameter `x`.
1143+
1144+
The array `wsave` which is used by subroutine `dcost` must be initialized by calling subroutine `dcosti(n,wsave)`.
1145+
1146+
#### Status
1147+
1148+
Experimental
1149+
1150+
#### Class
1151+
1152+
Pure subroutine.
1153+
1154+
#### Syntax
1155+
1156+
`call [[fftpack(module):dcost(interface)]](n, x, wsave)`
1157+
1158+
#### Arguments
1159+
1160+
`n`: Shall be a `integer` scalar.
1161+
This argument is `intent(in)`.
1162+
The length of the sequence `x`.
1163+
`n` must be greater than `1`.
1164+
The method is most efficient when `n-1` is a product of small primes.
1165+
1166+
`x`: Shall be a `real` and rank-1 array.
1167+
This argument is `intent(inout)`.
1168+
An array which contains the sequence to be transformed.
1169+
```
1170+
for i=1,...,n
1171+
1172+
x(i) = x(1)+(-1)**(i-1)*x(n)
1173+
1174+
+ the sum from k=2 to k=n-1
1175+
1176+
2*x(k)*cos((k-1)*(i-1)*pi/(n-1))
1177+
1178+
a call of dcost followed by another call of
1179+
dcost will multiply the sequence x by 2*(n-1)
1180+
hence dcost is the unnormalized inverse
1181+
of itself.
1182+
```
1183+
1184+
`wsave`: Shall be a `real` and rank-1 array.
1185+
This argument is `intent(in)`.
1186+
A work array which must be dimensioned at least `3*n+15` in the program that calls `dcost`.
1187+
The `wsave` array must be initialized by calling subroutine `dcosti(n,wsave)` and a different `wsave` array must be used for each different value of `n`.
1188+
This initialization does not have to be repeated so long as `n` remains unchanged thus subsequent
1189+
transforms can be obtained faster than the first.
1190+
Contains initialization calculations which must not be destroyed between calls of `dcost`.
1191+
1192+
#### Example
1193+
1194+
```fortran
1195+
program demo_dcost
1196+
use fftpack, only: dcosti, dcost
1197+
real(kind=8) :: x(4) = [1, 2, 3, 4]
1198+
real(kind=8) :: w(3*4 + 15)
1199+
call dcosti(4, w)
1200+
call dcost(4, x, w) !! Computes the discrete fourier cosine (forward) transform of an even sequence, `x`(unnormalized): [15.0, -4.0, 0.0, -1.0]
1201+
call dcost(4, x, w) !! Computes the discrete fourier cosine (backward) transform of an even sequence, `x`(unnormalized): [6.0, 12.0, 18.0, 24.0]
1202+
end program demo_dcost
1203+
```
1204+
1205+
### `dct`
1206+
1207+
#### Description
1208+
1209+
Discrete fourier cosine (forward) transform of an even sequence.
1210+
1211+
#### Status
1212+
1213+
Experimental.
1214+
1215+
#### Class
1216+
1217+
Pure function.
1218+
1219+
#### Syntax
1220+
1221+
`result = [[fftpack(module):dct(interface)]](x [, n])`
1222+
1223+
#### Argument
1224+
1225+
`x`: Shall be a `real` and rank-1 array.
1226+
This argument is `intent(in)`.
1227+
The data to transform.
1228+
1229+
`n`: Shall be an `integer` scalar.
1230+
This argument is `intent(in)` and `optional`.
1231+
Defines the length of the Fourier transform. If `n` is not specified (the default) then `n = size(x)`. If `n <= size(x)`, `x` is truncated, if `n > size(x)`, `x` is zero-padded.
1232+
1233+
#### Return value
1234+
1235+
Returns a `real` and rank-1 array, the Discrete-Cosine Transform (DCT) of `x`.
1236+
1237+
#### Notes
1238+
1239+
Within numerical accuracy, `y == dct(idct(y))/2*(size(y) - 1)`.
1240+
1241+
#### Example
1242+
1243+
```fortran
1244+
program demo_dct
1245+
use fftpack, only: dct
1246+
real(kind=8) :: x(4) = [1, 2, 3, 4]
1247+
print *, dct(x,3) !! [8.0, -2.0, 0.0].
1248+
print *, dct(x) !! [15.0, -4.0, 0.0, -1.0].
1249+
print *, dct(x,5) !! [19.0, -1.8, -5.0, 3.8, -5.0].
1250+
print *, dct(dct(x))/(2*(4 - 1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1251+
end program demo_dct
1252+
```
1253+
1254+
### `idct`
1255+
1256+
#### Description
1257+
1258+
Unnormalized inverse of `dct`.
1259+
In fact, `idct` and `dct` have the same effect, `idct` = `dct`.
1260+
1261+
#### Status
1262+
1263+
Experimental.
1264+
1265+
#### Class
1266+
1267+
Pure function.
1268+
1269+
#### Syntax
1270+
1271+
`result = [[fftpack(module):idct(interface)]](x [, n])`
1272+
1273+
#### Argument
1274+
1275+
`x`: Shall be a `real` array.
1276+
This argument is `intent(in)`.
1277+
Transformed data to invert.
1278+
1279+
`n`: Shall be an `integer` scalar.
1280+
This argument is `intent(in)` and `optional`.
1281+
Defines the length of the Fourier transform. If `n` is not specified (the default) then `n = size(x)`. If `n <= size(x)`, `x` is truncated, if `n > size(x)`, `x` is zero-padded.
1282+
1283+
#### Return value
1284+
1285+
Returns a `real` and rank-1 array, the inverse Discrete-Cosine Transform (iDCT) of `x`.
1286+
1287+
#### Example
1288+
1289+
```fortran
1290+
program demo_idct
1291+
use fftpack, only: dct, idct
1292+
real(kind=8) :: x(4) = [1, 2, 3, 4]
1293+
print *, idct(dct(x))/(2*(4-1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1294+
print *, idct(idct(x))/(2*(4-1)) !! (normalized): [1.0, 2.0, 3.0, 4.0]
1295+
print *, idct(dct(x), 3) !! (unnormalized): [7.0, 15.0, 23.0]
1296+
end program demo_idct
1297+
```
1298+
1299+
10901300
## Utility functions
10911301

10921302
### `fftshift`

fpm.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ name = "fftpack_iqct"
7272
source-dir = "test"
7373
main = "test_fftpack_iqct.f90"
7474

75+
[[test]]
76+
name = "fftpack_dcost"
77+
source-dir = "test"
78+
main = "test_fftpack_dcost.f90"
79+
80+
[[test]]
81+
name = "fftpack_dct"
82+
source-dir = "test"
83+
main = "test_fftpack_dct.f90"
84+
7585
# `fftpack` utility routines
7686
[[test]]
7787
name = "fftpack_fftshift"

src/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ SRCF90 = \
5858
fftpack_fftshift.f90\
5959
fftpack_ifftshift.f90\
6060
fftpack_qct.f90\
61-
fftpack_iqct.f90
61+
fftpack_iqct.f90\
62+
fftpack_dct.f90
6263

6364
OBJF := $(SRCF:.f=.o)
6465
OBJF90 := $(SRCF90:.f90=.o)
@@ -81,5 +82,6 @@ fftpack_rfft.o: fftpack.o
8182
fftpack_irfft.o: fftpack.o
8283
fftpack_qct.o: fftpack.o
8384
fftpack_iqct.o: fftpack.o
85+
fftpack_dct.o: fftpack.o
8486
fftpack_fftshift.o: fftpack.o
8587
fftpack_ifftshift.o: fftpack.o

0 commit comments

Comments
 (0)