3.2 子函数代码实现
/********************************************************************
* Name : FuncHd
* Function: Hd()--Required frequency response function
*
*
*********************************************************************/
COMP FuncHd(double LowLimit,double UpperLimit,COMP x)
{
if(x.real()>UpperLimit||x.real() < LowLimit)
return 0;
else
return 1;
}
void FIR(double LowLimit,double UpperLimit,int N,COMP Hn[])
{
int M = 2*N;
for(int i=0;i < N;i++)
{
Hn[i] = COMP(0,0);
for(int k=0;k < M;k++)
{
COMP C = COMP(cos(2*pi*i*k/(double)M),sin(2*pi*i*k/(double)M));
Hn[i] += C*FuncHd(LowLimit,UpperLimit,COMP(cos(2*pi*k/(double)M),sin(2*pi*k/(double)M)));
}
Hn[i] = Hn[i]*COMP(1/(double)M,0);
}
} |