From 1477c1a49291d7a9670c3d3f8858f3a9c62ab796 Mon Sep 17 00:00:00 2001 From: Liam Healy <liam@thinkpad.local> Date: Sun, 8 Nov 2009 21:16:05 -0500 Subject: [PATCH] GSL test test-real-radix2 working The first of the GSL tests has been ported to GSLL as test-real-radix2. Currently it doesn't do a comparison, just returns both the answer from the DFT and from the FFT. Also, stride=1 here. --- fast-fourier-transforms/example.lisp | 42 +++++++++++++++++++++++++++- fast-fourier-transforms/unpack.lisp | 2 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/fast-fourier-transforms/example.lisp b/fast-fourier-transforms/example.lisp index ea5371b0..dc69d855 100644 --- a/fast-fourier-transforms/example.lisp +++ b/fast-fourier-transforms/example.lisp @@ -1,6 +1,6 @@ ;; Example FFT: transform a pulse (using the "clean" fft interface) ;; Sumant Oemrawsingh, Sat Oct 31 2009 - 00:24 -;; Time-stamp: <2009-11-01 23:04:58EST fft-interface-example.lisp> +;; Time-stamp: <2009-11-08 21:13:33EST example.lisp> ;;; Here is an example program modelled after the example given in Section ;;; 15.3 of the GSL Manual, which computes the FFT of a short pulse. To make @@ -38,3 +38,43 @@ (fft-pulse-test 'single-float 630) (fft-pulse-test 'double-float 128) (fft-pulse-test 'double-float 630)) + +;; From gsl-1.11/fft/urand.c +(let ((urand-seed 1)) + (defun urand () + "Generate a random number. See fft/urand.c." + (setf urand-seed (logand #x7fffffff (+ 12345 (* urand-seed 1103515245)))) + (/ urand-seed 2147483648.d0)) + (defun reset-urand () + (setf urand-seed 1) + (values))) + +;; (make-urand-vector '(complex double-float) 5) +(defun make-urand-vector (element-type dimension) + "Make a vector with random elements." + (let ((vec (make-marray element-type :dimensions (list dimension)))) + (loop for i from 0 below dimension + do + (setf (maref vec i) (complex (urand)))) + vec)) + +(defun fft-signal-real-noise (element-type size) + "From generated random data, return the data and DFT. + See fft_signal_real_noise in fft/signals.mc." + (let ((data (make-urand-vector (list 'complex element-type) size))) + (values data (forward-discrete-fourier-transform data)))) + +(defun test-real-radix2 (element-type size) + "Test for FFT; returns the DFT answer and the computed FFT answer. + See test_real_radix2 in fft/test.mc." + (multiple-value-bind (complex-vector dft-answer) + (fft-signal-real-noise element-type size) ; results are complex + (let ((real-vector + (make-marray element-type :dimensions (list (* 2 size))))) + (loop for i below (total-size real-vector) do + (setf (maref real-vector i) + (if (evenp i) + (realpart (maref complex-vector (floor i 2))) + (coerce 0 element-type)))) + (let ((forward-fft (forward-fourier-transform real-vector))) + (values dft-answer (unpack forward-fft :unpack-type 'complex)))))) diff --git a/fast-fourier-transforms/unpack.lisp b/fast-fourier-transforms/unpack.lisp index 2ac7d925..c1dafea7 100644 --- a/fast-fourier-transforms/unpack.lisp +++ b/fast-fourier-transforms/unpack.lisp @@ -1,6 +1,6 @@ ;; Unpack functions for FFT vectors. ;; Sumant Oemrawsingh, Sun Oct 25 2009 - 16:35 -;; Time-stamp: <2009-11-03 23:20:35EST unpack.lisp> +;; Time-stamp: <2009-11-08 21:10:27EST unpack.lisp> (in-package :gsl) -- GitLab