44 double* transfWindowRe =
new double [
m_FFTLength ];
45 double* transfWindowIm =
new double [
m_FFTLength ];
55 for (
int j =
m_uK - 1; j >= 0; --j) {
65 int windowLength = (int)ceil
68 int origin = m_FFTLength/2 - windowLength/2;
70 for (
int i = 0; i < windowLength; ++i) {
71 double angle = (2.0 * M_PI *
m_dQ * i) / windowLength;
72 windowRe[origin + i] = cos(angle);
73 windowIm[origin + i] = sin(angle);
78 hamming.
cut(windowRe + origin);
79 hamming.
cut(windowIm + origin);
82 for (
int i = 0; i < windowLength; ++i) {
83 windowRe[origin + i] /= windowLength;
85 for (
int i = 0; i < windowLength; ++i) {
86 windowIm[origin + i] /= windowLength;
91 for (
int i = 0; i < m_FFTLength/2; ++i) {
92 double temp = windowRe[i];
93 windowRe[i] = windowRe[i + m_FFTLength/2];
94 windowRe[i + m_FFTLength/2] = temp;
96 for (
int i = 0; i < m_FFTLength/2; ++i) {
97 double temp = windowIm[i];
98 windowIm[i] = windowIm[i + m_FFTLength/2];
99 windowIm[i + m_FFTLength/2] = temp;
102 fft.
process(
false, windowRe, windowIm, transfWindowRe, transfWindowIm);
108 double mag =
squaredModule(transfWindowRe[i], transfWindowIm[i]);
109 if (mag <= squareThreshold)
continue;
116 sk->
real.push_back( transfWindowRe[i] / m_FFTLength);
117 sk->
imag.push_back(-transfWindowIm[i] / m_FFTLength);
123 delete [] transfWindowRe;
124 delete [] transfWindowIm;
163 std::cerr <<
"ERROR: ConstantQ::process: Sparse kernel has not been initialised" << std::endl;
169 for (
int row=0; row < 2 *
m_uK; row++) {
173 const int *fftbin = &(sk->
is[0]);
174 const int *cqbin = &(sk->
js[0]);
175 const double *real = &(sk->
real[0]);
176 const double *imag = &(sk->
imag[0]);
177 const int sparseCells = int(sk->
real.size());
179 for (
int i = 0; i < sparseCells; i++) {
180 const int row = cqbin[i];
181 const int col = fftbin[i];
182 if (col == 0)
continue;
183 const double & r1 = real[i];
184 const double & i1 = imag[i];
185 const double & r2 = fftdata[ (2*
m_FFTLength) - 2*col - 2 ];
186 const double & i2 = fftdata[ (2*
m_FFTLength) - 2*col - 2 + 1 ];
188 m_CQdata[ 2*row ] += (r1*r2 - i1*i2);
189 m_CQdata[ 2*row+1] += (r1*i2 + i1*r2);
196 double *CQRe,
double *CQIm)
199 std::cerr <<
"ERROR: ConstantQ::process: Sparse kernel has not been initialised" << std::endl;
205 for (
int row = 0; row <
m_uK; row++) {
210 const int *fftbin = &(sk->
is[0]);
211 const int *cqbin = &(sk->
js[0]);
212 const double *real = &(sk->
real[0]);
213 const double *imag = &(sk->
imag[0]);
214 const int sparseCells = int(sk->
real.size());
216 for (
int i = 0; i<sparseCells; i++) {
217 const int row = cqbin[i];
218 const int col = fftbin[i];
219 if (col == 0)
continue;
220 const double & r1 = real[i];
221 const double & i1 = imag[i];
225 CQRe[ row ] += (r1*r2 - i1*i2);
226 CQIm[ row ] += (r1*i2 + i1*r2);
std::vector< double > real
void process(const double *FFTRe, const double *FFTIm, double *CQRe, double *CQIm)
static double squaredModule(const double &xx, const double &yy)
SparseKernel * m_sparseKernel
std::vector< double > imag
void initialise(CQConfig config)
void process(bool inverse, const double *realIn, const double *imagIn, double *realOut, double *imagOut)
Carry out a forward or inverse transform (depending on the value of inverse) of size nsamples...
static int nextPowerOfTwo(int x)
Return the next higher integer power of two from x, e.g.
ConstantQ(CQConfig config)