AGC library not working?
I am using the AGC library to amplify small signals picked by the mic and attenuate loud signals so they can be processed by the FFT function from the DSP library.
I have initialized the AGC and set the amplitude target to 0.5f. I know from testing and documentation that if you pass anything to the DSP library outside of the range -0.5 to 0.5 fractcomplex format it will output garbage.
Is the 0.5f of the AGC equivalent to the -0.5 to 0.5 range for the DSP library? I am finding that if I pass values from the ADC that are near clipping my frequency detection stops working and get wrong results. My code is as follows:
void readMic(void)//Sample microphone input
sigCmpx[ix_MicADCbuff].real = ADC1_Channel0ConversionResultGet();
sigCmpx[ix_MicADCbuff].imag = 0;
void alarmFreq(void)//Detect the dominant frequency of the audio picked by the microphone
fractional maxValue = sigCmpx.real;
maxValue = sigCmpx[ix_MicADCbuff].real;
VectorScale(FFT_BLOCK_LENGTH, &sigCmpx.real, &sigCmpx.real, 0.5);
FFTComplexIP (LOG2_BLOCK_LENGTH, &sigCmpx, (fractcomplex *) __builtin_psvoffset(&twiddleFactors), (int) __builtin_psvpage(&twiddleFactors));// Perform FFT operation
BitReverseComplex (LOG2_BLOCK_LENGTH, &sigCmpx);// Store output samples in bit-reversed order of their addresses
SquareMagnitudeCplx(FFT_BLOCK_LENGTH, &sigCmpx, &sigCmpx.real);//Compute the square magnitude of the complex FFT output array so we have a Real output vector
VectorMax(FFT_BLOCK_LENGTH/2, &sigCmpx.real, &peakFrequencyBin);//Find the frequency Bin ( = index into the SigCmpx array) that has the largest energy
peakFrequency = peakFrequencyBin*(AUDIO_FS/FFT_BLOCK_LENGTH); //Compute the frequency (in Hz) of the largest spectral component
Right now my solution was to use the DSP function VectorScale() when the signal is bigger than 0.5 in combination with the AGC to amplify small signals.