Cutoff frequency variable LPF, HPF, BPF, and BRF by FIR 160th-order filter.

Dependencies:   UIT_ACM1602NI UITDSP_ADDA mbed UIT_AQM1602

Revision:
1:58271fae2e01
Parent:
0:ca94cfc90365
Child:
3:24b6aa1a19ba
--- a/main.cpp	Mon Dec 08 08:14:48 2014 +0000
+++ b/main.cpp	Tue Dec 09 06:04:35 2014 +0000
@@ -1,11 +1,10 @@
 //------------------------------------------------------------------------------
-// Cutoff frequency variable LPF and HPF,
-// center frequency variable BPF and BRF by FIR 160th-order filter
+// Cutoff frequency variable LPF, HPF, BPF and BRF by FIR 160th-order filter
 //      A0: Signal to be filtered
 //      A2: Value which controls cutoff frequency
 //
 //      1: LPF, 3: HPF, 5: BPF, 7: BRF, even: through
-// 2014/12/07, Copyright (c) 2014 MIKAMI, Naoki
+// 2014/12/09, Copyright (c) 2014 MIKAMI, Naoki
 //------------------------------------------------------------------------------
 
 #include "mbed.h"
@@ -32,15 +31,13 @@
 DigitalIn sw8_(D5, PullDown);
 
 WindowingDesign design_(ORDER_, FS_);
-DigitalOut dOut_(D7);
 
 uint16_t a2_ = 0;   // Inputted data from A2 pin
 
 // Interrupt service routine for ADC
 void AdcIsr()
 {   
-    dOut_.write(1);
-    xn_[0] = myAdc_.Read();   // Read from A0
+    xn_[0] = myAdc_.Read();     // Read from A0
 
     myAdc_.Select3rdChannel();  // Select A2   
     myAdc_.SoftStart();         // ADC start for A2 input
@@ -64,7 +61,6 @@
     myAdc_.Select1stChannel();      // Select A0
     myAdc_.ClearPending_EnableIRQ();// Clear pending interrupt
                                     // and enable ADC_IRQn
-    dOut_.write(0);
 }
 
 int main()
@@ -81,9 +77,6 @@
     float fc1 = 0;
     while (true)
     {
-        // fc: cutoff or center frequency, 200 -- 2000 Hz
-        float fc = 1800.0f*(a2_/4095.6f) + 200.0f;
-
         int sw = (sw8_ << 3) | (sw4_ << 2) | (sw2_ << 1) | sw1_;
         if (sw1_ == 0)
         {
@@ -96,38 +89,36 @@
         }
         else
         {
+            // fc: cutoff or center frequency, 200 -- 2000 Hz
+            float fc = 1800.0f*(a2_/4095.6f) + 200.0f;
+
             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, 1);
+                fc1 = fc;
 
-                if (sw == 1)
+                switch (sw)
                 {
-                    printf("LPF\r\n");
-                    lcd.WriteStringXY("LPF", 0, 0);
-                    design_.Design(ORDER_, WindowingDesign::LPF, fc, 0, hm_);
-                }
-                if (sw == 3)
-                {
-                    printf("HPF\r\n");
-                    lcd.WriteStringXY("HPF", 0, 0);
-                    design_.Design(ORDER_, WindowingDesign::HPF, fc, 0, hm_);
+                    case 1: printf("LPF\r\n");
+                            lcd.WriteStringXY("LPF", 0, 0);
+                            design_.Design(ORDER_, design_.LPF, fc, 0, hm_);
+                            break;
+                    case 3: printf("HPF\r\n");
+                            lcd.WriteStringXY("HPF", 0, 0);
+                            design_.Design(ORDER_, design_.HPF, fc, 0, hm_);
+                            break;
+                    case 5: printf("BPF\r\n");
+                            lcd.WriteStringXY("BPF", 0, 0);
+                            design_.Design(ORDER_, design_.BPF, fc-100, fc+100, hm_);
+                            break;
+                    case 7: printf("BRF\r\n");
+                            lcd.WriteStringXY("BRF", 0, 0);
+                            design_.Design(ORDER_, design_.BRF, fc-100, fc+100, hm_);
+                            break;
                 }
-                if (sw == 5)
-                {
-                    printf("BPF\r\n");
-                    lcd.WriteStringXY("BPF", 0, 0);
-                    design_.Design(ORDER_, WindowingDesign::BPF, fc-100, fc+100, hm_);
-                }
-                if (sw == 7)
-                {
-                    printf("BRF\r\n");
-                    lcd.WriteStringXY("BRF", 0, 0);
-                    design_.Design(ORDER_, WindowingDesign::BRF, fc-100, fc+100, hm_);
-                }
-                fc1 = fc;
             }
         }
         wait(0.1f);