うなりを生成

Committer:
k0050288
Date:
Tue Jun 26 06:27:08 2018 +0000
Revision:
0:66d8d7360022
??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
k0050288 0:66d8d7360022 1 /*
k0050288 0:66d8d7360022 2 * うなりを生成する
k0050288 0:66d8d7360022 3 */
k0050288 0:66d8d7360022 4 #include "sinc.h"
k0050288 0:66d8d7360022 5
k0050288 0:66d8d7360022 6 #define M_PI 3.141592653589793
k0050288 0:66d8d7360022 7
k0050288 0:66d8d7360022 8 sinc::sinc()
k0050288 0:66d8d7360022 9 {
k0050288 0:66d8d7360022 10
k0050288 0:66d8d7360022 11 }
k0050288 0:66d8d7360022 12
k0050288 0:66d8d7360022 13 void sinc::init()
k0050288 0:66d8d7360022 14 {
k0050288 0:66d8d7360022 15 generate();
k0050288 0:66d8d7360022 16 }
k0050288 0:66d8d7360022 17
k0050288 0:66d8d7360022 18 void sinc::generate()
k0050288 0:66d8d7360022 19 {
k0050288 0:66d8d7360022 20 //int fre_1 = 39750;
k0050288 0:66d8d7360022 21 //int fre_2 = 40250;
k0050288 0:66d8d7360022 22 int fre_1 = 39750;
k0050288 0:66d8d7360022 23 int fre_2 = 40250;
k0050288 0:66d8d7360022 24
k0050288 0:66d8d7360022 25 double changeToLSB = 4096 / 3.3; // 1LSB = 0.80566mV (12bit)
k0050288 0:66d8d7360022 26
k0050288 0:66d8d7360022 27 for(int i = 0; i < BUFFER_SIZE; i++) {
k0050288 0:66d8d7360022 28 double ome_1 = 2 * M_PI * fre_1 * (i + BUFFER_SIZE)/(BUFFER_SIZE*1000/2); // omega_1 = 2*pi*f_1
k0050288 0:66d8d7360022 29 double ome_2 = 2 * M_PI * fre_2 * (i + BUFFER_SIZE)/(BUFFER_SIZE*1000/2); // omega_2 = 2*pi*f_2
k0050288 0:66d8d7360022 30 // 0 ~ 4095
k0050288 0:66d8d7360022 31 buffer[i] = (uint16_t)(changeToLSB * (AMPLITUDE * (sin((ome_1 + M_PI)) + sin(ome_2)) + OFFSET));
k0050288 0:66d8d7360022 32 }
k0050288 0:66d8d7360022 33 }