![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cutoff frequency variable LPF by IIR 6th-order Butterworth filter for ST Nucleo F401RE.
Dependencies: UIT_IIR_Filter UIT_ACM1602NI UITDSP_ADDA mbed UIT_AQM1602
Diff: main.cpp
- Revision:
- 1:e9b451a71ebf
- Parent:
- 0:a9412b9e85b7
- Child:
- 3:4086d5ad6e7a
--- a/main.cpp Thu Oct 23 06:44:40 2014 +0000 +++ b/main.cpp Mon Nov 10 06:07:42 2014 +0000 @@ -3,7 +3,7 @@ // A0: Signal to be filtered // A2: Value which controls cutoff frequency // -// 2014/10/23, Copyright (c) 2014 MIKAMI, Naoki +// 2014/11/10, Copyright (c) 2014 MIKAMI, Naoki //-------------------------------------------------------------- #include "mbed.h" @@ -68,30 +68,40 @@ // fc: cutoff frequency, 200 -- 1000 Hz float fc = 800.0f*(a2_/4095.6f) + 200.0f; - if (fabs(fc - fc1) > 10.0f) + if (sw1_ == 0) { - printf("fc = %4d\r\n", int(fc+0.5f)); - char str[18]; - sprintf(str, "fc = %4d Hz", int(fc+0.5f)); - lcd.SetXY(0, 0); - lcd.WriteString(str); - fc1 = fc; + printf("Through\r\n"); + lcd.WriteStringXY("Through ", 0, 0); + wait(0.2f); + lcd.ClearLine(0); + fc1 = 0; + } + else + { + if (fabs(fc - fc1) > 10.0f) + { + printf("fc = %4d\r\n", int(fc+0.5f)); + char str[18]; + sprintf(str, "fc = %4d Hz", int(fc+0.5f)); + lcd.WriteStringXY(str, 0, 0); + fc1 = fc; - // Design new coefficients based on new fc - BiliearDesign::Coefs coefsLpf[ORDER/2]; - float g0; - lpfDsgn.Execute(fc, coefsLpf, g0); + // Design new coefficients based on new fc + BiliearDesign::Coefs coefsLpf[ORDER/2]; + float g0; + lpfDsgn.Execute(fc, coefsLpf, g0); - // Update new coefficients - Biquad::Coefs coefsIir[ORDER/2]; - for (int n=0; n<ORDER/2; n++) - { - coefsIir[n].a1 = coefsLpf[n].a1; - coefsIir[n].a2 = coefsLpf[n].a2; - coefsIir[n].b1 = coefsLpf[n].b1; - coefsIir[n].b2 = 1.0f; + // Update new coefficients + Biquad::Coefs coefsIir[ORDER/2]; + for (int n=0; n<ORDER/2; n++) + { + coefsIir[n].a1 = coefsLpf[n].a1; + coefsIir[n].a2 = coefsLpf[n].a2; + coefsIir[n].b1 = coefsLpf[n].b1; + coefsIir[n].b2 = 1.0f; + } + iirLpf_.SetCoefs(g0, coefsIir); } - iirLpf_.SetCoefs(g0, coefsIir); } wait(0.1f); }