请问计算各次谐波的幅值计算原理。至于如何实现傅立叶积分计算更是不懂,望各位大侠指
原理不懂,下面程序看看也是很费劲的。/* ************************************************************************
** 函 数 名:void ADCHD()
** 功能描述:单通道高频采样,数据处理,显示.
*************************************************************************** */
void ADCHD()
{
long D,SHU; //数据.
int n_x,k_x,i; //循环参数.
float Ur,Ui,Urn,Uin; //数据处理中间变量.
ADWORDS=ADCAN+7; //确定MAX197控制字.
for(ADD=0;ADD<64;ADD++) //采样.
{
OUTADC(ADWORDS); //送控制字.
DELAY(0); //延时.
DATA=INADC(); //读取数据.
}
for(ADD=0;ADD<64;ADD++) //显示波形.
{
D=(int)(40.0*DATA/4096.0); //取数据.
LCDPIEX(ADD+64,40-D); //显示.
}
for(n_x=0;n_x<5;n_x++) //计算.
{
Urn=0.0; //实部.
Uin=0.0; //虚部.
for(k_x=0;k_x<32;k_x++) //n_x次谐波.
{
D=DATA; //取数据计算.
Urn=Urn+D/409.6*cos((2*n_x+1)*(k_x+1)*0.196);
Uin=Uin+D/409.6*sin((2*n_x+1)*(k_x+1)*0.196);
}
Ur=Urn/16.0; //
Ui=Uin/16.0; //
SHU=(long)(100*sqrt(Ur*Ur+Ui*Ui));
UI=SHU; //第n_x次谐波幅值.
UI=SHU*SHU+UI; //
}
UI=(long)sqrt(UI); //总幅值.
for(i=0;i<5;i++) //
{
SHU=UI*1000; //
SHU=SHU/(UI); //
UP=SHU; //第i次谐波占有率.
}
SHU=1000*(UI-UI); //
UP=SHU/UI; //畸变率.
LCDCLEAN(12,2,126,7); //清除数据显示区.
for(i=0;i<6;i++)
{
OUTNUM(UI,1,28,2+i); //显示幅值.
OUTNUM(UP,3,56,2+i); //显示占有率.
}
ADWORDS=ADCAN; //还原控制字.
} 自己先顶一下 看样子懂的人还没来,自己再顶一下,不然就沉下去了。 http://cache.amobbs.com/bbs_upload782111/files_6/armok01146579.JPG 不懂,帮顶 3楼的图片应该就是这个程序产生的吧 上的程序只能说能够计算类似的数值。要实现上图的功能还差的远。
我原来是在上面图片产品的公司工作,可惜没有具体从事相关工作。这个东西台湾人设计的。开发的是我们的副总。60多岁的老头,不过看上去还是很年轻,奇色无比。不知道这几年有没有收敛。 郁闷,都快沉到底了。不顶不行了。
高手们,快点来吧! 看看DSP的书吧,数字信号处理原理.当时学的时候就觉得很难...这个不是在论坛上一句二句说得清楚的. 需要读 信号与系统, 数字信号处理 这些书籍, 确实不是在论坛上能说清的. 说实话,信号处理的书我找了好几本,没有一本是写的深入浅出的。一看就让人头大。
我的几个朋友以前都学过《数字信号处理》,现在他们都说学过,现在忘了。也不知道是真的忘了还是根本就没有学会。 都沉到底了,看样子是真的没有人懂了。 请师傅:http://weblab.xjtu.edu.cn/instrument/first/index.php?action=elements&itsid=13 按照自己的理解,请指点
DFT第1个点应该就是直流分量,第32个点就是采样频率,中间频率32等分。
每个点对应的值,就是该频率下的幅度.
以下是关键部分
/*,作用是进行32点dft计算
*主要是取出第1,3,5,7,9,次谐波的幅值
*然后把幅值相加
*/
for(n_x=0;n_x<5;n_x++)
{
Urn=0.0;
Uin=0.0;//虚部.
for(k_x=0;k_x<32;k_x++)//n_x次谐波.
{
D=DATA;//用到的模拟量x(t)的数值
//下面求出X(f)的值
//f(n)=((2*n_x+1)/32)*采样频率
//E的指数上面是-inm*(2pi/n)=cos(nm*2pi/N)+sin(nm*2pi/N)
//上面PI=3.14 N=32 n=k_x m=2*n_x+1
Urn=Urn+D/409.6*cos((2*n_x+1)*(k_x+1)*0.196);
Uin=Uin+D/409.6*sin((2*n_x+1)*(k_x+1)*0.196);
}
Ur=Urn/16.0; //信号重建,按照书上说的应该除采样总点数,不知道为什么要除2
Ui=Uin/16.0;
SHU=(long)(100*sqrt(Ur*Ur+Ui*Ui)); //把每次谐波的幅值相加
UI=SHU;//第n_x次谐波幅值.
UI=SHU*SHU+UI;
} ymmer,终于遇到你这个高手。
这个堂子里,你算是牛人了。 FP32 FFT_THD(FP32 const *CosTab,
FP32 const *SinTab) {
FP32 Kr, Ki, Krms;//系数,实部,虚部
INT8U i;
Kr = ((FP32)sample_data - (FP32)sample_data) * CosTab;
Ki = ((FP32)sample_data - (FP32)sample_data) * SinTab;
for (i=1;i<16;i++)
{
Kr += ((FP32)sample_data - (FP32)sample_data - (FP32)sample_data +
(FP32)sample_data) * CosTab;
Ki += ((FP32)sample_data + (FP32)sample_data - (FP32)sample_data -
(FP32)sample_data) * SinTab;
}
Krms = sqrt(Kr *Kr + Ki * Ki);
return(Krms);
}
const float costab1=
{
1.0, //0
0.99518472, //1
0.98078528, //2
0.95694033, //3
0.92387953, //4
0.88192126, //5
0.83146961, //6
0.77301046, //7
0.70710679, //8
0.63439329, //9
0.55557024, //10
0.47139675, //11
0.38268345, //12
0.29028469, //13
0.19509034, //14
0.09801716, //15
0.0 //16
};
const float sintab1=
{
0.0, //0
0.09801714, //1
0.19509032, //2
0.29028467, //3
0.38268343, //4
0.47139673, //5
0.55557023, //6
0.63439328, //7
0.70710678, //8
0.77301045, //9
0.83146961, //10
0.88192126, //11
0.92387953, //12
0.95694033, //13
0.98078528, //14
0.99518472, //15
1.0 //16
};
const float costab3=
{
1.0,
0.95694034, //1
0.83146961, //2
0.63439328, //3
0.38268343, //4
0.09801714,//5
-0.19509032,//6
-0.47139673,//7
-0.70710678,//8
-0.88192126,//9
-0.98078528,//10
-0.99518472,//11
-0.92387953,//12
-0.77301045,//13
-0.55557023,//14
-0.29028467,//15
0.0 //16
};
const float sintab3=
{
0.0, //0
0.29028468, //1
0.55557023, //2
0.77301045, //3
0.92387953, //4
0.99518473, //5
0.98078528, //6
0.88192126, //7
0.70710678, //8
0.47139674, //9
0.19509032, //10
-0.09801710, //11
-0.38268340, //12
-0.63439330, //13
-0.83146961, //14
-0.95694034, //15
-1.0 //16
};
const float costab5=
{
1.0, //0
0.88192126, //1
0.555568324,//2
0.09801714, //3
-0.38268343, //4
-0.77301045, //5
-0.98078528, //6
-0.95694033, //7
-0.70710678, //8
-0.29028468, //9
0.195090322, //10
0.634393284, //11
0.923879532, //12
0.995184726, //13
0.831469612, //14
0.471396737, //15
0.0 //16
};
const float sintab5=
{
0.0, //0
0.47139674, //1
0.83146961, //2
0.99518473, //3
0.92387953, //4
0.63439328, //5
0.19509032, //6
-0.29028468, //7
-0.70710678, //8
-0.95694034, //9
-0.98078528, //10
-0.77301045, //11
-0.38268343, //12
0.098017140, //13
0.555570233, //14
0.881921264, //15
1.0 //16
};
const float costab7=
{
1.0, //0
0.77301045, //1
0.19509032, //2
-0.47139674, //3
-0.92387953, //4
-0.95694034, //5
-0.55557023, //6
0.098017140, //7
0.707106781, //8
0.995184727, //9
0.831469612, //10
0.290284677, //11
-0.382683430, //12
-0.881921264, //13
-0.980785280, //14
-0.634393284, //15
0.0 //16
};
const float sintab7=
{
0.0, //0
0.63439328, //1
0.98078528, //2
0.88192126, //3
0.38268343, //4
-0.29028468, //5
-0.83146961, //6
-0.99518473, //7
-0.70710678, //8
-0.09801714, //9
0.55557023, //10
0.95694034, //11
0.92387953, //12
0.47139674, //13
-0.19509030, //14
-0.77301045, //15
-1.0 //16
};
//9
const float costab9=
{
1.0, //0
0.63439328, //1
-0.19509032, //2
-0.88192126, //3
-0.92387953, //4
-0.29028468, //5
0.55557023, //6
0.99518473, //7
0.70710678, //8
-0.09801714, //9
-0.83146961, //10
-0.95694034, //11
-0.38268343, //12
0.47139674, //13
0.98078528, //14
0.77301045, //15
0.0 //16
};
const float sintab9=
{
0.0, //0
0.77301045, //1
0.98078528, //2
0.47139674, //3
-0.38268343, //4
-0.95694034, //5
-0.83146961, //6
-0.09801714, //7
0.70710678, //8
0.99518473, //9
0.55557023, //10
-0.29028468, //11
-0.92387953, //12
-0.88192126, //13
-0.19509032, //14
0.63439328, //15
1.0 //16
};
//11
const float costab11=
{
1.0, //0
0.47139674, //1
-0.5555702, //2
-0.99518473, //3
-0.38268343, //4
0.63439328, //5
0.98078528, //6
0.29028467, //7
-0.70710678, //8
-0.95694033, //9
-0.19509032, //10
0.77301045, //11
0.92387953, //12
0.09801714, //13
-0.83146961, //14
-0.88192126, //15
0.0 //16
};
const float sintab11=
{
0.0, //0
0.88192126, //1
0.83146961, //2
-0.09801714, //3
-0.92387953, //4
-0.77301045, //5
0.19509032, //6
0.95694034, //7
0.70710678, //8
-0.29028468, //9
-0.98078528, //10
-0.63439328, //11
0.38268343, //12
0.99518473, //13
0.55557023, //14
-0.47139674, //15
-1.0 //16
};
//13
const floatcostab13=
{
1.0, //0
0.29028468, //1
-0.83146961, //2
-0.77301045, //3
0.38268343, //4
0.99518472, //5
0.19509032, //6
-0.88192126, //7
-0.70710678, //8
0.47139674, //9
0.98078528, //10
0.09801714, //11
-0.92387953, //12
-0.63439328, //13
0.55557023, //14
0.95694033, //15
0.0 //16
};
const float sintab13=
{
0.0, //0
0.95694034, //1
0.55557023, //2
-0.63439328, //3
-0.92387953, //4
0.09801714, //5
0.98078528, //6
0.47139673, //7
-0.70710678, //8
-0.88192126, //9
0.19509032, //10
0.99518473, //11
0.38268343, //12
-0.77301045, //13
-0.83146961, //14
0.29028468, //15
1.0 //16
};
//15
const float costab15=
{
1.0, //0
0.09801714, //1
-0.98078528, //2
-0.29028468, //3
0.92387953, //4
0.47139674, //5
-0.83146961, //6
-0.63439328, //7
0.70710678, //8
0.77301045, //9
-0.55557023, //10
-0.88192126, //11
0.38268343, //12
0.95694034, //13
-0.19509032, //14
-0.99518473, //15
0.0 //16
};
const float sintab15=
{
0.0, //0
0.99518473, //1
0.19509032, //2
-0.95694034, //3
-0.38268343, //4
0.88192126, //5
0.55557023, //6
-0.77301045, //7
-0.70710678, //8
0.63439328, //9
0.83146961, //10
-0.47139674, //11
-0.92387953, //12
0.29028468, //13
0.98078528, //14
-0.09801714, //15
-1.0 //16
}; void FFTdata(void) {
FP32 FFTx;
INT8U i;
FFTx = FFT_THD(costab1, sintab1);
FFTx = FFT_THD(costab3, sintab3);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = FFT_THD(costab5,sintab5);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = FFT_THD(costab7, sintab7);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = FFT_THD(costab9, sintab9);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = FFT_THD(costab11, sintab11);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = FFT_THD(costab13, sintab13);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = FFT_THD(costab15, sintab15);
Hr = (INT16U)((FFTx / FFTx) * 1000);
FFTx = 0x00;
for(i=0;i<7;i++) FFTx += ((FP32)(Hr) * (FP32)(Hr));
Hr = sqrt(FFTx);
} 14楼的牛人都来了啊,一个字:“强”! 帮顶,有空看看 呵呵,慢慢在理解一下 收藏了。 好,经典!谢谢了 好,经典!谢谢了
页:
[1]