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

Dependencies:   UIT_ACM1602NI UITDSP_ADDA mbed UIT_AQM1602

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Sat Jul 25 06:36:06 2015 +0000
Parent:
2:7b8a5b9de72c
Commit message:
4

Changed in this revision

UITDSP_ADDA.lib Show annotated file Show diff for this revision Revisions of this file
UIT_ACM1602NI.lib Show annotated file Show diff for this revision Revisions of this file
UIT_ADDA.lib Show diff for this revision Revisions of this file
UIT_AQM1602.lib Show annotated file Show diff for this revision Revisions of this file
WindowingDesign/WindowingDesign.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp 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
diff -r 7b8a5b9de72c -r 24b6aa1a19ba UITDSP_ADDA.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UITDSP_ADDA.lib	Sat Jul 25 06:36:06 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MikamiUitOpen/code/UITDSP_ADDA/#543daa087bd5
diff -r 7b8a5b9de72c -r 24b6aa1a19ba UIT_ACM1602NI.lib
--- a/UIT_ACM1602NI.lib	Tue Dec 09 06:10:08 2014 +0000
+++ b/UIT_ACM1602NI.lib	Sat Jul 25 06:36:06 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/MikamiUitOpen/code/UIT_ACM1602NI/#b4f73f5851fb
+http://mbed.org/users/MikamiUitOpen/code/UIT_ACM1602NI/#b7c761c179c9
diff -r 7b8a5b9de72c -r 24b6aa1a19ba UIT_ADDA.lib
--- a/UIT_ADDA.lib	Tue Dec 09 06:10:08 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/MikamiUitOpen/code/UIT_ADDA/#479d18a09e87
diff -r 7b8a5b9de72c -r 24b6aa1a19ba UIT_AQM1602.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UIT_AQM1602.lib	Sat Jul 25 06:36:06 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MikamiUitOpen/code/UIT_AQM1602/#c943f05b7843
diff -r 7b8a5b9de72c -r 24b6aa1a19ba WindowingDesign/WindowingDesign.cpp
--- a/WindowingDesign/WindowingDesign.cpp	Tue Dec 09 06:10:08 2014 +0000
+++ b/WindowingDesign/WindowingDesign.cpp	Sat Jul 25 06:36:06 2015 +0000
@@ -31,7 +31,7 @@
         if (pb == HPF) fC_ = 0.5f*FS_ - fc1;
         
         float w0 = PI_FS_*(fc1 + fc2);
-        if ((pb == BPF) || (pb == BPF))
+        if ((pb == BPF) || (pb == BRF))
             fC_ = 0.5f*fabs(fc2 - fc1);    
 
         if (order != order_)
diff -r 7b8a5b9de72c -r 24b6aa1a19ba main.cpp
--- a/main.cpp	Tue Dec 09 06:10:08 2014 +0000
+++ b/main.cpp	Sat Jul 25 06:36:06 2015 +0000
@@ -4,32 +4,36 @@
 //      A2: Value which controls cutoff frequency
 //
 //      1: LPF, 3: HPF, 5: BPF, 7: BRF, even: through
-// 2014/12/09, Copyright (c) 2014 MIKAMI, Naoki
+// 2015/07/25, Copyright (c) 2015 MIKAMI, Naoki
 //------------------------------------------------------------------------------
 
-#include "mbed.h"
-
 #include "ADC_Interrupt.hpp"    // for ADC using interrupt
-#include "DAC_MCP4922.hpp"      // for DAC MCP4922
-#include "ACM1602NI.hpp"        // for LCD display
+#include "DAC_MCP4921.hpp"      // for DAC MCP4921, MCP4922
+using namespace Mikami;
 
 #include "WindowingDesign.hpp"  // for design of FIR filter
 
-using namespace Mikami;
+// ACM1602Ni を使う場合は次の define 文をコメントにすること
+#define AQM1602
+
+#ifdef AQM1602
+#include "AQM1602.hpp"
+Aqm1602 Lcd_;
+#else
+#include "ACM1602NI.hpp"
+Acm1602Ni Lcd_;
+#endif
 
 const int FS_ = 16000;          // Sampling frequency: 16 kHz
 ADC_Intr myAdc_(A0, FS_, A1, A2);
-DAC_MCP4922 myDac_;
+DAC_MCP4921 myDac_;
 
 const int ORDER_ = 160;
 float hm_[ORDER_/2+1];
 float xn_[ORDER_+1];
 
-DigitalIn sw1_(D2, PullDown);
-DigitalIn sw2_(D3, PullDown);
-DigitalIn sw4_(D4, PullDown);
-DigitalIn sw8_(D5, PullDown);
-
+BusIn sws_(D2, D3, D4, D5);
+int sw_;
 WindowingDesign design_(ORDER_, FS_);
 
 uint16_t a2_ = 0;   // Inputted data from A2 pin
@@ -52,8 +56,10 @@
             xn_[k] = xn_[k-1];  // move input signals
     //-----------------------------------------
 
-    if (sw1_ == 0) myDac_.Write(xn_[0]);    // Using no filter
-    else           myDac_.Write(yn);        // Using filter
+    if ((sw_ & 0x01) == 0)
+        myDac_.Write(xn_[0]);    // Using no filter
+    else
+        myDac_.Write(yn);        // Using filter
 
     // Read value which controls cutoff frequency
     a2_ = myAdc_.ReadWait_u16();
@@ -63,11 +69,12 @@
                                     // and enable ADC_IRQn
 }
 
+void printfLcdDesign(WindowingDesign::Type pb, char str[], int f1, int f2 = 0);
+
 int main()
 {
     myDac_.ScfClockTim3(670000);    // cutoff frequency: 6.7 kHz
-
-    Acm1602Ni lcd;  // objetc for display using LCD
+    sws_.mode(PullDown);
 
     // Clear buffer in FIR filter
     for (int n=0; n<=ORDER_; n++)
@@ -77,14 +84,14 @@
     float fc1 = 0;
     while (true)
     {
-        int sw = (sw8_ << 3) | (sw4_ << 2) | (sw2_ << 1) | sw1_;
-        if (sw1_ == 0)
+        sw_ = sws_.read();
+        if ((sw_ & 0x01) == 0)
         {
             printf("Through\r\n");
-            lcd.ClearLine(1);
-            lcd.WriteStringXY("Through         ", 0, 0);
+            Lcd_.ClearLine(1);
+            Lcd_.WriteStringXY("Through         ", 0, 0);
             wait(0.2f);
-            lcd.ClearLine(0);           
+            Lcd_.ClearLine(0);           
             fc1 = 0;
         }
         else
@@ -94,29 +101,17 @@
 
             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;
 
-                switch (sw)
+                switch (sw_)
                 {
-                    case 1: printf("LPF\r\n");
-                            lcd.WriteStringXY("LPF", 0, 0);
-                            design_.Design(ORDER_, design_.LPF, fc, 0, hm_);
+                    case 1: printfLcdDesign(design_.LPF, "LPF", fc+0.5f);
                             break;
-                    case 3: printf("HPF\r\n");
-                            lcd.WriteStringXY("HPF", 0, 0);
-                            design_.Design(ORDER_, design_.HPF, fc, 0, hm_);
+                    case 3: printfLcdDesign(design_.HPF, "HPF", fc+0.5f);
                             break;
-                    case 5: printf("BPF\r\n");
-                            lcd.WriteStringXY("BPF", 0, 0);
-                            design_.Design(ORDER_, design_.BPF, fc-100, fc+100, hm_);
+                    case 5: printfLcdDesign(design_.BPF, "BPF", fc-100, fc+100);
                             break;
-                    case 7: printf("BRF\r\n");
-                            lcd.WriteStringXY("BRF", 0, 0);
-                            design_.Design(ORDER_, design_.BRF, fc-100, fc+100, hm_);
+                    case 7: printfLcdDesign(design_.BRF, "BRF", fc-150, fc+150);
                             break;
                 }
             }
@@ -124,3 +119,23 @@
         wait(0.1f);
     }
 }
+
+void printfLcdDesign(WindowingDesign::Type pb, char str[], int f1, int f2)
+{
+    printf(((string)str+"\r\n").c_str());
+    Lcd_.WriteStringXY(str, 0, 0);
+    char strFc[17];
+    if (f2 == 0)
+    {
+        printf("fc = %4d Hz\r\n", f1);
+        sprintf(strFc, "fc: %4d Hz", f1);
+    }
+    else
+    {
+        printf("fc = %4d, %4d Hz\r\n", f1, f2);
+        sprintf(strFc, "fc: %4d,%4d Hz", f1, f2);
+    }
+    Lcd_.WriteStringXY(strFc, 0, 1);
+
+    design_.Design(ORDER_, pb, f1, f2, hm_);
+}
diff -r 7b8a5b9de72c -r 24b6aa1a19ba mbed.bld
--- a/mbed.bld	Tue Dec 09 06:10:08 2014 +0000
+++ b/mbed.bld	Sat Jul 25 06:36:06 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file