The experiment using this program is introduced on "Interface" No.12, CQ publishing Co.,Ltd, 2014. 本プログラムを使った実験は,CQ出版社のインターフェース 2014年12月号で紹介しています.

Dependencies:   DSProcessingIO mbed

Files at this revision

API Documentation at this revision

Comitter:
CQpub0Mikami
Date:
Tue Jul 15 08:21:30 2014 +0000
Child:
1:bd300d649b1f
Commit message:
1

Changed in this revision

DSProcessingIO.lib Show annotated file Show diff for this revision Revisions of this file
FIR_LPF_Symmetry.cpp Show annotated file Show diff for this revision Revisions of this file
FIR_Symmetry.hpp Show annotated file Show diff for this revision Revisions of this file
FirBaseClass.hpp Show annotated file Show diff for this revision Revisions of this file
coefficientsSym_200.hpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DSProcessingIO.lib	Tue Jul 15 08:21:30 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/CQpub0Mikami/code/DSProcessingIO/#c3f647a89947
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FIR_LPF_Symmetry.cpp	Tue Jul 15 08:21:30 2014 +0000
@@ -0,0 +1,40 @@
+//--------------------------------------------------------------
+// FIR filter: Even order, Symmetric structure of direct form
+//
+// Copyright (c) 2014 MIKAMI, Naoki,  2014/06/20 
+//--------------------------------------------------------------
+
+#include "mbed.h"
+#include "AdcInternal.hpp"
+#include "MCP4922Single.hpp"
+#include "coefficientsSym_200.hpp"
+#include "FIR_Symmetry.hpp"
+
+using namespace Mikami;
+
+// sampling frequency
+const float FS_ = 10.0e3f;
+
+Adc adc_(A0);
+Dac dacA_(Dac::DAC_A);
+Ticker timer_;           // for timer interrupt
+
+FirSymmetry<ORDER_> lpf(hm_);
+
+void TimerIsr()
+{
+    float xn = adc_.Read(); // input
+
+    // Execute FIR filter
+    float yn = lpf.Execute(xn);
+
+    dacA_.Write(yn);        // output
+}
+
+int main()
+{
+    timer_.attach_us(&TimerIsr, 1.0e6f/FS_);
+
+    while (true) {}    // infinite loop
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FIR_Symmetry.hpp	Tue Jul 15 08:21:30 2014 +0000
@@ -0,0 +1,36 @@
+//--------------------------------------------------------------
+// FIR filter ---- Symmetry structure
+// Copyright (c) 2014 MIKAMI, Naoki, 2014/06/20
+//--------------------------------------------------------------
+
+#ifndef FIR_SYMMETRY_HPP
+#define FIR_SYMMETRY_HPP
+
+#include "mbed.h"
+#include "FirBaseClass.hpp"
+
+namespace Mikami
+{
+    template<int order> class FirSymmetry : public FirBase<order>
+    {
+    public:
+        using FirBase<order>::xn_;
+
+        FirSymmetry(const float hk[]) : FirBase<order>(hk) {}
+
+        virtual float Execute(float xin)
+        {
+            xn_[0] = xin;
+
+            float acc = hm_[order/2]*xn_[order/2];
+            for (int k=0; k<order/2; k++)
+                acc = acc + hm_[k]*(xn_[k] + xn_[order-k]);
+
+            FirBase<order>::Move();
+                
+            return acc;
+        }
+    };
+}
+#endif  // FIR_SYMMETRY_HPP
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FirBaseClass.hpp	Tue Jul 15 08:21:30 2014 +0000
@@ -0,0 +1,41 @@
+//--------------------------------------------------------------
+// Virtual base class for FIR filter
+// Copyright (c) 2014 MIKAMI, Naoki, 2014/06/22
+//--------------------------------------------------------------
+
+#ifndef FIR_BASE_HPP
+#define FIR_BASE_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    template<int order> class FirBase
+    {
+    private:
+        FirBase(const FirBase&);
+        FirBase& operator=(const FirBase&);
+    protected:
+        const float *const hm_; // pointer for filter coefficients
+        float xn_[order+1];     // buffer for inputs
+
+        // Constructor
+        FirBase(const float hk[]) : hm_(hk) { Clear(); }
+        
+        // Execute filter
+        virtual float Execute(float xin) = 0;
+
+        // Move signals in xn_[]
+        void Move()
+        {
+            for (int k=order; k>0; k--)
+                xn_[k] = xn_[k-1];  // move input signals
+        }
+    public:
+        void Clear()
+        {
+            for (int k=0; k<=order; k++) xn_[k] = 0.0;
+        }
+    };
+}
+#endif  // FIR_BASE_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coefficientsSym_200.hpp	Tue Jul 15 08:21:30 2014 +0000
@@ -0,0 +1,48 @@
+//--------------------------------------------------------------
+//  Coefficients for FIR filter, Order = 200
+//--------------------------------------------------------------
+
+//                                   Band1       Band2
+// Lower band edge frequency (kHz) 0.000000    0.600000
+// Upper band edge frequency (kHz) 0.500000    5.000000
+// Gain                            1.000000    0.000000
+// Weighting                       1.000000    1.000000
+// Deviation                       0.009734    0.009734
+// Deviation [dB]                  0.084139  -40.234188
+
+const int ORDER_ = 200;
+const float hm_[ORDER_/2+1] = {
+         -3.566292E-03f,  2.335185E-03f,  1.917338E-03f,
+          1.681921E-03f,  1.522689E-03f,  1.364066E-03f,
+          1.157961E-03f,  8.803014E-04f,  5.296940E-04f,
+          1.236180E-04f, -3.047488E-04f, -7.123405E-04f,
+         -1.051992E-03f, -1.279654E-03f, -1.360180E-03f,
+         -1.273725E-03f, -1.018960E-03f, -6.155554E-04f,
+         -1.029986E-04f,  4.621914E-04f,  1.013316E-03f,
+          1.480161E-03f,  1.798055E-03f,  1.916527E-03f,
+          1.805744E-03f,  1.463100E-03f,  9.143371E-04f,
+          2.130115E-04f, -5.640853E-04f, -1.326518E-03f,
+         -1.978121E-03f, -2.430574E-03f, -2.613837E-03f,
+         -2.486610E-03f, -2.043447E-03f, -1.317959E-03f,
+         -3.802110E-04f,  6.680631E-04f,  1.704594E-03f,
+          2.600376E-03f,  3.235972E-03f,  3.515095E-03f,
+          3.379365E-03f,  2.817894E-03f,  1.872141E-03f,
+          6.322899E-04f, -7.684087E-04f, -2.167773E-03f,
+         -3.393601E-03f, -4.284042E-03f, -4.705797E-03f,
+         -4.577073E-03f, -3.875274E-03f, -2.648668E-03f,
+         -1.012065E-03f,  8.616354E-04f,  2.758435E-03f,
+          4.447251E-03f,  5.706155E-03f,  6.350451E-03f,
+          6.257734E-03f,  5.386359E-03f,  3.786968E-03f,
+          1.602121E-03f, -9.435526E-04f, -3.565645E-03f,
+         -5.948320E-03f, -7.781761E-03f, -8.797770E-03f,
+         -8.807067E-03f, -7.725336E-03f, -5.594939E-03f,
+         -2.585050E-03f,  1.010693E-03f,  4.809328E-03f,
+          8.361672E-03f,  1.121444E-02f,  1.295107E-02f,
+          1.324389E-02f,  1.191081E-02f,  8.934171E-03f,
+          4.488148E-03f, -1.062401E-03f, -7.182842E-03f,
+         -1.321242E-02f, -1.841506E-02f, -2.204769E-02f,
+         -2.343209E-02f, -2.202840E-02f, -1.749386E-02f,
+         -9.730157E-03f,  1.092382E-03f,  1.453105E-02f,
+          2.989524E-02f,  4.629194E-02f,  6.269474E-02f,
+          7.802411E-02f,  9.123583E-02f,  1.014078E-01f,
+          1.078185E-01f,  1.100078E-01f};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 15 08:21:30 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file