ios - Auto-correlating the cepstrum -
i'm trying detect echoes in sound coming microphone. echoes periodic , @ 1 of 2 possible offsets. i've heard need auto-correlate cepstrum of signal in order detect presence of these echoes. can provide code using accelerate framework shows how detect echoes in audio data?
i'm not entirely sure why you'd auto correlate cepstrum. auto correlation, though, gives representation related cepstrum assume want auto correlate signal.
in simplest form performed follows:
int sample = 0; int samplemax = insize; while( sample < samplemax ) { vdsp_vsmul( pinput, 1, pinputsample, tempbuffer, 1, samplemax ); const size_t kautocorrwritepos = outsize - samplemax - sample; vdsp_vsadd( &poutput[kautocorrwritepos], 1, tempbuffer, 1, &poutput[kautocorrwritepos], 1, samplemax ) sample++; }
this is, however, slow operation. thankfully correlation can performed in several different ways. fastest method perform fft, multiply complex values conjugate of , inverse fft.
or in ios have nicely optimised vdsp_conv function:
std::vector< float > paddedbuffer( (insize + insize) - 1 ); memcpy( &paddedbuffer.front(), pinput, sizeof( float ) * insize ); vdsp_conv( &paddedbuffer.front(), 1, (float*)pinput, 1, (float*)poutput + (insize - 1), 1, insize, insize ); // reflect auto correlation true output. int poswrite = (insize - 1); int posread = (insize - 1); while( poswrite > 0 ) { poswrite--; posread++; poutput[poswrite] = poutput[posread]; }
so have auto correlation, d o it?
well firstly right in middle have highest peak. 0 lag point. want scan right of central peak identify secondary peaks. if yo looking specific peak @ specific offset can, simply, check number of samples on central peak , check if there peak there. if there isn't signal looking not there. if there, signal there.
edit: worth noting 512 sample wide window if lag looking @ beyond 128 may not enough of correlation signal spottable. correlation works providing peaks @ points of repetitive signals in sample data. @ lag of 128 have enough data point repeat 4 times. @ 256 can see point repeat twice. affect height of correlation peak. after 256 may not spot peak @ against random repeatability factors. said, though, experiment different window sizes see provides reliable results.
Comments
Post a Comment