qq_33719379
木屐啊
采纳率50%
2020-02-19 16:32

有没有大佬可以提供一个基于Hexagon sdk的adsp简单滤波算法的代码示例?(类似它自带的capi_v2_gain这种例子)

60
  1. 我自己仿照capi_v2_gain,写了一个低通滤波的框架,基本只改变了process里面的核心算法函数,输入信号为包含500、1000和2000频率成分的正弦信号,但是在sdk中仿真处理完之后的信号没有实现滤波,并且包含很多高频成分。将代码集成到adsp中,手机的录音就出现很多杂音。
  2. 另外:这个定点计算的低通滤波我在matlab中仿真过,可以得到正确的结果,但放到sdk里就不对了,有可能是需要内存分配啥的,我是个c/c++和dsp小白,一直找不到问题所在,求大佬拯救一下!!! 代码如下:
/*
in_buf[]是指向每个通道的数据缓冲区地址的指针数组,我设置的通道数(num_channels)为2,in_buf的数组元素数量为2;
N是滤波器阶数
*/
void lowpass_filter(int32_t* in_buf[],
        int32_t* out_buf[],
        uint16_t N,
        uint32_t num_samples)
{
    uint32_t h,i,j,k;
    int64_t out;
    int32_t coef;//定点化后的系数
    uint16_t Q = 13; //将滤波系数定点化的定标位
 //matlab中得到的1khz的低通滤波系数
    const float filter_coefficients[101] = {0.0001313106797282,6.834005229901e-05,-1.353104057844e-19,-7.762389720212e-05,
              -0.0001685125401241,-0.0002764357282808,-0.0004046614304012,-0.0005556629350297,
              -0.0007308354291817,-0.000930233679387,-0.001152342207602,-0.001393888663946,
              -0.001649710012508,-0.001912679692733,-0.002173702137323,-0.002421778970265,
               -0.00264414893783,-0.002826501212082,-0.002953259227455,-0.003007929747013,
              -0.002973509487934,-0.002832939445581,-0.002569595118286, -0.00216779921951,
              -0.001613342230416,-0.0008939953422497,9.204641745017e-19, 0.001075481592696,
               0.002335970006679, 0.003781340034815, 0.005407572350892, 0.007206595681381,
                0.00916622743461,  0.01127021808002,  0.01349840170039,  0.01582695213701,
                0.01822874110185,  0.02067379163472,  0.02312981742882,  0.02556283592438,
                0.02793784075965,  0.03021951724431,  0.03237298304651,  0.03436453530788,
                0.03616238495784,  0.03773735910487,   0.0390635530409,   0.0401189145893,
                 0.0408857452251,  0.04135110454983,  0.04150710725172,  0.04135110454983,
                 0.0408857452251,   0.0401189145893,   0.0390635530409,  0.03773735910487,
                0.03616238495784,  0.03436453530788,  0.03237298304651,  0.03021951724431,
                0.02793784075965,  0.02556283592438,  0.02312981742882,  0.02067379163472,
                0.01822874110185,  0.01582695213701,  0.01349840170039,  0.01127021808002,
                0.00916622743461, 0.007206595681381, 0.005407572350892, 0.003781340034815,
               0.002335970006679, 0.001075481592696,9.204641745017e-19,-0.0008939953422497,
              -0.001613342230416, -0.00216779921951,-0.002569595118286,-0.002832939445581,
              -0.002973509487934,-0.003007929747013,-0.002953259227455,-0.002826501212082,
               -0.00264414893783,-0.002421778970265,-0.002173702137323,-0.001912679692733,
              -0.001649710012508,-0.001393888663946,-0.001152342207602,-0.000930233679387,
              -0.0007308354291817,-0.0005556629350297,-0.0004046614304012,-0.0002764357282808,
              -0.0001685125401241,-7.762389720212e-05,-1.353104057844e-19,6.834005229901e-05,
              0.0001313106797282};
   //h是num_channels,即通道数,num_samples是每帧采样点
    for (h = 0; h < 2; h++)
    {
        for (i = 0; i < num_samples; i++)
        {
            //TODO:
            k = (i<N)?i:N;

            out = 0;
            for (j = 0; j <= k; j++)
            {

                coef = int16_t((filter_coefficients[j])* (float)((int32_t)(1)<<Q));
                out += int32_t(coef) * int32_t((in_buf[h][i-j]));
            }

             out = ((out >> Q));
             out_buf[h][i] = int32_t(out) ;
        }

    }

}
  • 点赞
  • 收藏
  • 复制链接分享

1条回答

相关推荐