comparison dsp/chromagram/ConstantQ.cpp @ 469:8d84e5d16314

Fix error in lower bins
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 30 May 2019 14:10:15 +0100
parents a72d98f8baa3
children 73fc1de3254a
comparison
equal deleted inserted replaced
468:a72d98f8baa3 469:8d84e5d16314
126 } 126 }
127 127
128 // Computing a hamming window 128 // Computing a hamming window
129 const unsigned hammingLength = (int) ceil( m_dQ * m_FS / ( m_FMin * pow(2,((double)(k))/(double)m_BPO))); 129 const unsigned hammingLength = (int) ceil( m_dQ * m_FS / ( m_FMin * pow(2,((double)(k))/(double)m_BPO)));
130 130
131 // cerr << "k = " << k << ", q = " << m_dQ << ", m_FMin = " << m_FMin << ", hammingLength = " << hammingLength << " (rounded up from " << (m_dQ * m_FS / ( m_FMin * pow(2,((double)(k))/(double)m_BPO))) << ")" << endl;
132
133
131 unsigned origin = m_FFTLength/2 - hammingLength/2; 134 unsigned origin = m_FFTLength/2 - hammingLength/2;
132 135
133 for (unsigned i=0; i<hammingLength; i++) 136 for (unsigned i=0; i<hammingLength; i++)
134 { 137 {
135 const double angle = 2*PI*m_dQ*i/hammingLength; 138 const double angle = 2*PI*m_dQ*i/hammingLength;
157 { 160 {
158 // perform thresholding 161 // perform thresholding
159 const double squaredBin = squaredModule( transfHammingWindowRe[ j ], transfHammingWindowIm[ j ]); 162 const double squaredBin = squaredModule( transfHammingWindowRe[ j ], transfHammingWindowIm[ j ]);
160 if (squaredBin <= squareThreshold) continue; 163 if (squaredBin <= squareThreshold) continue;
161 164
162 // Insert non-zero position indexes, doubled because they are floats 165 // Insert non-zero position indexes
163 sk->is.push_back(j); 166 sk->is.push_back(j);
164 sk->js.push_back(k); 167 sk->js.push_back(k);
165 168
166 // take conjugate, normalise and add to array sparkernel 169 // take conjugate, normalise and add to array sparkernel
167 sk->real.push_back( transfHammingWindowRe[ j ]/m_FFTLength); 170 sk->real.push_back( transfHammingWindowRe[ j ]/m_FFTLength);
269 272
270 for (unsigned i = 0; i<sparseCells; i++) 273 for (unsigned i = 0; i<sparseCells; i++)
271 { 274 {
272 const unsigned row = cqbin[i]; 275 const unsigned row = cqbin[i];
273 const unsigned col = fftbin[i]; 276 const unsigned col = fftbin[i];
277 if (col == 0) continue;
274 const double & r1 = real[i]; 278 const double & r1 = real[i];
275 const double & i1 = imag[i]; 279 const double & i1 = imag[i];
276 const double & r2 = fftdata[ (2*m_FFTLength) - 2*col - 2 ]; 280 const double & r2 = fftdata[ (2*m_FFTLength) - 2*col - 2 ];
277 const double & i2 = fftdata[ (2*m_FFTLength) - 2*col - 2 + 1 ]; 281 const double & i2 = fftdata[ (2*m_FFTLength) - 2*col - 2 + 1 ];
278 // add the multiplication 282 // add the multiplication
338 342
339 for (unsigned i = 0; i<sparseCells; i++) 343 for (unsigned i = 0; i<sparseCells; i++)
340 { 344 {
341 const unsigned row = cqbin[i]; 345 const unsigned row = cqbin[i];
342 const unsigned col = fftbin[i]; 346 const unsigned col = fftbin[i];
347 if (col == 0) continue;
343 const double & r1 = real[i]; 348 const double & r1 = real[i];
344 const double & i1 = imag[i]; 349 const double & i1 = imag[i];
345 const double & r2 = FFTRe[ m_FFTLength - col - 1 ]; 350 const double & r2 = FFTRe[ m_FFTLength - col ];
346 const double & i2 = FFTIm[ m_FFTLength - col - 1 ]; 351 const double & i2 = FFTIm[ m_FFTLength - col ];
347 // add the multiplication 352 // add the multiplication
348 CQRe[ row ] += (r1*r2 - i1*i2); 353 CQRe[ row ] += (r1*r2 - i1*i2);
349 CQIm[ row ] += (r1*i2 + i1*r2); 354 CQIm[ row ] += (r1*i2 + i1*r2);
350 } 355 }
351 } 356 }