Comparing the performance of headphones using MEMS microphones (Part 3) Improving the frequency sweep test[Copy link]
When I started testing headphones with a MEMS microphone, I used a frequency sweep method. The method was to generate a sine signal of a specified frequency through the audio DAC of the SensorTile. The single frequency was sampled through the MEMS microphone, the current amplitude was calculated, the signal frequency was increased, and then the signal was collected and calculated again. This time, optimizations were made on the original basis, including: 1. Solving the problem of unsmooth generated sine data 2. Solving the problem of noise when switching between frequencies 3. Converting the amplitude into decibels Sine wave generation function
//Get the minimum N when sampleCount is within maxN times and sampleCount has the smallest decimal //N < sampleCount //maxSampleCount * N =/≈ integer //sampleCount The number of samples to be calculated //maxSampleCount The maximum number of samples //return N uint16_t get_repeat_cycle(float sampleCount,uint16_t maxN) { uint16_t i; uint16_t min = maxN; float min_f = 1; float f; for(i=2;i<maxn;i++) (1)="" (float)samplecount="" (int)(samplecount*i);="" (int16_t)((tmp="" (maxcode="" *="" +="" +0.5四舍五入="" +1)="" -="" 0)="" 0.2)="" 0.5);="" 1)="" 180.00="" 1]="0;" 2="" 2.00="" 32768);="" 40="" ;="" <="" =="" [code]="" abs((int)(maxfreq="" code]="" continue;="" else="" f="sampleCount*i" fft();="" fft_data[i*2="" fft_data[i*2]="audio_in[/size][/font][i][font=微软雅黑][size=4];" fft转换="" float="" font][i][font="微软雅黑][size=4]" for(i="0;i<sampleCount;i++)" freq="" freq))="" freqresp[freqrespindex++]="20" i;="" if(abs((int)(maxfreq="" if(f="=" if(f<min_f)="" if(fft_flag)="" if(freqrespindex="" log10(maxamplitude="" maxamplitude="get_maxIndex_amplitude();" maxcode="" maxcode,float="" maxfreq="get_maxIndex_freq();" min="i;" min;="" min_f="f;" n="get_repeat_cycle(sampleCount,MAX_SIN_TABLE_SIZE/(uint16_t)sampleCount);" outfreq,float="" outfreq;="" return="" samplecount="samplingFreq" samplingfreq)="" sinegenerator(int16_t="" sintable[="" sintable[],float="" sintableindex[!sintablearrayindex]="0;" sintablelength[!sintablearrayindex]="SineGenerator(sinTable[!sinTableArrayIndex],65535,freq,AUDIO_SAMPLING_FREQUENCY);" size][="" stepdegrees="360.00" stepdegrees;="" swicthingfreqflag="1;" test();="" tmp="stepDegrees" tmp;="" uint16_t="" while="" {="" ||="" }="" }[="" 保存当前这个最小的小数对应的倍数="" 分步弧度="" 分步角度="" 切换频率="" 取整数,实际无意义="" 否则,如果当前小数已经判断的最小的小数还小,用现在的替换="" 在频率较高j时样本数较少,samplecount不为整数时如果将小数舍去生成的波形会变形="" 填充左声道数据到fft_data="" 声音测量和频率切换代码="" 如果小数是0直接返回当前倍数="" 得到a的小数部分="" 得到对应正弦数据="" 得到对应的sin数据="" 得到当前弧度="" 得到最终的样本数="" 数据达到fft_size时做fft="" 游标移到起始处="" 生成sin数据="" 计算samplecount在多少倍时为整数,或接近整数="" 误差10%="" 输出数据索引="" 返回sintable长度="" 采样率除输出频率得到总样本数量="" 重新生成频率对应的sin数据,添加到非当前数组="" 频率递增="">= SCAN_COUNT) { BSP_AUDIO_OUT_Stop(PCM1774_X_0_handle,1); while(1); __NOP(); } } HAL_Delay(50); fft_flag = 0; } } }
Reference Posts Using MEMS Microphone Test to Compare the Performance of Headphones (II) Pink Noise Test https://bbs.eeworld.com.cn/thread-586982-1-1.html Using MEMS Microphone Test to Compare the Performance of Headphones (I) Sweep Frequency Test https://bbs.eeworld.com.cn/thread-573300-1-1.htmlSensorTile Sine Wave Generator https://bbs.eeworld.com.cn/thread-573240-1-1.html