V001. 2017_11_30 10:21 Working code from Tuesday's lab session.

Dependencies:   mbed-rtos mbed

Fork of 2017_11_28_ELEC347_Coursework by Chris Hills

DSP Coursework ELEC347 2017-2018 Group members: Matthew Thewsey, Thomas Morris, Samuel Waggett, Christopher Hills .

Revision:
0:d39a06ca6bf1
Child:
1:b088b771a591
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filter.cpp	Thu Nov 23 10:41:18 2017 +0000
@@ -0,0 +1,71 @@
+#include "Filter.hpp"
+
+FILTER::FILTER(int Fs, int Fo, int Boost, int Q) //Constuctor
+{
+    _Fs = Fs;
+    this-> _Fo = Fo;
+    this-> _Boost = Boost;
+    this-> _Q = Q;
+
+    // B - Upnominator coefficients
+    _b0 = 0.0201;
+    _b1 = 0.0;
+    _b2 = -0.0402;
+    _b3 = 0.0;
+    _b4 = 0.0201;
+
+    // A - Denominator coefficients
+    _a0 = 1.0000;
+    _a1 = -2.5494;
+    _a2 = 3.2024;
+    _a3 = -2.0359;
+    _a4 = 0.6414;
+
+    _centreTap = 1;
+    _G = 0;
+    _k = 0;
+    _Wo = 0;
+
+    _xn = 0;     //this value is the input value
+    _xnm1 = 0;
+    _xnm2 = 0;
+    _xnm3 = 0;
+    _xnm4 = 0;
+
+    _yn = 0;
+    _ynm1 = 0;
+    _ynm2 = 0;
+    _ynm3 = 0;
+    _ynm4 = 0;
+}
+
+FILTER::~FILTER() {}
+
+void FILTER::setvalue(int RAW_input)
+{
+            
+    _xn = RAW_input;
+    _centreTap = _xn*_b0 + _xnm1*_b1 + _xnm2*_b2 + _xnm3*_b3 + _xnm4*_b4;  //IIR Filter
+    _yn = _centreTap*_a0 - _a1*_ynm1 - _a2*_ynm2  - _a3*_ynm3 - _a4*_ynm4; //Result in yn
+
+    FilterOutput=_yn+0.5f;       //Output resultant to DAC. Again MBED uses 0.0 to 1.0 float!!!!!! and Offset to give 0 to 3V3 range
+
+    //THESE NEED TO BE LOADED IN THIS ORDER OTHERWISE ALL xnm VALUES WILL BECOME THE SAME AS xn
+    _xnm4 = _xnm3;
+    _xnm3 = _xnm2;
+    _xnm2 = _xnm1;
+    _xnm1 = _xn;
+
+    //THESE NEED TO BE LOADED IN THIS ORDER OTHERWISE ALL ynm VALUES WILL BECOME THE SAME AS yn
+    _ynm4 = _ynm3;
+    _ynm3 = _ynm2;
+    _ynm2 = _ynm1;
+    _ynm1 = _yn;
+
+}
+
+float FILTER::getvalue(void)
+{
+    return FilterOutput;  
+}
+