-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfft.h
More file actions
44 lines (32 loc) · 1.59 KB
/
Copy pathfft.h
File metadata and controls
44 lines (32 loc) · 1.59 KB
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
#ifndef _FFT_INCLUDED
#define _FFT_INCLUDED
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#if FFT_USE_32_BIT
#define FFT_FLOAT_TYPE float
#else
#define FFT_FLOAT_TYPE double
#endif
typedef struct FFT_ComplexNumber { FFT_FLOAT_TYPE x,y; } fft_complex;
//for all FFT functions, src and dest must point to different places in memory
//the input and output will be complex numbers (2D vector arrays) with the type "fft_complex"
//size will be the same in every axis and for both src and dest. It must also be a power of 2
//inverse is a boolean for whether to do the inverse transform
void FFT(void *src, void *dest, uint32_t size, uint32_t inverse);
//src and dest must have a length of size*size
void FFT_2D(void *src, void *dest, uint32_t size, uint32_t inverse);
//because signals have a limited sampling rate, to reproduce a given frequency, you need at least
//twice as many samples. Since the FT is the same size as the input, its other half will therefore
//be a mirrored version of the first half since those frequencies cannot be represented.
//simply put, these functions mirror your FFT so that the 0th frequency is at index [size/2]
//remember to undo this if you then want to take the inverse FFT
void FFT_MIRROR(void *ft, uint32_t size);
void FFT_MIRROR_2D(void *ft, uint32_t size);
//takes in your transform and gets the amplitude of every frequency and writes it to amp
//it is expected that amp is of type FFT_FLOAT_TYPE
void FFT_AMPLITUDE(void *ft, void *amp, uint32_t size);
inline void FFT_AMPLITUDE_2D(void *ft, void *amp, uint32_t size) {
FFT_AMPLITUDE(ft, amp, size*size);
}
#endif