Skip to content

Commit 99e0f17

Browse files
committed
Original test suite for dcosq.
1 parent 7d39a38 commit 99e0f17

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

test/test_fftpack_original.f90

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ subroutine collect_original(testsuite)
1919
testsuite = [testsuite, new_unittest("zfft", test_zfft)]
2020
testsuite = [testsuite, new_unittest("sint", test_sint)]
2121
testsuite = [testsuite, new_unittest("cost", test_cost)]
22+
testsuite = [testsuite, new_unittest("cosqt", test_cosqt)]
2223
end subroutine collect_original
2324

2425
subroutine test_dfft(error)
@@ -285,6 +286,80 @@ subroutine test_cost(error)
285286
if (allocated(error)) return
286287
end do
287288
end subroutine test_cost
289+
290+
subroutine test_cosqt(error)
291+
type(error_type), allocatable, intent(out) :: error
292+
real(rk) :: x(200), y(200), xh(200), w(2000)
293+
integer :: i, j, k, n, np1, nm1, ns2, nz, modn
294+
real(rk) :: dt, sum1, sum2, arg, arg1
295+
real(rk) :: mismatch, cf
296+
297+
do nz = 1, size(nd)
298+
!> Create multisine signal.
299+
n = nd(nz)
300+
modn = mod(n, 2)
301+
np1 = n + 1; nm1 = n - 1
302+
do j = 1, np1
303+
x(j) = sin(j*sqrt(2.0_rk))
304+
y(j) = x(j)
305+
xh(j) = x(j)
306+
end do
307+
308+
!> Discrete quater-cos transform.
309+
dt = pi/(2*n)
310+
y(:n) = xh(:n)
311+
312+
do i = 1, n
313+
x(i) = 0.0_rk
314+
arg = (i - 1)*dt
315+
do k = 1, n
316+
x(i) = x(i) + y(k)*cos((2*k - 1)*arg)
317+
end do
318+
x(i) = 4*x(i)
319+
end do
320+
321+
!> Fast Quarter-cos Transform.
322+
call dcosqi(n, w)
323+
call dcosqb(n, y, w)
324+
325+
!> Check error.
326+
cf = 0.25_rk/n
327+
mismatch = maxval(abs(x(:n) - y(:n)))*cf
328+
call check(error, mismatch < rtol)
329+
if (allocated(error)) return
330+
331+
!> Discrete inverse quarter-cos transform.
332+
x(:n) = xh(:n)
333+
do i = 1, n
334+
y(i) = 0.5_rk*x(1)
335+
arg = (2*i - 1)*dt
336+
do k = 2, n
337+
y(i) = y(i) + x(k)*cos((k - 1)*arg)
338+
end do
339+
y(i) = 2*y(i)
340+
end do
341+
342+
!> Fast inverse quarter-cos transform.
343+
call dcosqf(n, x, w)
344+
345+
!> Check error.
346+
mismatch = maxval(abs(y(:n) - x(:n)))*cf
347+
print *, "Mismatch :", mismatch, rtol
348+
call check(error, mismatch < rtol)
349+
if (allocated(error)) return
350+
351+
!> Chain direct and inverse quarter-cos transforms.
352+
x(:n) = xh(:n); y(:n) = xh(:n) ! Restore signals.
353+
call dcosqb(n, x, w)
354+
call dcosqf(n, x, w)
355+
356+
!> Check error.
357+
mismatch = maxval(abs(cf*x(:n) - y(:n)))
358+
call check(error, mismatch < rtol)
359+
if (allocated(error)) return
360+
361+
end do
362+
end subroutine test_cosqt
288363
end module test_fftpack_original
289364

290365
program test_original

0 commit comments

Comments
 (0)