3 * Copyright 2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <gcell/gcp_fft_1d_r2.h>
30 init_jd(gc_job_desc *jd,
32 unsigned log2_fft_length,
34 std::complex<float> *out,
35 const std::complex<float> *in,
36 const std::complex<float> *twiddle,
39 jd->proc_id = proc_id;
44 jd->input.arg[0].u32 = log2_fft_length;
45 jd->input.arg[1].u32 = shift;
46 unsigned int fft_length = 1 << log2_fft_length;
48 jd->eaa.arg[0].ea_addr = ptr_to_ea(out);
49 jd->eaa.arg[0].direction = GCJD_DMA_PUT;
50 jd->eaa.arg[0].put_size = sizeof(std::complex<float>) * fft_length;
52 jd->eaa.arg[1].ea_addr = ptr_to_ea(const_cast<std::complex<float>*>(in));
53 jd->eaa.arg[1].direction = GCJD_DMA_GET;
54 jd->eaa.arg[1].get_size = sizeof(std::complex<float>) * fft_length;
56 jd->eaa.arg[2].ea_addr = ptr_to_ea(const_cast<std::complex<float>*>(twiddle));
57 jd->eaa.arg[2].direction = GCJD_DMA_GET;
58 jd->eaa.arg[2].get_size = sizeof(std::complex<float>) * fft_length / 4;
60 jd->eaa.arg[3].ea_addr = ptr_to_ea(const_cast<float*>(window));
61 jd->eaa.arg[3].direction = GCJD_DMA_GET;
63 jd->eaa.arg[3].get_size = 0;
65 jd->eaa.arg[3].get_size = sizeof(float) * fft_length;
70 gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr,
71 unsigned int log2_fft_length,
74 std::complex<float> *out,
75 const std::complex<float> *in,
76 const std::complex<float> *twiddle,
79 unsigned int fft_length = 1 << log2_fft_length;
80 if (fft_length > 4096)
81 throw std::invalid_argument("fft_length > 4096");
83 if ((intptr_t)out & 0xf)
84 throw gc_bad_align("out");
85 if ((intptr_t)in & 0xf)
86 throw gc_bad_align("in");
87 if ((intptr_t)twiddle & 0xf)
88 throw gc_bad_align("twiddle");
89 if ((intptr_t)window & 0xf)
90 throw gc_bad_align("window");
92 std::string proc_name;
94 proc_name = "fwd_fft_1d_r2";
96 proc_name = "inv_fft_1d_r2";
98 gc_proc_id_t fft_id = mgr->lookup_proc(proc_name);
99 gc_job_desc_sptr jd = gc_job_manager::alloc_job_desc(mgr);
100 init_jd(jd.get(), fft_id, log2_fft_length, shift, out, in, twiddle, window);
101 if (!mgr->submit_job(jd.get())){
102 gc_job_status_t s = jd->status;
103 throw gc_bad_submit(proc_name, s);
109 gcp_fft_1d_r2_twiddle(unsigned int log2_fft_length, std::complex<float> *twiddle)
111 unsigned int n = 1 << log2_fft_length;
113 twiddle[0].real() = 1.0;
114 twiddle[0].imag() = 0.0;
115 for (unsigned i=1; i < n/4; i++){
116 twiddle[i].real() = cos(i * 2*M_PI/n);
117 twiddle[n/4 - i].imag() = -twiddle[i].real();