うなりを生成

Files at this revision

API Documentation at this revision

Comitter:
k0050288
Date:
Tue Jun 26 06:27:08 2018 +0000
Commit message:
??????

Changed in this revision

sinc.cpp Show annotated file Show diff for this revision Revisions of this file
sinc.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 66d8d7360022 sinc.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sinc.cpp	Tue Jun 26 06:27:08 2018 +0000
@@ -0,0 +1,33 @@
+/*
+* うなりを生成する
+*/
+#include "sinc.h"
+
+#define M_PI 3.141592653589793
+
+sinc::sinc()
+{
+    
+}
+
+void sinc::init()
+{
+    generate();
+}
+
+void sinc::generate()
+{
+    //int    fre_1 = 39750;
+    //int    fre_2 = 40250;
+    int    fre_1 = 39750;
+    int    fre_2 = 40250;
+    
+    double changeToLSB   = 4096 / 3.3;                    // 1LSB = 0.80566mV (12bit)
+    
+    for(int i = 0; i < BUFFER_SIZE; i++) {
+        double ome_1 = 2 * M_PI * fre_1 * (i + BUFFER_SIZE)/(BUFFER_SIZE*1000/2);  // omega_1 = 2*pi*f_1
+        double ome_2 = 2 * M_PI * fre_2 * (i + BUFFER_SIZE)/(BUFFER_SIZE*1000/2);  // omega_2 = 2*pi*f_2
+        // 0 ~ 4095
+        buffer[i] = (uint16_t)(changeToLSB * (AMPLITUDE * (sin((ome_1 + M_PI)) + sin(ome_2)) + OFFSET));
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 66d8d7360022 sinc.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sinc.h	Tue Jun 26 06:27:08 2018 +0000
@@ -0,0 +1,26 @@
+/*
+* うなりを生成する
+*/
+
+#ifndef SINC_H
+#define SINC_H
+
+#include <math.h>
+#include <stdint.h>
+
+#define BUFFER_SIZE   2000
+#define AMPLITUDE     0.75  // 3.3V * amplitude
+#define OFFSET        1.6
+
+class sinc {
+private:
+    void generate();
+public:
+    uint16_t buffer[BUFFER_SIZE];
+    
+    sinc();
+    
+    void init();
+    };
+
+#endif
\ No newline at end of file