打印

GD32F303之无限冲击响应滤波

[复制链接]
791|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 zeshoufx 于 2019-9-3 20:51 编辑

一、信号输入
test_in=arm_sin_f32(2*3.1415926*50*i/1000)+arm_sin_f32(2*3.1415926*250*i/1000);
二、测试函数
#include "dsp_filter.h"


#define length 320
#define numstatas 2


static float32_t test_in[320];
static float32_t test_out[320];
static float32_t iir_stata[8];

const float32_t IIRCoeffs32LP[5*numstatas] = {
1.0f, 2.0f, 1.0f, 1.4797988943972167f, -0.68867695305386178f,
1.0f, 2.0f, 1.0f, 1.2128120926202184f, -0.38400416228655354f
};

void filter_test(void)
{
        u32 i=0;
        arm_biquad_casd_df1_inst_f32 S;
        float32_t Proportion;
        

        for(i=0;i<length;i++)
        {
                test_in[i]=arm_sin_f32(2*3.1415926*50*i/1000)+arm_sin_f32(2*3.1415926*250*i/1000);
        }
        arm_biquad_cascade_df1_init_f32(&S,numstatas,(float32_t *)&IIRCoeffs32LP[0],&iir_stata[0]);
        arm_biquad_cascade_df1_f32(&S,test_in,test_out,320);
        Proportion= 0.052219514664161221f * 0.04279801741658381f;
        for(i=0;i<length;i++)
        {
                printf("%f\r\n",test_out[i]*Proportion);
        }
}



三、结果

四、主函数

/*
    昆明电器科学研究所 张恩寿 2019年5月3日
        
        
*/
#include "bitband.h"
#include "led_config.h"
#include "systick.h"
#include "usart.h"
#include "spi_flash.h"
#include "tft.h"
#include "key_lookup.h"
#include "dsp_filter.h"




int main(void)
{                        
        systick_config(120);
        nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
        usart0_init(115200);
    led_init();
        filter_test();
        
        while(1)
        {
                led_on();
                delay_nms(600);
                led_off();
                delay_nms(600);
        }
               
}




五、MATLAB函数
gd32=[0.000000
0.002925
0.020893
0.070248
0.153351
0.258624
0.382087
0.526850
0.677789
0.800785
0.871091
0.880735
0.818354
0.669428
0.441693
0.166833
-0.126544
-0.419203
-0.680922
-0.871749
-0.969688
-0.975598
-0.889837
-0.709505
-0.451699
-0.154097
0.152185
0.448280
0.706214
0.889093
0.977894
0.975770
0.884423
0.701365
0.443376
0.147382
-0.156390
-0.449879
-0.705684
-0.887207
-0.975468
-0.973478
-0.882702
-0.700396
-0.443127
-0.147681
0.155777
0.449177
0.705069
0.886780
0.975261
0.973466
0.882827
0.700589
0.443327
0.147845
-0.155672
-0.449136
-0.705079
-0.886824
-0.975318
-0.973520
-0.882868
-0.700612
-0.443334
-0.147838
0.155686
0.449152
0.705093
0.886834
0.975323
0.973521
0.882866
0.700608
0.443329
0.147834
-0.155690
-0.449154
-0.705094
-0.886834
-0.975323
-0.973521
-0.882865
-0.700609
-0.443330
-0.147835
0.155688
0.449153
0.705092
0.886832
0.975320
0.973517
0.882862
0.700605
0.443326
0.147832
-0.155692
-0.449155
-0.705094
-0.886832
-0.975320
-0.973517
-0.882862
-0.700605
-0.443326
-0.147833
0.155690
0.449154
0.705093
0.886832
0.975321
0.973519
0.882863
0.700607
0.443328
0.147833
-0.155691
-0.449155
-0.705095
-0.886835
-0.975324
-0.973521
-0.882866
-0.700608
-0.443329
-0.147834
0.155690
0.449155
0.705095
0.886835
0.975324
0.973522
0.882866
0.700608
0.443328
0.147833
-0.155692
-0.449157
-0.705098
-0.886838
-0.975327
-0.973524
-0.882867
-0.700608
-0.443327
-0.147831
0.155694
0.449159
0.705099
0.886840
0.975329
0.973527
0.882871
0.700614
0.443335
0.147839
-0.155687
-0.449154
-0.705096
-0.886838
-0.975328
-0.973527
-0.882872
-0.700616
-0.443336
-0.147841
0.155684
0.449150
0.705090
0.886830
0.975319
0.973517
0.882862
0.700606
0.443329
0.147837
-0.155684
-0.449147
-0.705086
-0.886827
-0.975318
-0.973519
-0.882866
-0.700611
-0.443332
-0.147837
0.155688
0.449153
0.705092
0.886832
0.975320
0.973517
0.882862
0.700606
0.443330
0.147838
-0.155684
-0.449148
-0.705089
-0.886831
-0.975321
-0.973521
-0.882866
-0.700609
-0.443330
-0.147834
0.155690
0.449154
0.705093
0.886832
0.975319
0.973516
0.882861
0.700605
0.443328
0.147835
-0.155688
-0.449153
-0.705094
-0.886835
-0.975325
-0.973523
-0.882867
-0.700609
-0.443328
-0.147832
0.155692
0.449156
0.705096
0.886835
0.975324
0.973522
0.882868
0.700613
0.443335
0.147841
-0.155684
-0.449150
-0.705093
-0.886835
-0.975326
-0.973525
-0.882870
-0.700613
-0.443333
-0.147836
0.155690
0.449155
0.705096
0.886837
0.975326
0.973525
0.882870
0.700614
0.443335
0.147840
-0.155684
-0.449150
-0.705091
-0.886832
-0.975321
-0.973519
-0.882863
-0.700605
-0.443327
-0.147834
0.155687
0.449148
0.705084
0.886822
0.975311
0.973511
0.882861
0.700609
0.443335
0.147843
-0.155681
-0.449148
-0.705092
-0.886837
-0.975329
-0.973528
-0.882871
-0.700612
-0.443331
-0.147835
0.155688
0.449151
0.705090
0.886830
0.975321
0.973522
0.882870
0.700618
0.443341
0.147847
-0.155679
-0.449147
-0.705091
-0.886833
-0.975323
-0.973521
-0.882866
-0.700609
-0.443332
-0.147840
0.155680
0.449142
0.705082
0.886824
0.975316
0.973520
0.882870
0.700618
0.443341
0.147847
-0.155678
-0.449144
-0.705086
-0.886827
];
fs=1000;
N=320;
n=0:N-1;
t=n/fs;
f=n*fs/N;
b=fir1(28,0.25);
x=sin(2*pi*50*t)+sin(2*pi*250*t);
x1=sin(2*pi*50*t);
y=filter(b,1,x);
subplot(311)
plot(t,x),title('未滤波效果'),xlabel('时间'),ylabel('幅值'),grid;
subplot(312)
plot(t,x1),title('MATLAB 基波'),xlabel('时间'),ylabel('幅值'),grid;
subplot(313)
plot(t,gd32),title('GD32F303 IIR滤波效果'),xlabel('时间'),ylabel('幅值'),grid;



780415d6e61296d77d.png (47.57 KB )

780415d6e61296d77d.png

使用特权

评论回复
评论
zeshoufx 2019-9-5 11:04 回复TA
自己顶一个 
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

67

主题

1962

帖子

14

粉丝