File: CFFTW3.cpp

package info (click to toggle)
fmit 1.3.2-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,356 kB
  • sloc: cpp: 9,515; sh: 69; makefile: 12
file content (68 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "CFFTW3.h"

#include <assert.h>
using namespace std;
#include <CppAddons/CAMath.h>
using namespace Math;

CFFTW3::CFFTW3(bool forward)
{
	m_size = 0;
	m_out = m_in = NULL;
	m_plan = NULL;
	m_forward = forward;
}
CFFTW3::CFFTW3(int n)
{
	resize(n);
}
void CFFTW3::resize(int n)
{
	assert(n>0);

	m_size = n;

	m_out = m_in = NULL;

	m_in = new fftw_complex[m_size];
	m_out = new fftw_complex[m_size];
	in.resize(m_size);
	out.resize(m_size);

	//  | FFTW_PRESERVE_INPUT
	if(m_forward)
		m_plan = fftw_plan_dft_1d(m_size, m_in, m_out, FFTW_FORWARD, FFTW_MEASURE);
	else
		m_plan = fftw_plan_dft_1d(m_size, m_in, m_out, FFTW_BACKWARD, FFTW_MEASURE);
}

void CFFTW3::execute()
{
	execute(in, out);
}

void CFFTW3::execute(const vector<double>& in, vector<std::complex<double> >& out)
{
	assert(int(in.size())>=m_size);

	for(int i=0; i<m_size; i++)
	{
		m_in[i][0] = in[i];
		m_in[i][1] = 0.0;
	}

	fftw_execute(m_plan);

	if(int(out.size())<m_size)
		out.resize(m_size);

	for(int i=0; i<m_size; i++)
		out[i] = make_complex(m_out[i]);
}

CFFTW3::~CFFTW3()
{
	if(m_plan)	fftw_destroy_plan(m_plan);
	if(m_in)	delete[] m_in;
	if(m_out)	delete[] m_out;
}