Skip to content
Snippets Groups Projects
Commit 1477c1a4 authored by Liam Healy's avatar Liam Healy
Browse files

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.
parent 1dc7b6ca
No related branches found
No related tags found
No related merge requests found
;; 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))))))
;; 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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment