-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfft.cpp
More file actions
50 lines (42 loc) · 873 Bytes
/
fft.cpp
File metadata and controls
50 lines (42 loc) · 873 Bytes
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
#include "fft.h"
#include <math.h>
fft::fft()
{
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * fftN);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * fftN);
for(int i=0; i < fftN; i++)
{
in[i][0] = 0;
in[i][1] = 0;
out[i][0] = 0;
out[i][1] = 0;
}
plan = fftw_plan_dft_1d(fftN, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
}
fft::~fft()
{
fftw_destroy_plan(plan);
fftw_free(in);
fftw_free(out);
}
//methods
void fft::take_input(float *buffer, int buffer_size)
{
if(buffer_size > fftN)
return;
for(int i = 0; i < buffer_size; i++)
{
in[i][0] = buffer[i];
}
}
void fft::execute()
{
fftw_execute(plan);
}
void fft::compute_powers()
{
for(int i = 0; i < fftN/2; i++)
{
powers[i] = sqrt(out[i][0]*out[i][0] + out[i][1]*out[i][1]);
}
}