|
|
|
@ -3,6 +3,8 @@ |
|
|
|
|
* |
|
|
|
|
* Status: Checked for function and accuracy. 19 April 2020 |
|
|
|
|
* 10 March 2021 Corrected Interpolation equations. Bob L |
|
|
|
|
* 23 Feb 2022 Added "pure spectrum" filtering. RSL |
|
|
|
|
* This adds the function pureSpectrum(bool _setPure); // Default: false
|
|
|
|
|
* |
|
|
|
|
* Created: Bob Larkin 15 April 2020 |
|
|
|
|
* |
|
|
|
@ -89,6 +91,37 @@ public: |
|
|
|
|
if (freq < 0.0f) freq = 0.0f; |
|
|
|
|
else if (freq > sample_rate_Hz/2.0f) freq = sample_rate_Hz/2.0f; |
|
|
|
|
phaseIncrement = 512.0f * freq / sample_rate_Hz; |
|
|
|
|
|
|
|
|
|
// Find coeff for 2 stages of BPF to remove harmoncs
|
|
|
|
|
// Always compute these in case pureSpectrum is enabled later.
|
|
|
|
|
if(freq > 0.003f*sample_rate_Hz) |
|
|
|
|
{ |
|
|
|
|
float32_t q = 20.0f; |
|
|
|
|
float32_t w0 = freq * (2.0f * 3.141592654f / sample_rate_Hz); |
|
|
|
|
float32_t alpha = sin(w0) / (q * 2.0); |
|
|
|
|
float32_t scale = 1.0f / (1.0f + alpha); |
|
|
|
|
/* b0 */ coeff32[0] = alpha * scale; |
|
|
|
|
/* b1 */ coeff32[1] = 0; |
|
|
|
|
/* b2 */ coeff32[2] = (-alpha) * scale; |
|
|
|
|
/* a1 */ coeff32[3] = -(-2.0 * cos(w0)) * scale; |
|
|
|
|
/* a2 */ coeff32[4] = -(1.0 - alpha) * scale; |
|
|
|
|
/* b0 */ coeff32[5] = coeff32[0]; |
|
|
|
|
/* b1 */ coeff32[6] = coeff32[1]; |
|
|
|
|
/* b2 */ coeff32[7] = coeff32[2]; |
|
|
|
|
/* a1 */ coeff32[8] = coeff32[3]; |
|
|
|
|
/* a2 */ coeff32[9] = coeff32[4]; |
|
|
|
|
arm_biquad_cascade_df1_init_f32( &bq_instS, 2, coeff32, state32S ); |
|
|
|
|
arm_biquad_cascade_df1_init_f32( &bq_instC, 2, coeff32, state32C ); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
for(int ii=0; ii<10; ii++) // Coeff for BiQuad BPF
|
|
|
|
|
coeff32[ii] = 0.0; |
|
|
|
|
coeff32[0] = 1.0; // b0 = 1 for pass through
|
|
|
|
|
coeff32[5] = 1.0; |
|
|
|
|
arm_biquad_cascade_df1_init_f32( &bq_instS, 2, coeff32, state32S ); |
|
|
|
|
arm_biquad_cascade_df1_init_f32( &bq_instC, 2, coeff32, state32C ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Externally, phase comes in the range (0,2*M_PI) keeping with C math functions
|
|
|
|
@ -146,6 +179,8 @@ public: |
|
|
|
|
block_length = bl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void pureSpectrum(bool _setPure) { doPureSpectrum = _setPure; } |
|
|
|
|
|
|
|
|
|
virtual void update(void); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
@ -159,5 +194,11 @@ private: |
|
|
|
|
// if only freq() is used, the complexities of phase, phaseS_C,
|
|
|
|
|
// and amplitude are not used, speeding up the sin and cos:
|
|
|
|
|
bool doSimple = true; |
|
|
|
|
bool doPureSpectrum = false; // Adds bandpass filter (not normally needed)
|
|
|
|
|
float32_t coeff32[10]; // 2 biquad stages for filtering output shared S&C
|
|
|
|
|
float32_t state32S[8]; |
|
|
|
|
arm_biquad_casd_df1_inst_f32 bq_instS; // ARM DSP Math library filter instance.
|
|
|
|
|
float32_t state32C[8]; |
|
|
|
|
arm_biquad_casd_df1_inst_f32 bq_instC; // ARM DSP Math library filter instance.
|
|
|
|
|
}; |
|
|
|
|
#endif |
|
|
|
|