?? lowpassfilter.c
字號(hào):
#include <stdio.h>
#define FRAME 180
short int h[19] = {
399,-296,-945,-1555,
-1503,-285,2112,5061,
7503,8450,7503,5061,
2112,-285,-1503,-1555,
-945,-296,399
};
static short int nBuff[FRAME + 20];
void LowpassFilter(short int nIn[],short int nOut[],int nLen,short int h[]);
void main()
{
FILE *m_pInput;
FILE *m_pOutput;
short int input[FRAME];
short int output[FRAME];
int count;
// 打開輸入文件
if((m_pInput = fopen("input.wav", "rb")) == NULL)
{
return;
}
//打開輸出文件
if((m_pOutput = fopen("output.wav", "wb")) == NULL)
{
return;
}
count = 0;
while( fread(&input[0], sizeof(short int), FRAME, m_pInput) == FRAME)
{
printf("Frame =%d\r", count++);
//濾波處理
LowpassFilter(input,output,19,h);
//將濾波后的數(shù)據(jù)寫到文件里
fwrite(output, sizeof(short int), FRAME, m_pOutput);
}
fclose(m_pOutput);
fclose(m_pInput);
}
void LowpassFilter(short int nIn[],short int nOut[],int nLen,short int h[])
{
short int i,j;
int sum;
//緩沖區(qū)的內(nèi)容更新
for(i = 0;i < FRAME;i++)
{
nBuff[i + nLen -1] = nIn[i];
}
//FIR濾波處理
for(i = 0;i < FRAME;i++)
{
sum = 0;
for(j = 0;j < nLen;j++)
{
sum += h[j] * nBuff[i - j + nLen -1];
}
nOut[i] = sum >> 15;
}
//更新緩沖區(qū)的內(nèi)容
for(i = 0;i < nLen - 1;i++)
{
nBuff[nLen - i - 2] = nIn[FRAME - i - 1];
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -