-
Notifications
You must be signed in to change notification settings - Fork 25
/
fft.h
147 lines (133 loc) · 4.42 KB
/
fft.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* header file for fft.c --
* FFT subroutine for WaoN with FFTW library
* Copyright (C) 1998-2013 Kengo Ichiki <[email protected]>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _FFT_H_
#define _FFT_H_
double parzen (int i, int nn);
double welch (int i, int nn);
double hanning (int i, int nn);
double hamming (int i, int nn);
double blackman (int i, int nn);
double steeper (int i, int nn);
/* apply window function to data[]
* INPUT
* flag_window : 0 : no-window (default -- that is, other than 1 ~ 6)
* 1 : parzen window
* 2 : welch window
* 3 : hanning window
* 4 : hamming window
* 5 : blackman window
* 6 : steeper 30-dB/octave rolloff window
*/
void
windowing (int n, const double *data, int flag_window, double scale,
double *out);
void
fprint_window_name (FILE *out, int flag_window);
/* apply FFT with the window and return amplitude and phase
* this is a wrapper mainly for phase vocoder process
* INPUT
* len : FFT length
* data[len] : data to analyze
* flag_window : window type
* plan, in, out : for FFTW3
* scale : amplitude scale factor
* OUTPUT
* amp[len/2+1] : amplitude multiplied by the factor "scale" above
* phs[len/2+1] : phase
*/
void
apply_FFT (int len, const double *data, int flag_window,
fftw_plan plan, double *in, double *out,
double scale,
double *amp, double *phs);
/* prepare window for FFT
* INPUT
* n : # of samples for FFT
* flag_window : 0 : no-window (default -- that is, other than 1 ~ 6)
* 1 : parzen window
* 2 : welch window
* 3 : hanning window
* 4 : hamming window
* 5 : blackman window
* 6 : steeper 30-dB/octave rolloff window
* OUTPUT
* density factor as RETURN VALUE
*/
double
init_den (int n, char flag_window);
/* calc power spectrum of real data x[n]
* INPUT
* n : # of data in x
* x[] : data
* y[] : for output (you have to allocate before calling)
* den : weight of window function; calculated by init_den().
* flag_window : 0 : no-window (default -- that is, other than 1 ~ 6)
* 1 : parzen window
* 2 : welch window
* 3 : hanning window
* 4 : hamming window
* 5 : blackman window
* 6 : steeper 30-dB/octave rolloff window
* OUTPUT
* y[] : fourier transform of x[]
* p[(n+1)/2] : stored only n/2 data
*/
#ifdef FFTW2
#include <rfftw.h>
void
power_spectrum_fftw (int n, double *x, double *y, double *p,
double den,
char flag_window,
rfftw_plan plan)
#else // FFTW3
void
power_spectrum_fftw (int n, double *x, double *y, double *p,
double den,
char flag_window,
fftw_plan plan);
#endif // !FFTW2
/* subtract average from the power spectrum
* -- intend to remove non-tonal signal (such as drums, percussions)
* INPUT
* n : FFT size
* p[(n+1)/2] : power spectrum
* m : number of bins to average out
* factor : factor * average is subtracted from the power
* (factor = 0.0) means no subtraction
* (factor = 1.0) means full subtraction of the average
* (factor = 2.0) means over subtraction
* OUTPUT
* p[(n+1)/2] : subtracted power spectrum
*/
void
power_subtract_ave (int n, double *p, int m, double factor);
/* octave remover
* INPUT
* n : FFT size
* p[(n+1)/2] : power spectrum
* factor : factor * average is subtracted from the power
* (factor = 0.0) means no subtraction
* (factor = 1.0) means full subtraction of the average
* (factor = 2.0) means over subtraction
* OUTPUT
* p[(n+1)/2] : subtracted power spectrum
*/
void
power_subtract_octave (int n, double *p, double factor);
#endif /* !_FFT_H_ */