Commit b6d847b1 authored by Liam Healy's avatar Liam Healy
Browse files

Define noise tests for all element types

The noise generator make-urand-vector and the noise test, now called
test-fft-noise, now work for all four element types, double-float,
single-float, (complex double-float), (complex single-float).  These
are meant to emulate the noise parts of GSL's test_complex_radix2,
test_real_radix2, test_complex_float_radix2, test_real_float_radix2,
test_complex_float_func, test_complex_func, test_real_float_func, and
test_real_func.  The real tests pass and the complex tests currently
parent d14dc372
;; Example FFT: transform a pulse (using the "clean" fft interface)
;; Sumant Oemrawsingh, Sat Oct 31 2009 - 00:24
;; Time-stamp: <2009-11-09 22:29:03EST example.lisp>
;; Time-stamp: <2009-11-15 23:22:45EST example.lisp>
(in-package :gsl)
;;;; Pulse test
;;; 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
......@@ -16,8 +22,6 @@
;;; program in Section 15.4 of the GSL Manual:
;;; (fft-pulse-test '(complex double-float) 630)
(in-package :gsl)
(defun fft-pulse-test (element-type dimension)
(assert (and (integerp dimension) (> dimension 20)))
(let ((pulse (make-marray element-type :dimensions dimension))
......@@ -39,6 +43,10 @@
(fft-pulse-test 'double-float 128)
(fft-pulse-test 'double-float 630))
;;;; Random vector transformations, from the GSL tests
;; From gsl-1.11/fft/urand.c
(let ((urand-seed 1))
(defun urand ()
......@@ -52,10 +60,14 @@
;; (make-urand-vector '(complex double-float) 5)
(defun make-urand-vector (element-type dimension &key (stride 1))
"Make a vector with random elements."
(let ((vec (make-marray element-type :dimensions (list (* stride dimension)))))
(let ((vec (make-marray `(complex ,(component-float-type element-type))
:dimensions (list (* stride dimension)))))
(loop for i from 0 below (* stride dimension) by stride
(setf (maref vec i) (complex (urand))))
(setf (maref vec i)
(if (subtypep element-type 'complex)
(coerce (complex (urand) (urand)) element-type)
(complex (coerce (urand) element-type)))))
(defun realpart-vector (complex-vector)
......@@ -69,14 +81,20 @@
(realpart (maref complex-vector i))))
(defun test-real-radix2 (element-type size &key (stride 1))
"Test for FFT; returns the DFT answer and the computed FFT answer.
See test_real_radix2 in fft/"
(let ((random-vector (make-urand-vector (list 'complex element-type) size :stride stride)))
(defun test-fft-noise (element-type size &key (stride 1))
"Test for FFT with random data (noise); returns the DFT answer and the computed FFT answer.
See test_real_radix2 etc. in fft/"
(let* ((random-vector (make-urand-vector element-type size :stride stride))
(if (subtypep element-type 'complex)
(realpart-vector random-vector))
:stride stride)))
(forward-discrete-fourier-transform random-vector :stride stride)
(forward-fourier-transform (realpart-vector random-vector) :stride stride)
:unpack-type 'complex :stride stride))))
(if (subtypep element-type 'complex)
(unpack forward :unpack-type 'complex :stride stride)))))
;;(test-real-radix2 'double-float 10 :stride 5)
;;(test-fft-noise 'double-float 10 :stride 5)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment