;;; Lisplab, level3-fft-generic.lisp ;;; Simple converters is the to the methods that do calculations ;;; Copyright (C) 2009 Joern Inge Vestgaarden ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License along ;;; with this program; if not, write to the Free Software Foundation, Inc., ;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. (in-package :lisplab) (defun convert-to-matrix-zge (m) (let ((m-copy (mcreate* m :element-type :z))) (copy-contents m m-copy) m-copy)) ;;;; Real matrices (defmethod fft1 ((x matrix-base-dge) &key) (fft1! (convert-to-matrix-zge x))) (defmethod ifft1 ((x matrix-base-dge) &key) (ifft1! (convert-to-matrix-zge x))) (defmethod ifft2 ((x matrix-base-dge) &key) (ifft2! (convert-to-matrix-zge x))) (defmethod fft2 ((x matrix-base-dge) &key) (fft2! (convert-to-matrix-zge x))) ;;; Complex matrices (defmethod fft1 ((x matrix-base-zge) &key) (fft1! (copy x))) (defmethod ifft1 ((x matrix-base-zge) &key) (ifft1! (copy x))) (defmethod ifft2 ((x matrix-base-zge) &key) (ifft2! (copy x))) (defmethod fft2 ((x matrix-base-zge) &key) (fft2! (copy x))) (defmethod fft-shift ((m matrix-base)) (let* ((rows (rows m)) (fr (floor rows 2)) (cr (ceiling rows 2)) (cols (cols m)) (fc (floor cols 2)) (cc (ceiling cols 2))) (fmat (type-of m) (list rows cols) (lambda (i j) (mref m (if (< i fr) (+ i cr) (- i fr)) (if (< j fc) (+ j cc) (- j fc))))))) (defmethod ifft-shift ((m matrix-base)) (let* ((rows (rows m)) (fr (floor rows 2)) (cr (ceiling rows 2)) (cols (cols m)) (fc (floor cols 2)) (cc (ceiling cols 2))) (fmat (type-of m) (list rows cols) (lambda (i j) (mref m (if (< i cr) (+ i fr) (- i cr)) (if (< j cc) (+ j fc) (- j cc)))))))