欢迎使用CSDN-markdown编辑器

单元测试

APstack

#include <stdio.h>
#define APstacksize 10     //stack size 和滤波时间要不要关联起来

typedef unsigned int Uint32;
typedef unsigned short int Uint16;

//要求一段时间的变化量,还是必须有个栈能保存这段时间的样本的
//需要自己内部构造一个采样器
typedef struct
{
    Uint16 samplefreq;       //采样频率   
    Uint16 sample;
    Uint16 samplepre;        //上一次采样值
    Uint16 DeltaSamplePst;   //每两次采样间隔样本变化量
    Uint16 DeltaSampleAT;
    Uint16 samplefiltered;
    Uint16 filterTime;       //数据量累计的时间
}ST_lpf;

Uint16 samplestack[APstacksize];
Uint16 p21st,p2last;
void lpfinit(ST_lpf *lpf,Uint16 frq,Uint16 T);     
void AimposLpf(ST_lpf *lpf); 
int main(void) {
    static stackfullflag;
    static ST_lpf stlpf_Aimpos;
    Uint16 runtime;
    Uint16 Tperiod = 0; 
    Uint16 Tcount = 0;
    Uint16 filtereddata[100];
    stackfullflag = 0;
    lpfinit(&stlpf_Aimpos,2,5);
    Tperiod = 20*stlpf_Aimpos.samplefreq;
    for(runtime=0;runtime<100;runtime++)
    {

      if(0 == runtime%stlpf_Aimpos.samplefreq)
      {
        Tcount++;
        if(Tcount >= APstacksize-1)
        {
            Tcount = APstacksize-1;
        }
        stlpf_Aimpos.samplepre = stlpf_Aimpos.sample;
        stlpf_Aimpos.sample = runtime<<3;
        stlpf_Aimpos.DeltaSamplePst = stlpf_Aimpos.sample - stlpf_Aimpos.samplepre;
        samplestack[p2last] =  stlpf_Aimpos.sample;
        stlpf_Aimpos.DeltaSampleAT = samplestack[p2last]-samplestack[p21st];
        stlpf_Aimpos.DeltaSamplePst = stlpf_Aimpos.DeltaSampleAT*100/Tperiod;

        filtereddata[runtime] = stlpf_Aimpos.samplefiltered;
    //      printf("%d %d %d %d\n", stlpf_Aimpos.sample,p21st,p2last,samplestack[p2last]);
                printf("%d %d %d %d %d %d\n", runtime,samplestack[p2last],samplestack[p21st],stlpf_Aimpos.DeltaSampleAT,stlpf_Aimpos.DeltaSamplePst,stlpf_Aimpos.samplefiltered);

        p2last++;
        if(p2last < APstacksize - 1 && Tcount >= APstacksize-1 )   //注意与matlab的区别
        {
            p21st = p2last+1;
        }
        else if(p2last == APstacksize - 1)
        {
            p21st = 0;
        }
        else if(p2last > APstacksize - 1)
        {
            p2last = 0;
            p21st = p2last+1;
        }
      }
      AimposLpf(&stlpf_Aimpos);
    }
    return 0;
}
void lpfinit(ST_lpf *lpf,Uint16 frq,Uint16 T)
{
    lpf->samplefreq = frq;
    lpf->sample = 0;
    lpf->samplepre = 0;
    lpf->DeltaSamplePst = 0;
    lpf->DeltaSampleAT=0;
    lpf->samplefiltered = 0;
    lpf->filterTime = T;
}
void AimposLpf(ST_lpf *lpf)
{
    lpf->samplefiltered = lpf->samplefiltered + lpf->DeltaSamplePst;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值