您尚未登录。

#1 Re: ESP32/ESP8266 » 精致小板系列之esp32c3 » 2021-12-24 15:29:46

大佬开源吗? 想打样几块来玩玩

#2 ST/STM8/STM8S/STM8L » 双二阶滤波器代码 » 2021-12-20 22:00:23

vjcmain
回复: 3

最近在DIY ECG,涉及到滤波器的设计

1.双二阶滤波器介绍:
   a) https://blog.csdn.net/hunterhuang2013/article/details/62043972


#include "biquad.h"

void calc_biquad(bq_coeff_p coeff_p);
void biquad_set_type(bq_coeff_p coeff_p,uint8_t filter_type)
{
        coeff_p->type = filter_type;
        calc_biquad(coeff_p);
}

void biquad_set_Q(bq_coeff_p coeff_p, double Q)
{
        coeff_p->Q = Q;
        calc_biquad(coeff_p);
}

void biquad_set_fc(bq_coeff_p coeff_p, double fc)
{
        coeff_p->fc = fc/coeff_p->sample_rate;
        calc_biquad(coeff_p);
}

void biquad_set_peak_gain(bq_coeff_p coeff_p, double peak_gainDB)
{
        coeff_p->peak_gain = peak_gainDB;
        calc_biquad( coeff_p);
}

void biquad_config(bq_coeff_p coeff_p,uint8_t type, double fc,uint32_t sample_rate,double Q, double peak_gainDB)
{
        coeff_p->type = type;
        coeff_p->fc = fc/(double)sample_rate;
        coeff_p->sample_rate =sample_rate;
        coeff_p->Q = Q;
        coeff_p->peak_gain = peak_gainDB;
        calc_biquad(coeff_p);
}

void calc_biquad(bq_coeff_p coeff_p)
{
        double norm;
        double a0 = 0;
        double a1 = 0;
        double a2 = 0;
        double b1 = 0;
        double b2 = 0;
        double Q = coeff_p->Q;
        double V = pow(10, fabs(coeff_p->peak_gain) / 20.0);
        double K = tan(M_PI * coeff_p->fc);
        switch (coeff_p->type)
        {
        case bq_type_lowpass:
                norm = 1 / (1 + K / Q + K * K);
                a0 = K * K * norm;
                a1 = 2 * a0;
                a2 = a0;
                b1 = 2 * (K * K - 1) * norm;
                b2 = (1 - K / Q + K * K) * norm;
                break;

        case bq_type_highpass:
                norm = 1 / (1 + K / Q + K * K);
                a0 = 1 * norm;
                a1 = -2 * a0;
                a2 = a0;
                b1 = 2 * (K * K - 1) * norm;
                b2 = (1 - K / Q + K * K) * norm;
                break;

        case bq_type_bandpass:
                norm = 1 / (1 + K / Q + K * K);
                a0 = K / Q * norm;
                a1 = 0;
                a2 = -a0;
                b1 = 2 * (K * K - 1) * norm;
                b2 = (1 - K / Q + K * K) * norm;
                break;

        case bq_type_notch:
                norm = 1 / (1 + K / Q + K * K);
                a0 = (1 + K * K) * norm;
                a1 = 2 * (K * K - 1) * norm;
                a2 = a0;
                b1 = a1;
                b2 = (1 - K / Q + K * K) * norm;
                break;

        case bq_type_peak:
                if (coeff_p->peak_gain >= 0)       // boost
                {
                        norm = 1 / (1 + 1 / Q * K + K * K);
                        a0 = (1 + V / Q * K + K * K) * norm;
                        a1 = 2 * (K * K - 1) * norm;
                        a2 = (1 - V / Q * K + K * K) * norm;
                        b1 = a1;
                        b2 = (1 - 1 / Q * K + K * K) * norm;
                }
                else      // cut
                {
                        norm = 1 / (1 + V / Q * K + K * K);
                        a0 = (1 + 1 / Q * K + K * K) * norm;
                        a1 = 2 * (K * K - 1) * norm;
                        a2 = (1 - 1 / Q * K + K * K) * norm;
                        b1 = a1;
                        b2 = (1 - V / Q * K + K * K) * norm;
                }

                break;

        case bq_type_lowshelf:
                if (coeff_p->peak_gain >= 0)       // boost
                {
                        norm = 1 / (1 + sqrt(2) * K + K * K);
                        a0 = (1 + sqrt(2 * V) * K + V * K * K) * norm;
                        a1 = 2 * (V * K * K - 1) * norm;
                        a2 = (1 - sqrt(2 * V) * K + V * K * K) * norm;
                        b1 = 2 * (K * K - 1) * norm;
                        b2 = (1 - sqrt(2) * K + K * K) * norm;
                }
                else      // cut
                {
                        norm = 1 / (1 + sqrt(2 * V) * K + V * K * K);
                        a0 = (1 + sqrt(2) * K + K * K) * norm;
                        a1 = 2 * (K * K - 1) * norm;
                        a2 = (1 - sqrt(2) * K + K * K) * norm;
                        b1 = 2 * (V * K * K - 1) * norm;
                        b2 = (1 - sqrt(2 * V) * K + V * K * K) * norm;
                }

                break;

        case bq_type_highshelf:
                if (coeff_p->peak_gain >= 0)       // boost
                {
                        norm = 1 / (1 + sqrt(2) * K + K * K);
                        a0 = (V + sqrt(2 * V) * K + K * K) * norm;
                        a1 = 2 * (K * K - V) * norm;
                        a2 = (V - sqrt(2 * V) * K + K * K) * norm;
                        b1 = 2 * (K * K - 1) * norm;
                        b2 = (1 - sqrt(2) * K + K * K) * norm;
                }
                else      // cut
                {
                        norm = 1 / (V + sqrt(2 * V) * K + K * K);
                        a0 = (1 + sqrt(2) * K + K * K) * norm;
                        a1 = 2 * (K * K - 1) * norm;
                        a2 = (1 - sqrt(2) * K + K * K) * norm;
                        b1 = 2 * (K * K - V) * norm;
                        b2 = (V - sqrt(2 * V) * K + K * K) * norm;
                }

                break;
        }

        coeff_p->a0 = a0;
        coeff_p->a1 = a1;
        coeff_p->a2 = a2;
        coeff_p->b1 = b1;
        coeff_p->b2 = b2;
        return;
}


float  biquad_process(bq_coeff_p coeff_p,float in)
{
        double out = in *  coeff_p->a0 +  coeff_p->z1;
        coeff_p->z1 = in * coeff_p->a1 + coeff_p->z2 - coeff_p->b1 * out;
        coeff_p->z2 = in * coeff_p->a2 - coeff_p->b2 * out;
        return out;
}



3 例子:
        bq_coeff_t bsf;
        bq_coeff_t hpf;
        bq_coeff_t lpf;
        biquad_config(&bsf,bq_type_notch, 50,250,0.7071, 6.0);//配置一个陷波器,FC 50Hz,采样频率250Hz,Q=0.7071,Gain=6
        biquad_config(&hpf,bq_type_highpass, 0.6,250,0.7071, 6.0);//配置一个高通滤波器,FC 0.6Hz,采样频率250Hz,Q=0.7071,Gain=6
        biquad_config(&lpf,bq_type_lowpass, 35,250,0.7071, 6.0);//配置一个低通滤波器,FC35Hz,采样频率250Hz,Q=0.7071,Gain=6
        calc_biquad(&bsf);
        calc_biquad(&hpf);
        calc_biquad(&lpf);
        for(int idx=0;idx<LEN;idx++)
        {
        bsf_out[idx]=biquad_process(&bsf,raw_in[idx]);
        hpf_out[idx]=biquad_process(&hpf,bsf_out[idx]);
        lpf_out[idx]=biquad_process(&lpf,hpf_out[idx]);
        }
        for(int idx=0;idx<LEN;idx++)
        {
        printf("raw=%6d,bsf=%6d,hpf=%6d,lpf=%6d\r\n",raw_in[idx],(int)bsf_out[idx],(int)hpf_out[idx],(int)lpf_out[idx]);
        }

22222_20211220-2158.png

biquad_c  .rar

#3 Re: 全志 SOC » 《MangoPi-MQ 麻雀D1s上手教程》Tina系统编译烧录及基础分析 » 2021-12-20 21:53:41

感谢楼主,写的很详细。自己试了下没点亮,晚上学习下你的再试试

#4 Re: 全志 SOC » 兄弟们,MangoPi-麻雀MQ已成功量产 » 2021-12-15 11:56:51

我的还在路上。。。。。。。。。。。。。

#6 ST/STM8/STM8S/STM8L » 最新版modbusPoll7.1.0 和ModbusSlave 6.2.0 软件及序列号 » 2020-10-02 21:38:16

vjcmain
回复: 0

注意上面的软件都是64bit 的 下载地址:http://www.modbustools.com/download.html

key
ModbusPoll rev 7.1.0 sn:5A5742575C5D10
ModbusSlave rev 6.2.0 sn:5455415451475662



调modbus 用上了这两个软件,比较好用,分享给大家


Modbus Master RTU/ASCII Component for .NET  8stdgazf7gjlcsq9kopqfubni4B42
Modbus Master TCP/IP Component for .NET        cbiplmfshp3zedhal8o6fbrro53A6

下载地址:
WSMBT: Modbus master .NET control for C#, VB and managed C++.
Supports Modbus TCP/IP

WSMBS: Modbus master .NET control for C#, VB and managed C++.
Supports Modbus RTU/ASCII

key 使用方法。
在初始化的时候加上:
在控件初始化的时候加上下列代码:
wsmbsControl1.LicenseKey("8stdgazf7gjlcsq9kopqfubni4B42");



WSMBTSetup.rar

WSMBSSetup.rar
ModbusSlaveSetup64Bit.rar

ModbusPollSetup64Bit.rar

#7 Re: 全志 SOC » F1C100S的Keil裸机USB+LCD+PWM+GPIO工程搞定,修复GNU工具链BUG » 2020-10-02 21:29:37

谢谢分享!之前荔枝派一直动不起来,就是想要这样的工程,下载下来研究一下

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn