本人现在正在用STM32 的ADC来采样两路SENSOR信号,分别用ADC完成中断和ADC DMA传输完成中断。。。
================
DFT 刚刚接触,也刚刚接触算法问题。。。。
思路如下:
两adc利用中断得到数据---》然后吧数据做成数组buff ---》 然后在主循环中做DFT运算-------------------------说真的DFT 这个函数不知道如何设计来完成他!以下是我从上位机VB移植过来DFT处理程序。
double DFT_OLD(short dir,int16_t dwADSample,double saBuffera[],double saBufferb[])
{
static double t=0;
static double Loff=0,Qoff=0,SumLC=0,SumLS=0,SumQC=0,SumQS=0,LdAvg,RefAvg,gsd33FFtTotal;
static double LdPhase,RefPhase,LdTotal,RefTotal,LdTtl,RefTtl;
static int16_t i,m=0;
m=(dwADSample/2)-1;
//flag=0;
//delay_ms(10);
for (i=0;i<m;i++)
{
t = i * 0.0002006004;
//for any offsets
Loff = Loff + saBuffera[i]; //for Load Cell input Raw Data.
Qoff = Qoff + saBufferb[i]; //for Probe input Raw Data.
//convert (load) to cosine and sine.
SumLC = (SumLC + saBuffera[i] * (cos(FREQ * t)));
SumLS = (SumLS + saBuffera[i] * (sin(FREQ * t)));
//convert (charge amp.) to cosine and sine.
SumQC = (SumQC + saBufferb[i] * (cos(FREQ * t)));
SumQS = (SumQS + saBufferb[i] * (sin(FREQ * t)));
}
//flag=1;
LdAvg = Loff / (dwADSample / 2); //offset for load cell
RefAvg = Qoff / (dwADSample / 2); //offset for charge amp (probe)
// to get the total
LdTtl = ((sqrt(SumLC*SumLC + SumLS*SumLS)) / (dwADSample / 2));
RefTtl = ((sqrt(SumQC*SumQC + SumQS*SumQS)) / (dwADSample / 2));
//convert totals into voltages
// LdAvg = (LdAvg * 0.00015259) '(0.0012207) * 0.123)
// RefAvg = (RefAvg * 0.000015259) '(0.0012207) * 0.0123)
// LdTotal = (LdTtl * 0.0001529)
// RefTotal = (RefTtl * 0.0001529) - RefAvg
LdTotal = LdTtl;
RefTotal = RefTtl - RefAvg;
// to find the phase angle
LdPhase = atan(SumLS / SumLC); //phase angle of load cell
RefPhase = atan(SumQS / SumQC); //phase angle of charge amp (probe)
if ((Sgn(SumLS) == 1)&&(Sgn(SumLC) == -1 ))
LdPhase = LdPhase - 3.14159265;
if ((Sgn(SumLS) == -1)&&( Sgn(SumLC) == -1 ))
LdPhase = LdPhase + 3.14159265;
if ((Sgn(SumQS) == 1)&&(Sgn(SumQC) == -1))
RefPhase = RefPhase - 3.14159265;
if ((Sgn(SumQS) == -1) &&( Sgn(SumQC) == -1 ))
RefPhase = RefPhase + 3.14159265;
//using the phase to find the polarity of the film
if ((fabs(LdPhase - RefPhase) > 1.57079632) && (fabs(LdPhase - RefPhase) < (3 * 1.57079632)))
gsd33FFtTotal = -1 * ((RefTotal / LdTotal) * 22.49718785); //RefTtl + LdTtl are Calibration Factors
else
gsd33FFtTotal = ((RefTotal / LdTotal) * 22.49718785);
if(dir==1)
return (LdAvg);
else
return (gsd33FFtTotal);
}
但在实际中,按照上述思路设计。STM32的RAM不够了。 我用DFT取点为4096点。。。。超出RAM.................
还请有哪位大虾指教下!!!TKS
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>