diff --git a/src/fft.c b/src/fft.c index 9b7f6de..7b41171 100644 --- a/src/fft.c +++ b/src/fft.c @@ -33,7 +33,7 @@ void complex_to_absolute(value_type *re, value_type *im, value_type *result) { for(i = 0; i < DATALEN; i++) { - result[i] = sqrt( re[i]*re[i] + im[i]*im[i] ); + result[i] = sqrtf( re[i]*re[i] + im[i]*im[i] ); } } @@ -135,7 +135,7 @@ value_type get_energy_in_band(value_type *fft, uint32_t minFreq, uint32_t maxFre return energy; } -value_type get_energy_density_in_band(value_type *fft, uint32_t minFreq, uint32_t maxFreq) { +value_type get_spectral_density_in_band(value_type *fft, uint32_t minFreq, uint32_t maxFreq) { int firstBlock = minFreq * BLOCK_LEN / SAMPLE_RATE; int lastBlock = maxFreq * BLOCK_LEN / SAMPLE_RATE; int i; @@ -149,7 +149,7 @@ value_type get_energy_density_in_band(value_type *fft, uint32_t minFreq, uint32_ energy /= (lastBlock - firstBlock); } - energy *= (float)BLOCK_LEN / (float)SAMPLE_RATE; // normalze to Hz + energy *= sqrtf((float)BLOCK_LEN / (float)SAMPLE_RATE); // normalze to sqrt(Hz) return energy; } diff --git a/src/fft.h b/src/fft.h index 6013eb4..170f6da 100644 --- a/src/fft.h +++ b/src/fft.h @@ -11,6 +11,8 @@ void apply_hanning(value_type *dftinput); void fft_transform(value_type *samples, value_type *resultRe, value_type *resultIm); uint32_t find_loudest_frequency(value_type *absFFT); value_type get_energy_in_band(value_type *fft, uint32_t minFreq, uint32_t maxFreq); -value_type get_energy_density_in_band(value_type *fft, uint32_t minFreq, uint32_t maxFreq); + +// calculate the spectral density in V/sqrt(Hz) +value_type get_spectral_density_in_band(value_type *fft, uint32_t minFreq, uint32_t maxFreq); #endif // FFT_H diff --git a/src/fft_config.h b/src/fft_config.h index 25accf6..ba03f72 100644 --- a/src/fft_config.h +++ b/src/fft_config.h @@ -2,7 +2,7 @@ #define CONFIG_H // FFT transformation parameters -#define FFT_EXPONENT 9 // ATTENTION: when you change this, run gen_lut.py with this value as argument +#define FFT_EXPONENT 11 // ATTENTION: when you change this, run gen_lut.py with this value as argument #define BLOCK_LEN (1 << FFT_EXPONENT) // 2^FFT_EXPONENT #define SAMPLE_RATE 48000 #define DATALEN (BLOCK_LEN / 2) diff --git a/src/lut.c b/src/lut.c index e0eccb5..36db998 100644 --- a/src/lut.c +++ b/src/lut.c @@ -20,7 +20,11 @@ value_type sin_lut7[128] = {0, -0.0245412285, -0.0490676743, -0.0735645636, -0.0 value_type sin_lut8[256] = {0, -0.0122715383, -0.0245412285, -0.0368072229, -0.0490676743, -0.0613207363, -0.0735645636, -0.0857973123, -0.0980171403, -0.1102222073, -0.1224106752, -0.1345807085, -0.1467304745, -0.1588581433, -0.1709618888, -0.1830398880, -0.1950903220, -0.2071113762, -0.2191012402, -0.2310581083, -0.2429801799, -0.2548656596, -0.2667127575, -0.2785196894, -0.2902846773, -0.3020059493, -0.3136817404, -0.3253102922, -0.3368898534, -0.3484186802, -0.3598950365, -0.3713171940, -0.3826834324, -0.3939920401, -0.4052413140, -0.4164295601, -0.4275550934, -0.4386162385, -0.4496113297, -0.4605387110, -0.4713967368, -0.4821837721, -0.4928981922, -0.5035383837, -0.5141027442, -0.5245896827, -0.5349976199, -0.5453249884, -0.5555702330, -0.5657318108, -0.5758081914, -0.5857978575, -0.5956993045, -0.6055110414, -0.6152315906, -0.6248594881, -0.6343932842, -0.6438315429, -0.6531728430, -0.6624157776, -0.6715589548, -0.6806009978, -0.6895405447, -0.6983762494, -0.7071067812, -0.7157308253, -0.7242470830, -0.7326542717, -0.7409511254, -0.7491363945, -0.7572088465, -0.7651672656, -0.7730104534, -0.7807372286, -0.7883464276, -0.7958369046, -0.8032075315, -0.8104571983, -0.8175848132, -0.8245893028, -0.8314696123, -0.8382247056, -0.8448535652, -0.8513551931, -0.8577286100, -0.8639728561, -0.8700869911, -0.8760700942, -0.8819212643, -0.8876396204, -0.8932243012, -0.8986744657, -0.9039892931, -0.9091679831, -0.9142097557, -0.9191138517, -0.9238795325, -0.9285060805, -0.9329927988, -0.9373390119, -0.9415440652, -0.9456073254, -0.9495281806, -0.9533060404, -0.9569403357, -0.9604305194, -0.9637760658, -0.9669764710, -0.9700312532, -0.9729399522, -0.9757021300, -0.9783173707, -0.9807852804, -0.9831054874, -0.9852776424, -0.9873014182, -0.9891765100, -0.9909026354, -0.9924795346, -0.9939069700, -0.9951847267, -0.9963126122, -0.9972904567, -0.9981181129, -0.9987954562, -0.9993223846, -0.9996988187, -0.9999247018, -1.0000000000, -0.9999247018, -0.9996988187, -0.9993223846, -0.9987954562, -0.9981181129, -0.9972904567, -0.9963126122, -0.9951847267, -0.9939069700, -0.9924795346, -0.9909026354, -0.9891765100, -0.9873014182, -0.9852776424, -0.9831054874, -0.9807852804, -0.9783173707, -0.9757021300, -0.9729399522, -0.9700312532, -0.9669764710, -0.9637760658, -0.9604305194, -0.9569403357, -0.9533060404, -0.9495281806, -0.9456073254, -0.9415440652, -0.9373390119, -0.9329927988, -0.9285060805, -0.9238795325, -0.9191138517, -0.9142097557, -0.9091679831, -0.9039892931, -0.8986744657, -0.8932243012, -0.8876396204, -0.8819212643, -0.8760700942, -0.8700869911, -0.8639728561, -0.8577286100, -0.8513551931, -0.8448535652, -0.8382247056, -0.8314696123, -0.8245893028, -0.8175848132, -0.8104571983, -0.8032075315, -0.7958369046, -0.7883464276, -0.7807372286, -0.7730104534, -0.7651672656, -0.7572088465, -0.7491363945, -0.7409511254, -0.7326542717, -0.7242470830, -0.7157308253, -0.7071067812, -0.6983762494, -0.6895405447, -0.6806009978, -0.6715589548, -0.6624157776, -0.6531728430, -0.6438315429, -0.6343932842, -0.6248594881, -0.6152315906, -0.6055110414, -0.5956993045, -0.5857978575, -0.5758081914, -0.5657318108, -0.5555702330, -0.5453249884, -0.5349976199, -0.5245896827, -0.5141027442, -0.5035383837, -0.4928981922, -0.4821837721, -0.4713967368, -0.4605387110, -0.4496113297, -0.4386162385, -0.4275550934, -0.4164295601, -0.4052413140, -0.3939920401, -0.3826834324, -0.3713171940, -0.3598950365, -0.3484186802, -0.3368898534, -0.3253102922, -0.3136817404, -0.3020059493, -0.2902846773, -0.2785196894, -0.2667127575, -0.2548656596, -0.2429801799, -0.2310581083, -0.2191012402, -0.2071113762, -0.1950903220, -0.1830398880, -0.1709618888, -0.1588581433, -0.1467304745, -0.1345807085, -0.1224106752, -0.1102222073, -0.0980171403, -0.0857973123, -0.0735645636, -0.0613207363, -0.0490676743, -0.0368072229, -0.0245412285, -0.0122715383}; -value_type *sin_lut[9] = {sin_lut0, sin_lut1, sin_lut2, sin_lut3, sin_lut4, sin_lut5, sin_lut6, sin_lut7, sin_lut8}; +value_type sin_lut9[512] = {0, -0.0061358846, -0.0122715383, -0.0184067299, -0.0245412285, -0.0306748032, -0.0368072229, -0.0429382569, -0.0490676743, -0.0551952443, -0.0613207363, -0.0674439196, -0.0735645636, -0.0796824380, -0.0857973123, -0.0919089565, -0.0980171403, -0.1041216339, -0.1102222073, -0.1163186309, -0.1224106752, -0.1284981108, -0.1345807085, -0.1406582393, -0.1467304745, -0.1527971853, -0.1588581433, -0.1649131205, -0.1709618888, -0.1770042204, -0.1830398880, -0.1890686641, -0.1950903220, -0.2011046348, -0.2071113762, -0.2131103199, -0.2191012402, -0.2250839114, -0.2310581083, -0.2370236060, -0.2429801799, -0.2489276057, -0.2548656596, -0.2607941179, -0.2667127575, -0.2726213554, -0.2785196894, -0.2844075372, -0.2902846773, -0.2961508882, -0.3020059493, -0.3078496400, -0.3136817404, -0.3195020308, -0.3253102922, -0.3311063058, -0.3368898534, -0.3426607173, -0.3484186802, -0.3541635254, -0.3598950365, -0.3656129978, -0.3713171940, -0.3770074102, -0.3826834324, -0.3883450467, -0.3939920401, -0.3996241998, -0.4052413140, -0.4108431711, -0.4164295601, -0.4220002708, -0.4275550934, -0.4330938189, -0.4386162385, -0.4441221446, -0.4496113297, -0.4550835871, -0.4605387110, -0.4659764958, -0.4713967368, -0.4767992301, -0.4821837721, -0.4875501601, -0.4928981922, -0.4982276670, -0.5035383837, -0.5088301425, -0.5141027442, -0.5193559902, -0.5245896827, -0.5298036247, -0.5349976199, -0.5401714727, -0.5453249884, -0.5504579729, -0.5555702330, -0.5606615762, -0.5657318108, -0.5707807459, -0.5758081914, -0.5808139581, -0.5857978575, -0.5907597019, -0.5956993045, -0.6006164794, -0.6055110414, -0.6103828063, -0.6152315906, -0.6200572118, -0.6248594881, -0.6296382389, -0.6343932842, -0.6391244449, -0.6438315429, -0.6485144010, -0.6531728430, -0.6578066933, -0.6624157776, -0.6669999223, -0.6715589548, -0.6760927036, -0.6806009978, -0.6850836678, -0.6895405447, -0.6939714609, -0.6983762494, -0.7027547445, -0.7071067812, -0.7114321957, -0.7157308253, -0.7200025080, -0.7242470830, -0.7284643904, -0.7326542717, -0.7368165689, -0.7409511254, -0.7450577854, -0.7491363945, -0.7531867990, -0.7572088465, -0.7612023855, -0.7651672656, -0.7691033376, -0.7730104534, -0.7768884657, -0.7807372286, -0.7845565972, -0.7883464276, -0.7921065773, -0.7958369046, -0.7995372691, -0.8032075315, -0.8068475535, -0.8104571983, -0.8140363297, -0.8175848132, -0.8211025150, -0.8245893028, -0.8280450453, -0.8314696123, -0.8348628750, -0.8382247056, -0.8415549774, -0.8448535652, -0.8481203448, -0.8513551931, -0.8545579884, -0.8577286100, -0.8608669386, -0.8639728561, -0.8670462455, -0.8700869911, -0.8730949784, -0.8760700942, -0.8790122264, -0.8819212643, -0.8847970984, -0.8876396204, -0.8904487232, -0.8932243012, -0.8959662498, -0.8986744657, -0.9013488470, -0.9039892931, -0.9065957045, -0.9091679831, -0.9117060320, -0.9142097557, -0.9166790599, -0.9191138517, -0.9215140393, -0.9238795325, -0.9262102421, -0.9285060805, -0.9307669611, -0.9329927988, -0.9351835099, -0.9373390119, -0.9394592236, -0.9415440652, -0.9435934582, -0.9456073254, -0.9475855910, -0.9495281806, -0.9514350210, -0.9533060404, -0.9551411683, -0.9569403357, -0.9587034749, -0.9604305194, -0.9621214043, -0.9637760658, -0.9653944417, -0.9669764710, -0.9685220943, -0.9700312532, -0.9715038910, -0.9729399522, -0.9743393828, -0.9757021300, -0.9770281427, -0.9783173707, -0.9795697657, -0.9807852804, -0.9819638691, -0.9831054874, -0.9842100924, -0.9852776424, -0.9863080972, -0.9873014182, -0.9882575677, -0.9891765100, -0.9900582103, -0.9909026354, -0.9917097537, -0.9924795346, -0.9932119492, -0.9939069700, -0.9945645707, -0.9951847267, -0.9957674145, -0.9963126122, -0.9968202993, -0.9972904567, -0.9977230666, -0.9981181129, -0.9984755806, -0.9987954562, -0.9990777278, -0.9993223846, -0.9995294175, -0.9996988187, -0.9998305818, -0.9999247018, -0.9999811753, -1.0000000000, -0.9999811753, -0.9999247018, -0.9998305818, -0.9996988187, -0.9995294175, -0.9993223846, -0.9990777278, -0.9987954562, -0.9984755806, -0.9981181129, -0.9977230666, -0.9972904567, -0.9968202993, -0.9963126122, -0.9957674145, -0.9951847267, -0.9945645707, -0.9939069700, -0.9932119492, -0.9924795346, -0.9917097537, -0.9909026354, -0.9900582103, -0.9891765100, -0.9882575677, -0.9873014182, -0.9863080972, -0.9852776424, -0.9842100924, -0.9831054874, -0.9819638691, -0.9807852804, -0.9795697657, -0.9783173707, -0.9770281427, -0.9757021300, -0.9743393828, -0.9729399522, -0.9715038910, -0.9700312532, -0.9685220943, -0.9669764710, -0.9653944417, -0.9637760658, -0.9621214043, -0.9604305194, -0.9587034749, -0.9569403357, -0.9551411683, -0.9533060404, -0.9514350210, -0.9495281806, -0.9475855910, -0.9456073254, -0.9435934582, -0.9415440652, -0.9394592236, -0.9373390119, -0.9351835099, -0.9329927988, -0.9307669611, -0.9285060805, -0.9262102421, -0.9238795325, -0.9215140393, -0.9191138517, -0.9166790599, -0.9142097557, -0.9117060320, -0.9091679831, -0.9065957045, -0.9039892931, -0.9013488470, -0.8986744657, -0.8959662498, -0.8932243012, -0.8904487232, -0.8876396204, -0.8847970984, -0.8819212643, -0.8790122264, -0.8760700942, -0.8730949784, -0.8700869911, -0.8670462455, -0.8639728561, -0.8608669386, -0.8577286100, -0.8545579884, -0.8513551931, -0.8481203448, -0.8448535652, -0.8415549774, -0.8382247056, -0.8348628750, -0.8314696123, -0.8280450453, -0.8245893028, -0.8211025150, -0.8175848132, -0.8140363297, -0.8104571983, -0.8068475535, -0.8032075315, -0.7995372691, -0.7958369046, -0.7921065773, -0.7883464276, -0.7845565972, -0.7807372286, -0.7768884657, -0.7730104534, -0.7691033376, -0.7651672656, -0.7612023855, -0.7572088465, -0.7531867990, -0.7491363945, -0.7450577854, -0.7409511254, -0.7368165689, -0.7326542717, -0.7284643904, -0.7242470830, -0.7200025080, -0.7157308253, -0.7114321957, -0.7071067812, -0.7027547445, -0.6983762494, -0.6939714609, -0.6895405447, -0.6850836678, -0.6806009978, -0.6760927036, -0.6715589548, -0.6669999223, -0.6624157776, -0.6578066933, -0.6531728430, -0.6485144010, -0.6438315429, -0.6391244449, -0.6343932842, -0.6296382389, -0.6248594881, -0.6200572118, -0.6152315906, -0.6103828063, -0.6055110414, -0.6006164794, -0.5956993045, -0.5907597019, -0.5857978575, -0.5808139581, -0.5758081914, -0.5707807459, -0.5657318108, -0.5606615762, -0.5555702330, -0.5504579729, -0.5453249884, -0.5401714727, -0.5349976199, -0.5298036247, -0.5245896827, -0.5193559902, -0.5141027442, -0.5088301425, -0.5035383837, -0.4982276670, -0.4928981922, -0.4875501601, -0.4821837721, -0.4767992301, -0.4713967368, -0.4659764958, -0.4605387110, -0.4550835871, -0.4496113297, -0.4441221446, -0.4386162385, -0.4330938189, -0.4275550934, -0.4220002708, -0.4164295601, -0.4108431711, -0.4052413140, -0.3996241998, -0.3939920401, -0.3883450467, -0.3826834324, -0.3770074102, -0.3713171940, -0.3656129978, -0.3598950365, -0.3541635254, -0.3484186802, -0.3426607173, -0.3368898534, -0.3311063058, -0.3253102922, -0.3195020308, -0.3136817404, -0.3078496400, -0.3020059493, -0.2961508882, -0.2902846773, -0.2844075372, -0.2785196894, -0.2726213554, -0.2667127575, -0.2607941179, -0.2548656596, -0.2489276057, -0.2429801799, -0.2370236060, -0.2310581083, -0.2250839114, -0.2191012402, -0.2131103199, -0.2071113762, -0.2011046348, -0.1950903220, -0.1890686641, -0.1830398880, -0.1770042204, -0.1709618888, -0.1649131205, -0.1588581433, -0.1527971853, -0.1467304745, -0.1406582393, -0.1345807085, -0.1284981108, -0.1224106752, -0.1163186309, -0.1102222073, -0.1041216339, -0.0980171403, -0.0919089565, -0.0857973123, -0.0796824380, -0.0735645636, -0.0674439196, -0.0613207363, -0.0551952443, -0.0490676743, -0.0429382569, -0.0368072229, -0.0306748032, -0.0245412285, -0.0184067299, -0.0122715383, -0.0061358846}; + +value_type sin_lut10[1024] = {0, -0.0030679568, -0.0061358846, -0.0092037548, -0.0122715383, -0.0153392063, -0.0184067299, -0.0214740803, -0.0245412285, -0.0276081458, -0.0306748032, -0.0337411719, -0.0368072229, -0.0398729276, -0.0429382569, -0.0460031821, -0.0490676743, -0.0521317047, -0.0551952443, -0.0582582645, -0.0613207363, -0.0643826309, -0.0674439196, -0.0705045734, -0.0735645636, -0.0766238614, -0.0796824380, -0.0827402645, -0.0857973123, -0.0888535526, -0.0919089565, -0.0949634953, -0.0980171403, -0.1010698628, -0.1041216339, -0.1071724250, -0.1102222073, -0.1132709522, -0.1163186309, -0.1193652148, -0.1224106752, -0.1254549834, -0.1284981108, -0.1315400287, -0.1345807085, -0.1376201216, -0.1406582393, -0.1436950332, -0.1467304745, -0.1497645347, -0.1527971853, -0.1558283977, -0.1588581433, -0.1618863938, -0.1649131205, -0.1679382950, -0.1709618888, -0.1739838734, -0.1770042204, -0.1800229014, -0.1830398880, -0.1860551517, -0.1890686641, -0.1920803970, -0.1950903220, -0.1980984107, -0.2011046348, -0.2041089661, -0.2071113762, -0.2101118369, -0.2131103199, -0.2161067971, -0.2191012402, -0.2220936210, -0.2250839114, -0.2280720832, -0.2310581083, -0.2340419586, -0.2370236060, -0.2400030224, -0.2429801799, -0.2459550503, -0.2489276057, -0.2518978182, -0.2548656596, -0.2578311022, -0.2607941179, -0.2637546790, -0.2667127575, -0.2696683256, -0.2726213554, -0.2755718193, -0.2785196894, -0.2814649379, -0.2844075372, -0.2873474595, -0.2902846773, -0.2932191627, -0.2961508882, -0.2990798263, -0.3020059493, -0.3049292297, -0.3078496400, -0.3107671527, -0.3136817404, -0.3165933756, -0.3195020308, -0.3224076788, -0.3253102922, -0.3282098436, -0.3311063058, -0.3339996514, -0.3368898534, -0.3397768844, -0.3426607173, -0.3455413250, -0.3484186802, -0.3512927561, -0.3541635254, -0.3570309612, -0.3598950365, -0.3627557244, -0.3656129978, -0.3684668300, -0.3713171940, -0.3741640630, -0.3770074102, -0.3798472089, -0.3826834324, -0.3855160538, -0.3883450467, -0.3911703843, -0.3939920401, -0.3968099874, -0.3996241998, -0.4024346509, -0.4052413140, -0.4080441629, -0.4108431711, -0.4136383122, -0.4164295601, -0.4192168884, -0.4220002708, -0.4247796812, -0.4275550934, -0.4303264813, -0.4330938189, -0.4358570799, -0.4386162385, -0.4413712687, -0.4441221446, -0.4468688402, -0.4496113297, -0.4523495872, -0.4550835871, -0.4578133036, -0.4605387110, -0.4632597836, -0.4659764958, -0.4686888220, -0.4713967368, -0.4741002147, -0.4767992301, -0.4794937577, -0.4821837721, -0.4848692480, -0.4875501601, -0.4902264833, -0.4928981922, -0.4955652618, -0.4982276670, -0.5008853826, -0.5035383837, -0.5061866453, -0.5088301425, -0.5114688504, -0.5141027442, -0.5167317990, -0.5193559902, -0.5219752929, -0.5245896827, -0.5271991348, -0.5298036247, -0.5324031279, -0.5349976199, -0.5375870763, -0.5401714727, -0.5427507849, -0.5453249884, -0.5478940592, -0.5504579729, -0.5530167056, -0.5555702330, -0.5581185312, -0.5606615762, -0.5631993440, -0.5657318108, -0.5682589527, -0.5707807459, -0.5732971667, -0.5758081914, -0.5783137964, -0.5808139581, -0.5833086529, -0.5857978575, -0.5882815482, -0.5907597019, -0.5932322950, -0.5956993045, -0.5981607070, -0.6006164794, -0.6030665985, -0.6055110414, -0.6079497850, -0.6103828063, -0.6128100824, -0.6152315906, -0.6176473079, -0.6200572118, -0.6224612794, -0.6248594881, -0.6272518155, -0.6296382389, -0.6320187359, -0.6343932842, -0.6367618612, -0.6391244449, -0.6414810128, -0.6438315429, -0.6461760130, -0.6485144010, -0.6508466850, -0.6531728430, -0.6554928530, -0.6578066933, -0.6601143421, -0.6624157776, -0.6647109782, -0.6669999223, -0.6692825883, -0.6715589548, -0.6738290004, -0.6760927036, -0.6783500431, -0.6806009978, -0.6828455464, -0.6850836678, -0.6873153409, -0.6895405447, -0.6917592584, -0.6939714609, -0.6961771315, -0.6983762494, -0.7005687939, -0.7027547445, -0.7049340804, -0.7071067812, -0.7092728264, -0.7114321957, -0.7135848688, -0.7157308253, -0.7178700451, -0.7200025080, -0.7221281939, -0.7242470830, -0.7263591551, -0.7284643904, -0.7305627692, -0.7326542717, -0.7347388781, -0.7368165689, -0.7388873245, -0.7409511254, -0.7430079521, -0.7450577854, -0.7471006060, -0.7491363945, -0.7511651319, -0.7531867990, -0.7552013769, -0.7572088465, -0.7592091890, -0.7612023855, -0.7631884173, -0.7651672656, -0.7671389119, -0.7691033376, -0.7710605243, -0.7730104534, -0.7749531066, -0.7768884657, -0.7788165124, -0.7807372286, -0.7826505962, -0.7845565972, -0.7864552136, -0.7883464276, -0.7902302214, -0.7921065773, -0.7939754776, -0.7958369046, -0.7976908409, -0.7995372691, -0.8013761717, -0.8032075315, -0.8050313311, -0.8068475535, -0.8086561816, -0.8104571983, -0.8122505866, -0.8140363297, -0.8158144108, -0.8175848132, -0.8193475201, -0.8211025150, -0.8228497814, -0.8245893028, -0.8263210628, -0.8280450453, -0.8297612338, -0.8314696123, -0.8331701647, -0.8348628750, -0.8365477272, -0.8382247056, -0.8398937942, -0.8415549774, -0.8432082396, -0.8448535652, -0.8464909388, -0.8481203448, -0.8497417680, -0.8513551931, -0.8529606049, -0.8545579884, -0.8561473284, -0.8577286100, -0.8593018184, -0.8608669386, -0.8624239561, -0.8639728561, -0.8655136241, -0.8670462455, -0.8685707060, -0.8700869911, -0.8715950867, -0.8730949784, -0.8745866523, -0.8760700942, -0.8775452902, -0.8790122264, -0.8804708891, -0.8819212643, -0.8833633387, -0.8847970984, -0.8862225301, -0.8876396204, -0.8890483559, -0.8904487232, -0.8918407094, -0.8932243012, -0.8945994856, -0.8959662498, -0.8973245807, -0.8986744657, -0.9000158920, -0.9013488470, -0.9026733182, -0.9039892931, -0.9052967593, -0.9065957045, -0.9078861165, -0.9091679831, -0.9104412923, -0.9117060320, -0.9129621904, -0.9142097557, -0.9154487161, -0.9166790599, -0.9179007756, -0.9191138517, -0.9203182767, -0.9215140393, -0.9227011283, -0.9238795325, -0.9250492408, -0.9262102421, -0.9273625257, -0.9285060805, -0.9296408958, -0.9307669611, -0.9318842656, -0.9329927988, -0.9340925504, -0.9351835099, -0.9362656672, -0.9373390119, -0.9384035341, -0.9394592236, -0.9405060706, -0.9415440652, -0.9425731976, -0.9435934582, -0.9446048373, -0.9456073254, -0.9466009131, -0.9475855910, -0.9485613499, -0.9495281806, -0.9504860739, -0.9514350210, -0.9523750127, -0.9533060404, -0.9542280951, -0.9551411683, -0.9560452513, -0.9569403357, -0.9578264130, -0.9587034749, -0.9595715131, -0.9604305194, -0.9612804858, -0.9621214043, -0.9629532669, -0.9637760658, -0.9645897933, -0.9653944417, -0.9661900034, -0.9669764710, -0.9677538371, -0.9685220943, -0.9692812354, -0.9700312532, -0.9707721407, -0.9715038910, -0.9722264971, -0.9729399522, -0.9736442497, -0.9743393828, -0.9750253451, -0.9757021300, -0.9763697313, -0.9770281427, -0.9776773578, -0.9783173707, -0.9789481753, -0.9795697657, -0.9801821360, -0.9807852804, -0.9813791933, -0.9819638691, -0.9825393023, -0.9831054874, -0.9836624192, -0.9842100924, -0.9847485018, -0.9852776424, -0.9857975092, -0.9863080972, -0.9868094018, -0.9873014182, -0.9877841416, -0.9882575677, -0.9887216920, -0.9891765100, -0.9896220175, -0.9900582103, -0.9904850843, -0.9909026354, -0.9913108598, -0.9917097537, -0.9920993131, -0.9924795346, -0.9928504145, -0.9932119492, -0.9935641355, -0.9939069700, -0.9942404495, -0.9945645707, -0.9948793308, -0.9951847267, -0.9954807555, -0.9957674145, -0.9960447009, -0.9963126122, -0.9965711458, -0.9968202993, -0.9970600703, -0.9972904567, -0.9975114561, -0.9977230666, -0.9979252862, -0.9981181129, -0.9983015449, -0.9984755806, -0.9986402182, -0.9987954562, -0.9989412932, -0.9990777278, -0.9992047586, -0.9993223846, -0.9994306046, -0.9995294175, -0.9996188225, -0.9996988187, -0.9997694054, -0.9998305818, -0.9998823475, -0.9999247018, -0.9999576446, -0.9999811753, -0.9999952938, -1.0000000000, -0.9999952938, -0.9999811753, -0.9999576446, -0.9999247018, -0.9998823475, -0.9998305818, -0.9997694054, -0.9996988187, -0.9996188225, -0.9995294175, -0.9994306046, -0.9993223846, -0.9992047586, -0.9990777278, -0.9989412932, -0.9987954562, -0.9986402182, -0.9984755806, -0.9983015449, -0.9981181129, -0.9979252862, -0.9977230666, -0.9975114561, -0.9972904567, -0.9970600703, -0.9968202993, -0.9965711458, -0.9963126122, -0.9960447009, -0.9957674145, -0.9954807555, -0.9951847267, -0.9948793308, -0.9945645707, -0.9942404495, -0.9939069700, -0.9935641355, -0.9932119492, -0.9928504145, -0.9924795346, -0.9920993131, -0.9917097537, -0.9913108598, -0.9909026354, -0.9904850843, -0.9900582103, -0.9896220175, -0.9891765100, -0.9887216920, -0.9882575677, -0.9877841416, -0.9873014182, -0.9868094018, -0.9863080972, -0.9857975092, -0.9852776424, -0.9847485018, -0.9842100924, -0.9836624192, -0.9831054874, -0.9825393023, -0.9819638691, -0.9813791933, -0.9807852804, -0.9801821360, -0.9795697657, -0.9789481753, -0.9783173707, -0.9776773578, -0.9770281427, -0.9763697313, -0.9757021300, -0.9750253451, -0.9743393828, -0.9736442497, -0.9729399522, -0.9722264971, -0.9715038910, -0.9707721407, -0.9700312532, -0.9692812354, -0.9685220943, -0.9677538371, -0.9669764710, -0.9661900034, -0.9653944417, -0.9645897933, -0.9637760658, -0.9629532669, -0.9621214043, -0.9612804858, -0.9604305194, -0.9595715131, -0.9587034749, -0.9578264130, -0.9569403357, -0.9560452513, -0.9551411683, -0.9542280951, -0.9533060404, -0.9523750127, -0.9514350210, -0.9504860739, -0.9495281806, -0.9485613499, -0.9475855910, -0.9466009131, -0.9456073254, -0.9446048373, -0.9435934582, -0.9425731976, -0.9415440652, -0.9405060706, -0.9394592236, -0.9384035341, -0.9373390119, -0.9362656672, -0.9351835099, -0.9340925504, -0.9329927988, -0.9318842656, -0.9307669611, -0.9296408958, -0.9285060805, -0.9273625257, -0.9262102421, -0.9250492408, -0.9238795325, -0.9227011283, -0.9215140393, -0.9203182767, -0.9191138517, -0.9179007756, -0.9166790599, -0.9154487161, -0.9142097557, -0.9129621904, -0.9117060320, -0.9104412923, -0.9091679831, -0.9078861165, -0.9065957045, -0.9052967593, -0.9039892931, -0.9026733182, -0.9013488470, -0.9000158920, -0.8986744657, -0.8973245807, -0.8959662498, -0.8945994856, -0.8932243012, -0.8918407094, -0.8904487232, -0.8890483559, -0.8876396204, -0.8862225301, -0.8847970984, -0.8833633387, -0.8819212643, -0.8804708891, -0.8790122264, -0.8775452902, -0.8760700942, -0.8745866523, -0.8730949784, -0.8715950867, -0.8700869911, -0.8685707060, -0.8670462455, -0.8655136241, -0.8639728561, -0.8624239561, -0.8608669386, -0.8593018184, -0.8577286100, -0.8561473284, -0.8545579884, -0.8529606049, -0.8513551931, -0.8497417680, -0.8481203448, -0.8464909388, -0.8448535652, -0.8432082396, -0.8415549774, -0.8398937942, -0.8382247056, -0.8365477272, -0.8348628750, -0.8331701647, -0.8314696123, -0.8297612338, -0.8280450453, -0.8263210628, -0.8245893028, -0.8228497814, -0.8211025150, -0.8193475201, -0.8175848132, -0.8158144108, -0.8140363297, -0.8122505866, -0.8104571983, -0.8086561816, -0.8068475535, -0.8050313311, -0.8032075315, -0.8013761717, -0.7995372691, -0.7976908409, -0.7958369046, -0.7939754776, -0.7921065773, -0.7902302214, -0.7883464276, -0.7864552136, -0.7845565972, -0.7826505962, -0.7807372286, -0.7788165124, -0.7768884657, -0.7749531066, -0.7730104534, -0.7710605243, -0.7691033376, -0.7671389119, -0.7651672656, -0.7631884173, -0.7612023855, -0.7592091890, -0.7572088465, -0.7552013769, -0.7531867990, -0.7511651319, -0.7491363945, -0.7471006060, -0.7450577854, -0.7430079521, -0.7409511254, -0.7388873245, -0.7368165689, -0.7347388781, -0.7326542717, -0.7305627692, -0.7284643904, -0.7263591551, -0.7242470830, -0.7221281939, -0.7200025080, -0.7178700451, -0.7157308253, -0.7135848688, -0.7114321957, -0.7092728264, -0.7071067812, -0.7049340804, -0.7027547445, -0.7005687939, -0.6983762494, -0.6961771315, -0.6939714609, -0.6917592584, -0.6895405447, -0.6873153409, -0.6850836678, -0.6828455464, -0.6806009978, -0.6783500431, -0.6760927036, -0.6738290004, -0.6715589548, -0.6692825883, -0.6669999223, -0.6647109782, -0.6624157776, -0.6601143421, -0.6578066933, -0.6554928530, -0.6531728430, -0.6508466850, -0.6485144010, -0.6461760130, -0.6438315429, -0.6414810128, -0.6391244449, -0.6367618612, -0.6343932842, -0.6320187359, -0.6296382389, -0.6272518155, -0.6248594881, -0.6224612794, -0.6200572118, -0.6176473079, -0.6152315906, -0.6128100824, -0.6103828063, -0.6079497850, -0.6055110414, -0.6030665985, -0.6006164794, -0.5981607070, -0.5956993045, -0.5932322950, -0.5907597019, -0.5882815482, -0.5857978575, -0.5833086529, -0.5808139581, -0.5783137964, -0.5758081914, -0.5732971667, -0.5707807459, -0.5682589527, -0.5657318108, -0.5631993440, -0.5606615762, -0.5581185312, -0.5555702330, -0.5530167056, -0.5504579729, -0.5478940592, -0.5453249884, -0.5427507849, -0.5401714727, -0.5375870763, -0.5349976199, -0.5324031279, -0.5298036247, -0.5271991348, -0.5245896827, -0.5219752929, -0.5193559902, -0.5167317990, -0.5141027442, -0.5114688504, -0.5088301425, -0.5061866453, -0.5035383837, -0.5008853826, -0.4982276670, -0.4955652618, -0.4928981922, -0.4902264833, -0.4875501601, -0.4848692480, -0.4821837721, -0.4794937577, -0.4767992301, -0.4741002147, -0.4713967368, -0.4686888220, -0.4659764958, -0.4632597836, -0.4605387110, -0.4578133036, -0.4550835871, -0.4523495872, -0.4496113297, -0.4468688402, -0.4441221446, -0.4413712687, -0.4386162385, -0.4358570799, -0.4330938189, -0.4303264813, -0.4275550934, -0.4247796812, -0.4220002708, -0.4192168884, -0.4164295601, -0.4136383122, -0.4108431711, -0.4080441629, -0.4052413140, -0.4024346509, -0.3996241998, -0.3968099874, -0.3939920401, -0.3911703843, -0.3883450467, -0.3855160538, -0.3826834324, -0.3798472089, -0.3770074102, -0.3741640630, -0.3713171940, -0.3684668300, -0.3656129978, -0.3627557244, -0.3598950365, -0.3570309612, -0.3541635254, -0.3512927561, -0.3484186802, -0.3455413250, -0.3426607173, -0.3397768844, -0.3368898534, -0.3339996514, -0.3311063058, -0.3282098436, -0.3253102922, -0.3224076788, -0.3195020308, -0.3165933756, -0.3136817404, -0.3107671527, -0.3078496400, -0.3049292297, -0.3020059493, -0.2990798263, -0.2961508882, -0.2932191627, -0.2902846773, -0.2873474595, -0.2844075372, -0.2814649379, -0.2785196894, -0.2755718193, -0.2726213554, -0.2696683256, -0.2667127575, -0.2637546790, -0.2607941179, -0.2578311022, -0.2548656596, -0.2518978182, -0.2489276057, -0.2459550503, -0.2429801799, -0.2400030224, -0.2370236060, -0.2340419586, -0.2310581083, -0.2280720832, -0.2250839114, -0.2220936210, -0.2191012402, -0.2161067971, -0.2131103199, -0.2101118369, -0.2071113762, -0.2041089661, -0.2011046348, -0.1980984107, -0.1950903220, -0.1920803970, -0.1890686641, -0.1860551517, -0.1830398880, -0.1800229014, -0.1770042204, -0.1739838734, -0.1709618888, -0.1679382950, -0.1649131205, -0.1618863938, -0.1588581433, -0.1558283977, -0.1527971853, -0.1497645347, -0.1467304745, -0.1436950332, -0.1406582393, -0.1376201216, -0.1345807085, -0.1315400287, -0.1284981108, -0.1254549834, -0.1224106752, -0.1193652148, -0.1163186309, -0.1132709522, -0.1102222073, -0.1071724250, -0.1041216339, -0.1010698628, -0.0980171403, -0.0949634953, -0.0919089565, -0.0888535526, -0.0857973123, -0.0827402645, -0.0796824380, -0.0766238614, -0.0735645636, -0.0705045734, -0.0674439196, -0.0643826309, -0.0613207363, -0.0582582645, -0.0551952443, -0.0521317047, -0.0490676743, -0.0460031821, -0.0429382569, -0.0398729276, -0.0368072229, -0.0337411719, -0.0306748032, -0.0276081458, -0.0245412285, -0.0214740803, -0.0184067299, -0.0153392063, -0.0122715383, -0.0092037548, -0.0061358846, -0.0030679568}; + +value_type *sin_lut[11] = {sin_lut0, sin_lut1, sin_lut2, sin_lut3, sin_lut4, sin_lut5, sin_lut6, sin_lut7, sin_lut8, sin_lut9, sin_lut10}; value_type cos_lut0[1] = {1}; value_type cos_lut1[2] = {1, 0.0000000000}; @@ -39,7 +43,11 @@ value_type cos_lut7[128] = {1, 0.9996988187, 0.9987954562, 0.9972904567, 0.99518 value_type cos_lut8[256] = {1, 0.9999247018, 0.9996988187, 0.9993223846, 0.9987954562, 0.9981181129, 0.9972904567, 0.9963126122, 0.9951847267, 0.9939069700, 0.9924795346, 0.9909026354, 0.9891765100, 0.9873014182, 0.9852776424, 0.9831054874, 0.9807852804, 0.9783173707, 0.9757021300, 0.9729399522, 0.9700312532, 0.9669764710, 0.9637760658, 0.9604305194, 0.9569403357, 0.9533060404, 0.9495281806, 0.9456073254, 0.9415440652, 0.9373390119, 0.9329927988, 0.9285060805, 0.9238795325, 0.9191138517, 0.9142097557, 0.9091679831, 0.9039892931, 0.8986744657, 0.8932243012, 0.8876396204, 0.8819212643, 0.8760700942, 0.8700869911, 0.8639728561, 0.8577286100, 0.8513551931, 0.8448535652, 0.8382247056, 0.8314696123, 0.8245893028, 0.8175848132, 0.8104571983, 0.8032075315, 0.7958369046, 0.7883464276, 0.7807372286, 0.7730104534, 0.7651672656, 0.7572088465, 0.7491363945, 0.7409511254, 0.7326542717, 0.7242470830, 0.7157308253, 0.7071067812, 0.6983762494, 0.6895405447, 0.6806009978, 0.6715589548, 0.6624157776, 0.6531728430, 0.6438315429, 0.6343932842, 0.6248594881, 0.6152315906, 0.6055110414, 0.5956993045, 0.5857978575, 0.5758081914, 0.5657318108, 0.5555702330, 0.5453249884, 0.5349976199, 0.5245896827, 0.5141027442, 0.5035383837, 0.4928981922, 0.4821837721, 0.4713967368, 0.4605387110, 0.4496113297, 0.4386162385, 0.4275550934, 0.4164295601, 0.4052413140, 0.3939920401, 0.3826834324, 0.3713171940, 0.3598950365, 0.3484186802, 0.3368898534, 0.3253102922, 0.3136817404, 0.3020059493, 0.2902846773, 0.2785196894, 0.2667127575, 0.2548656596, 0.2429801799, 0.2310581083, 0.2191012402, 0.2071113762, 0.1950903220, 0.1830398880, 0.1709618888, 0.1588581433, 0.1467304745, 0.1345807085, 0.1224106752, 0.1102222073, 0.0980171403, 0.0857973123, 0.0735645636, 0.0613207363, 0.0490676743, 0.0368072229, 0.0245412285, 0.0122715383, 0.0000000000, -0.0122715383, -0.0245412285, -0.0368072229, -0.0490676743, -0.0613207363, -0.0735645636, -0.0857973123, -0.0980171403, -0.1102222073, -0.1224106752, -0.1345807085, -0.1467304745, -0.1588581433, -0.1709618888, -0.1830398880, -0.1950903220, -0.2071113762, -0.2191012402, -0.2310581083, -0.2429801799, -0.2548656596, -0.2667127575, -0.2785196894, -0.2902846773, -0.3020059493, -0.3136817404, -0.3253102922, -0.3368898534, -0.3484186802, -0.3598950365, -0.3713171940, -0.3826834324, -0.3939920401, -0.4052413140, -0.4164295601, -0.4275550934, -0.4386162385, -0.4496113297, -0.4605387110, -0.4713967368, -0.4821837721, -0.4928981922, -0.5035383837, -0.5141027442, -0.5245896827, -0.5349976199, -0.5453249884, -0.5555702330, -0.5657318108, -0.5758081914, -0.5857978575, -0.5956993045, -0.6055110414, -0.6152315906, -0.6248594881, -0.6343932842, -0.6438315429, -0.6531728430, -0.6624157776, -0.6715589548, -0.6806009978, -0.6895405447, -0.6983762494, -0.7071067812, -0.7157308253, -0.7242470830, -0.7326542717, -0.7409511254, -0.7491363945, -0.7572088465, -0.7651672656, -0.7730104534, -0.7807372286, -0.7883464276, -0.7958369046, -0.8032075315, -0.8104571983, -0.8175848132, -0.8245893028, -0.8314696123, -0.8382247056, -0.8448535652, -0.8513551931, -0.8577286100, -0.8639728561, -0.8700869911, -0.8760700942, -0.8819212643, -0.8876396204, -0.8932243012, -0.8986744657, -0.9039892931, -0.9091679831, -0.9142097557, -0.9191138517, -0.9238795325, -0.9285060805, -0.9329927988, -0.9373390119, -0.9415440652, -0.9456073254, -0.9495281806, -0.9533060404, -0.9569403357, -0.9604305194, -0.9637760658, -0.9669764710, -0.9700312532, -0.9729399522, -0.9757021300, -0.9783173707, -0.9807852804, -0.9831054874, -0.9852776424, -0.9873014182, -0.9891765100, -0.9909026354, -0.9924795346, -0.9939069700, -0.9951847267, -0.9963126122, -0.9972904567, -0.9981181129, -0.9987954562, -0.9993223846, -0.9996988187, -0.9999247018}; -value_type *cos_lut[9] = {cos_lut0, cos_lut1, cos_lut2, cos_lut3, cos_lut4, cos_lut5, cos_lut6, cos_lut7, cos_lut8}; +value_type cos_lut9[512] = {1, 0.9999811753, 0.9999247018, 0.9998305818, 0.9996988187, 0.9995294175, 0.9993223846, 0.9990777278, 0.9987954562, 0.9984755806, 0.9981181129, 0.9977230666, 0.9972904567, 0.9968202993, 0.9963126122, 0.9957674145, 0.9951847267, 0.9945645707, 0.9939069700, 0.9932119492, 0.9924795346, 0.9917097537, 0.9909026354, 0.9900582103, 0.9891765100, 0.9882575677, 0.9873014182, 0.9863080972, 0.9852776424, 0.9842100924, 0.9831054874, 0.9819638691, 0.9807852804, 0.9795697657, 0.9783173707, 0.9770281427, 0.9757021300, 0.9743393828, 0.9729399522, 0.9715038910, 0.9700312532, 0.9685220943, 0.9669764710, 0.9653944417, 0.9637760658, 0.9621214043, 0.9604305194, 0.9587034749, 0.9569403357, 0.9551411683, 0.9533060404, 0.9514350210, 0.9495281806, 0.9475855910, 0.9456073254, 0.9435934582, 0.9415440652, 0.9394592236, 0.9373390119, 0.9351835099, 0.9329927988, 0.9307669611, 0.9285060805, 0.9262102421, 0.9238795325, 0.9215140393, 0.9191138517, 0.9166790599, 0.9142097557, 0.9117060320, 0.9091679831, 0.9065957045, 0.9039892931, 0.9013488470, 0.8986744657, 0.8959662498, 0.8932243012, 0.8904487232, 0.8876396204, 0.8847970984, 0.8819212643, 0.8790122264, 0.8760700942, 0.8730949784, 0.8700869911, 0.8670462455, 0.8639728561, 0.8608669386, 0.8577286100, 0.8545579884, 0.8513551931, 0.8481203448, 0.8448535652, 0.8415549774, 0.8382247056, 0.8348628750, 0.8314696123, 0.8280450453, 0.8245893028, 0.8211025150, 0.8175848132, 0.8140363297, 0.8104571983, 0.8068475535, 0.8032075315, 0.7995372691, 0.7958369046, 0.7921065773, 0.7883464276, 0.7845565972, 0.7807372286, 0.7768884657, 0.7730104534, 0.7691033376, 0.7651672656, 0.7612023855, 0.7572088465, 0.7531867990, 0.7491363945, 0.7450577854, 0.7409511254, 0.7368165689, 0.7326542717, 0.7284643904, 0.7242470830, 0.7200025080, 0.7157308253, 0.7114321957, 0.7071067812, 0.7027547445, 0.6983762494, 0.6939714609, 0.6895405447, 0.6850836678, 0.6806009978, 0.6760927036, 0.6715589548, 0.6669999223, 0.6624157776, 0.6578066933, 0.6531728430, 0.6485144010, 0.6438315429, 0.6391244449, 0.6343932842, 0.6296382389, 0.6248594881, 0.6200572118, 0.6152315906, 0.6103828063, 0.6055110414, 0.6006164794, 0.5956993045, 0.5907597019, 0.5857978575, 0.5808139581, 0.5758081914, 0.5707807459, 0.5657318108, 0.5606615762, 0.5555702330, 0.5504579729, 0.5453249884, 0.5401714727, 0.5349976199, 0.5298036247, 0.5245896827, 0.5193559902, 0.5141027442, 0.5088301425, 0.5035383837, 0.4982276670, 0.4928981922, 0.4875501601, 0.4821837721, 0.4767992301, 0.4713967368, 0.4659764958, 0.4605387110, 0.4550835871, 0.4496113297, 0.4441221446, 0.4386162385, 0.4330938189, 0.4275550934, 0.4220002708, 0.4164295601, 0.4108431711, 0.4052413140, 0.3996241998, 0.3939920401, 0.3883450467, 0.3826834324, 0.3770074102, 0.3713171940, 0.3656129978, 0.3598950365, 0.3541635254, 0.3484186802, 0.3426607173, 0.3368898534, 0.3311063058, 0.3253102922, 0.3195020308, 0.3136817404, 0.3078496400, 0.3020059493, 0.2961508882, 0.2902846773, 0.2844075372, 0.2785196894, 0.2726213554, 0.2667127575, 0.2607941179, 0.2548656596, 0.2489276057, 0.2429801799, 0.2370236060, 0.2310581083, 0.2250839114, 0.2191012402, 0.2131103199, 0.2071113762, 0.2011046348, 0.1950903220, 0.1890686641, 0.1830398880, 0.1770042204, 0.1709618888, 0.1649131205, 0.1588581433, 0.1527971853, 0.1467304745, 0.1406582393, 0.1345807085, 0.1284981108, 0.1224106752, 0.1163186309, 0.1102222073, 0.1041216339, 0.0980171403, 0.0919089565, 0.0857973123, 0.0796824380, 0.0735645636, 0.0674439196, 0.0613207363, 0.0551952443, 0.0490676743, 0.0429382569, 0.0368072229, 0.0306748032, 0.0245412285, 0.0184067299, 0.0122715383, 0.0061358846, 0.0000000000, -0.0061358846, -0.0122715383, -0.0184067299, -0.0245412285, -0.0306748032, -0.0368072229, -0.0429382569, -0.0490676743, -0.0551952443, -0.0613207363, -0.0674439196, -0.0735645636, -0.0796824380, -0.0857973123, -0.0919089565, -0.0980171403, -0.1041216339, -0.1102222073, -0.1163186309, -0.1224106752, -0.1284981108, -0.1345807085, -0.1406582393, -0.1467304745, -0.1527971853, -0.1588581433, -0.1649131205, -0.1709618888, -0.1770042204, -0.1830398880, -0.1890686641, -0.1950903220, -0.2011046348, -0.2071113762, -0.2131103199, -0.2191012402, -0.2250839114, -0.2310581083, -0.2370236060, -0.2429801799, -0.2489276057, -0.2548656596, -0.2607941179, -0.2667127575, -0.2726213554, -0.2785196894, -0.2844075372, -0.2902846773, -0.2961508882, -0.3020059493, -0.3078496400, -0.3136817404, -0.3195020308, -0.3253102922, -0.3311063058, -0.3368898534, -0.3426607173, -0.3484186802, -0.3541635254, -0.3598950365, -0.3656129978, -0.3713171940, -0.3770074102, -0.3826834324, -0.3883450467, -0.3939920401, -0.3996241998, -0.4052413140, -0.4108431711, -0.4164295601, -0.4220002708, -0.4275550934, -0.4330938189, -0.4386162385, -0.4441221446, -0.4496113297, -0.4550835871, -0.4605387110, -0.4659764958, -0.4713967368, -0.4767992301, -0.4821837721, -0.4875501601, -0.4928981922, -0.4982276670, -0.5035383837, -0.5088301425, -0.5141027442, -0.5193559902, -0.5245896827, -0.5298036247, -0.5349976199, -0.5401714727, -0.5453249884, -0.5504579729, -0.5555702330, -0.5606615762, -0.5657318108, -0.5707807459, -0.5758081914, -0.5808139581, -0.5857978575, -0.5907597019, -0.5956993045, -0.6006164794, -0.6055110414, -0.6103828063, -0.6152315906, -0.6200572118, -0.6248594881, -0.6296382389, -0.6343932842, -0.6391244449, -0.6438315429, -0.6485144010, -0.6531728430, -0.6578066933, -0.6624157776, -0.6669999223, -0.6715589548, -0.6760927036, -0.6806009978, -0.6850836678, -0.6895405447, -0.6939714609, -0.6983762494, -0.7027547445, -0.7071067812, -0.7114321957, -0.7157308253, -0.7200025080, -0.7242470830, -0.7284643904, -0.7326542717, -0.7368165689, -0.7409511254, -0.7450577854, -0.7491363945, -0.7531867990, -0.7572088465, -0.7612023855, -0.7651672656, -0.7691033376, -0.7730104534, -0.7768884657, -0.7807372286, -0.7845565972, -0.7883464276, -0.7921065773, -0.7958369046, -0.7995372691, -0.8032075315, -0.8068475535, -0.8104571983, -0.8140363297, -0.8175848132, -0.8211025150, -0.8245893028, -0.8280450453, -0.8314696123, -0.8348628750, -0.8382247056, -0.8415549774, -0.8448535652, -0.8481203448, -0.8513551931, -0.8545579884, -0.8577286100, -0.8608669386, -0.8639728561, -0.8670462455, -0.8700869911, -0.8730949784, -0.8760700942, -0.8790122264, -0.8819212643, -0.8847970984, -0.8876396204, -0.8904487232, -0.8932243012, -0.8959662498, -0.8986744657, -0.9013488470, -0.9039892931, -0.9065957045, -0.9091679831, -0.9117060320, -0.9142097557, -0.9166790599, -0.9191138517, -0.9215140393, -0.9238795325, -0.9262102421, -0.9285060805, -0.9307669611, -0.9329927988, -0.9351835099, -0.9373390119, -0.9394592236, -0.9415440652, -0.9435934582, -0.9456073254, -0.9475855910, -0.9495281806, -0.9514350210, -0.9533060404, -0.9551411683, -0.9569403357, -0.9587034749, -0.9604305194, -0.9621214043, -0.9637760658, -0.9653944417, -0.9669764710, -0.9685220943, -0.9700312532, -0.9715038910, -0.9729399522, -0.9743393828, -0.9757021300, -0.9770281427, -0.9783173707, -0.9795697657, -0.9807852804, -0.9819638691, -0.9831054874, -0.9842100924, -0.9852776424, -0.9863080972, -0.9873014182, -0.9882575677, -0.9891765100, -0.9900582103, -0.9909026354, -0.9917097537, -0.9924795346, -0.9932119492, -0.9939069700, -0.9945645707, -0.9951847267, -0.9957674145, -0.9963126122, -0.9968202993, -0.9972904567, -0.9977230666, -0.9981181129, -0.9984755806, -0.9987954562, -0.9990777278, -0.9993223846, -0.9995294175, -0.9996988187, -0.9998305818, -0.9999247018, -0.9999811753}; + +value_type cos_lut10[1024] = {1, 0.9999952938, 0.9999811753, 0.9999576446, 0.9999247018, 0.9998823475, 0.9998305818, 0.9997694054, 0.9996988187, 0.9996188225, 0.9995294175, 0.9994306046, 0.9993223846, 0.9992047586, 0.9990777278, 0.9989412932, 0.9987954562, 0.9986402182, 0.9984755806, 0.9983015449, 0.9981181129, 0.9979252862, 0.9977230666, 0.9975114561, 0.9972904567, 0.9970600703, 0.9968202993, 0.9965711458, 0.9963126122, 0.9960447009, 0.9957674145, 0.9954807555, 0.9951847267, 0.9948793308, 0.9945645707, 0.9942404495, 0.9939069700, 0.9935641355, 0.9932119492, 0.9928504145, 0.9924795346, 0.9920993131, 0.9917097537, 0.9913108598, 0.9909026354, 0.9904850843, 0.9900582103, 0.9896220175, 0.9891765100, 0.9887216920, 0.9882575677, 0.9877841416, 0.9873014182, 0.9868094018, 0.9863080972, 0.9857975092, 0.9852776424, 0.9847485018, 0.9842100924, 0.9836624192, 0.9831054874, 0.9825393023, 0.9819638691, 0.9813791933, 0.9807852804, 0.9801821360, 0.9795697657, 0.9789481753, 0.9783173707, 0.9776773578, 0.9770281427, 0.9763697313, 0.9757021300, 0.9750253451, 0.9743393828, 0.9736442497, 0.9729399522, 0.9722264971, 0.9715038910, 0.9707721407, 0.9700312532, 0.9692812354, 0.9685220943, 0.9677538371, 0.9669764710, 0.9661900034, 0.9653944417, 0.9645897933, 0.9637760658, 0.9629532669, 0.9621214043, 0.9612804858, 0.9604305194, 0.9595715131, 0.9587034749, 0.9578264130, 0.9569403357, 0.9560452513, 0.9551411683, 0.9542280951, 0.9533060404, 0.9523750127, 0.9514350210, 0.9504860739, 0.9495281806, 0.9485613499, 0.9475855910, 0.9466009131, 0.9456073254, 0.9446048373, 0.9435934582, 0.9425731976, 0.9415440652, 0.9405060706, 0.9394592236, 0.9384035341, 0.9373390119, 0.9362656672, 0.9351835099, 0.9340925504, 0.9329927988, 0.9318842656, 0.9307669611, 0.9296408958, 0.9285060805, 0.9273625257, 0.9262102421, 0.9250492408, 0.9238795325, 0.9227011283, 0.9215140393, 0.9203182767, 0.9191138517, 0.9179007756, 0.9166790599, 0.9154487161, 0.9142097557, 0.9129621904, 0.9117060320, 0.9104412923, 0.9091679831, 0.9078861165, 0.9065957045, 0.9052967593, 0.9039892931, 0.9026733182, 0.9013488470, 0.9000158920, 0.8986744657, 0.8973245807, 0.8959662498, 0.8945994856, 0.8932243012, 0.8918407094, 0.8904487232, 0.8890483559, 0.8876396204, 0.8862225301, 0.8847970984, 0.8833633387, 0.8819212643, 0.8804708891, 0.8790122264, 0.8775452902, 0.8760700942, 0.8745866523, 0.8730949784, 0.8715950867, 0.8700869911, 0.8685707060, 0.8670462455, 0.8655136241, 0.8639728561, 0.8624239561, 0.8608669386, 0.8593018184, 0.8577286100, 0.8561473284, 0.8545579884, 0.8529606049, 0.8513551931, 0.8497417680, 0.8481203448, 0.8464909388, 0.8448535652, 0.8432082396, 0.8415549774, 0.8398937942, 0.8382247056, 0.8365477272, 0.8348628750, 0.8331701647, 0.8314696123, 0.8297612338, 0.8280450453, 0.8263210628, 0.8245893028, 0.8228497814, 0.8211025150, 0.8193475201, 0.8175848132, 0.8158144108, 0.8140363297, 0.8122505866, 0.8104571983, 0.8086561816, 0.8068475535, 0.8050313311, 0.8032075315, 0.8013761717, 0.7995372691, 0.7976908409, 0.7958369046, 0.7939754776, 0.7921065773, 0.7902302214, 0.7883464276, 0.7864552136, 0.7845565972, 0.7826505962, 0.7807372286, 0.7788165124, 0.7768884657, 0.7749531066, 0.7730104534, 0.7710605243, 0.7691033376, 0.7671389119, 0.7651672656, 0.7631884173, 0.7612023855, 0.7592091890, 0.7572088465, 0.7552013769, 0.7531867990, 0.7511651319, 0.7491363945, 0.7471006060, 0.7450577854, 0.7430079521, 0.7409511254, 0.7388873245, 0.7368165689, 0.7347388781, 0.7326542717, 0.7305627692, 0.7284643904, 0.7263591551, 0.7242470830, 0.7221281939, 0.7200025080, 0.7178700451, 0.7157308253, 0.7135848688, 0.7114321957, 0.7092728264, 0.7071067812, 0.7049340804, 0.7027547445, 0.7005687939, 0.6983762494, 0.6961771315, 0.6939714609, 0.6917592584, 0.6895405447, 0.6873153409, 0.6850836678, 0.6828455464, 0.6806009978, 0.6783500431, 0.6760927036, 0.6738290004, 0.6715589548, 0.6692825883, 0.6669999223, 0.6647109782, 0.6624157776, 0.6601143421, 0.6578066933, 0.6554928530, 0.6531728430, 0.6508466850, 0.6485144010, 0.6461760130, 0.6438315429, 0.6414810128, 0.6391244449, 0.6367618612, 0.6343932842, 0.6320187359, 0.6296382389, 0.6272518155, 0.6248594881, 0.6224612794, 0.6200572118, 0.6176473079, 0.6152315906, 0.6128100824, 0.6103828063, 0.6079497850, 0.6055110414, 0.6030665985, 0.6006164794, 0.5981607070, 0.5956993045, 0.5932322950, 0.5907597019, 0.5882815482, 0.5857978575, 0.5833086529, 0.5808139581, 0.5783137964, 0.5758081914, 0.5732971667, 0.5707807459, 0.5682589527, 0.5657318108, 0.5631993440, 0.5606615762, 0.5581185312, 0.5555702330, 0.5530167056, 0.5504579729, 0.5478940592, 0.5453249884, 0.5427507849, 0.5401714727, 0.5375870763, 0.5349976199, 0.5324031279, 0.5298036247, 0.5271991348, 0.5245896827, 0.5219752929, 0.5193559902, 0.5167317990, 0.5141027442, 0.5114688504, 0.5088301425, 0.5061866453, 0.5035383837, 0.5008853826, 0.4982276670, 0.4955652618, 0.4928981922, 0.4902264833, 0.4875501601, 0.4848692480, 0.4821837721, 0.4794937577, 0.4767992301, 0.4741002147, 0.4713967368, 0.4686888220, 0.4659764958, 0.4632597836, 0.4605387110, 0.4578133036, 0.4550835871, 0.4523495872, 0.4496113297, 0.4468688402, 0.4441221446, 0.4413712687, 0.4386162385, 0.4358570799, 0.4330938189, 0.4303264813, 0.4275550934, 0.4247796812, 0.4220002708, 0.4192168884, 0.4164295601, 0.4136383122, 0.4108431711, 0.4080441629, 0.4052413140, 0.4024346509, 0.3996241998, 0.3968099874, 0.3939920401, 0.3911703843, 0.3883450467, 0.3855160538, 0.3826834324, 0.3798472089, 0.3770074102, 0.3741640630, 0.3713171940, 0.3684668300, 0.3656129978, 0.3627557244, 0.3598950365, 0.3570309612, 0.3541635254, 0.3512927561, 0.3484186802, 0.3455413250, 0.3426607173, 0.3397768844, 0.3368898534, 0.3339996514, 0.3311063058, 0.3282098436, 0.3253102922, 0.3224076788, 0.3195020308, 0.3165933756, 0.3136817404, 0.3107671527, 0.3078496400, 0.3049292297, 0.3020059493, 0.2990798263, 0.2961508882, 0.2932191627, 0.2902846773, 0.2873474595, 0.2844075372, 0.2814649379, 0.2785196894, 0.2755718193, 0.2726213554, 0.2696683256, 0.2667127575, 0.2637546790, 0.2607941179, 0.2578311022, 0.2548656596, 0.2518978182, 0.2489276057, 0.2459550503, 0.2429801799, 0.2400030224, 0.2370236060, 0.2340419586, 0.2310581083, 0.2280720832, 0.2250839114, 0.2220936210, 0.2191012402, 0.2161067971, 0.2131103199, 0.2101118369, 0.2071113762, 0.2041089661, 0.2011046348, 0.1980984107, 0.1950903220, 0.1920803970, 0.1890686641, 0.1860551517, 0.1830398880, 0.1800229014, 0.1770042204, 0.1739838734, 0.1709618888, 0.1679382950, 0.1649131205, 0.1618863938, 0.1588581433, 0.1558283977, 0.1527971853, 0.1497645347, 0.1467304745, 0.1436950332, 0.1406582393, 0.1376201216, 0.1345807085, 0.1315400287, 0.1284981108, 0.1254549834, 0.1224106752, 0.1193652148, 0.1163186309, 0.1132709522, 0.1102222073, 0.1071724250, 0.1041216339, 0.1010698628, 0.0980171403, 0.0949634953, 0.0919089565, 0.0888535526, 0.0857973123, 0.0827402645, 0.0796824380, 0.0766238614, 0.0735645636, 0.0705045734, 0.0674439196, 0.0643826309, 0.0613207363, 0.0582582645, 0.0551952443, 0.0521317047, 0.0490676743, 0.0460031821, 0.0429382569, 0.0398729276, 0.0368072229, 0.0337411719, 0.0306748032, 0.0276081458, 0.0245412285, 0.0214740803, 0.0184067299, 0.0153392063, 0.0122715383, 0.0092037548, 0.0061358846, 0.0030679568, 0.0000000000, -0.0030679568, -0.0061358846, -0.0092037548, -0.0122715383, -0.0153392063, -0.0184067299, -0.0214740803, -0.0245412285, -0.0276081458, -0.0306748032, -0.0337411719, -0.0368072229, -0.0398729276, -0.0429382569, -0.0460031821, -0.0490676743, -0.0521317047, -0.0551952443, -0.0582582645, -0.0613207363, -0.0643826309, -0.0674439196, -0.0705045734, -0.0735645636, -0.0766238614, -0.0796824380, -0.0827402645, -0.0857973123, -0.0888535526, -0.0919089565, -0.0949634953, -0.0980171403, -0.1010698628, -0.1041216339, -0.1071724250, -0.1102222073, -0.1132709522, -0.1163186309, -0.1193652148, -0.1224106752, -0.1254549834, -0.1284981108, -0.1315400287, -0.1345807085, -0.1376201216, -0.1406582393, -0.1436950332, -0.1467304745, -0.1497645347, -0.1527971853, -0.1558283977, -0.1588581433, -0.1618863938, -0.1649131205, -0.1679382950, -0.1709618888, -0.1739838734, -0.1770042204, -0.1800229014, -0.1830398880, -0.1860551517, -0.1890686641, -0.1920803970, -0.1950903220, -0.1980984107, -0.2011046348, -0.2041089661, -0.2071113762, -0.2101118369, -0.2131103199, -0.2161067971, -0.2191012402, -0.2220936210, -0.2250839114, -0.2280720832, -0.2310581083, -0.2340419586, -0.2370236060, -0.2400030224, -0.2429801799, -0.2459550503, -0.2489276057, -0.2518978182, -0.2548656596, -0.2578311022, -0.2607941179, -0.2637546790, -0.2667127575, -0.2696683256, -0.2726213554, -0.2755718193, -0.2785196894, -0.2814649379, -0.2844075372, -0.2873474595, -0.2902846773, -0.2932191627, -0.2961508882, -0.2990798263, -0.3020059493, -0.3049292297, -0.3078496400, -0.3107671527, -0.3136817404, -0.3165933756, -0.3195020308, -0.3224076788, -0.3253102922, -0.3282098436, -0.3311063058, -0.3339996514, -0.3368898534, -0.3397768844, -0.3426607173, -0.3455413250, -0.3484186802, -0.3512927561, -0.3541635254, -0.3570309612, -0.3598950365, -0.3627557244, -0.3656129978, -0.3684668300, -0.3713171940, -0.3741640630, -0.3770074102, -0.3798472089, -0.3826834324, -0.3855160538, -0.3883450467, -0.3911703843, -0.3939920401, -0.3968099874, -0.3996241998, -0.4024346509, -0.4052413140, -0.4080441629, -0.4108431711, -0.4136383122, -0.4164295601, -0.4192168884, -0.4220002708, -0.4247796812, -0.4275550934, -0.4303264813, -0.4330938189, -0.4358570799, -0.4386162385, -0.4413712687, -0.4441221446, -0.4468688402, -0.4496113297, -0.4523495872, -0.4550835871, -0.4578133036, -0.4605387110, -0.4632597836, -0.4659764958, -0.4686888220, -0.4713967368, -0.4741002147, -0.4767992301, -0.4794937577, -0.4821837721, -0.4848692480, -0.4875501601, -0.4902264833, -0.4928981922, -0.4955652618, -0.4982276670, -0.5008853826, -0.5035383837, -0.5061866453, -0.5088301425, -0.5114688504, -0.5141027442, -0.5167317990, -0.5193559902, -0.5219752929, -0.5245896827, -0.5271991348, -0.5298036247, -0.5324031279, -0.5349976199, -0.5375870763, -0.5401714727, -0.5427507849, -0.5453249884, -0.5478940592, -0.5504579729, -0.5530167056, -0.5555702330, -0.5581185312, -0.5606615762, -0.5631993440, -0.5657318108, -0.5682589527, -0.5707807459, -0.5732971667, -0.5758081914, -0.5783137964, -0.5808139581, -0.5833086529, -0.5857978575, -0.5882815482, -0.5907597019, -0.5932322950, -0.5956993045, -0.5981607070, -0.6006164794, -0.6030665985, -0.6055110414, -0.6079497850, -0.6103828063, -0.6128100824, -0.6152315906, -0.6176473079, -0.6200572118, -0.6224612794, -0.6248594881, -0.6272518155, -0.6296382389, -0.6320187359, -0.6343932842, -0.6367618612, -0.6391244449, -0.6414810128, -0.6438315429, -0.6461760130, -0.6485144010, -0.6508466850, -0.6531728430, -0.6554928530, -0.6578066933, -0.6601143421, -0.6624157776, -0.6647109782, -0.6669999223, -0.6692825883, -0.6715589548, -0.6738290004, -0.6760927036, -0.6783500431, -0.6806009978, -0.6828455464, -0.6850836678, -0.6873153409, -0.6895405447, -0.6917592584, -0.6939714609, -0.6961771315, -0.6983762494, -0.7005687939, -0.7027547445, -0.7049340804, -0.7071067812, -0.7092728264, -0.7114321957, -0.7135848688, -0.7157308253, -0.7178700451, -0.7200025080, -0.7221281939, -0.7242470830, -0.7263591551, -0.7284643904, -0.7305627692, -0.7326542717, -0.7347388781, -0.7368165689, -0.7388873245, -0.7409511254, -0.7430079521, -0.7450577854, -0.7471006060, -0.7491363945, -0.7511651319, -0.7531867990, -0.7552013769, -0.7572088465, -0.7592091890, -0.7612023855, -0.7631884173, -0.7651672656, -0.7671389119, -0.7691033376, -0.7710605243, -0.7730104534, -0.7749531066, -0.7768884657, -0.7788165124, -0.7807372286, -0.7826505962, -0.7845565972, -0.7864552136, -0.7883464276, -0.7902302214, -0.7921065773, -0.7939754776, -0.7958369046, -0.7976908409, -0.7995372691, -0.8013761717, -0.8032075315, -0.8050313311, -0.8068475535, -0.8086561816, -0.8104571983, -0.8122505866, -0.8140363297, -0.8158144108, -0.8175848132, -0.8193475201, -0.8211025150, -0.8228497814, -0.8245893028, -0.8263210628, -0.8280450453, -0.8297612338, -0.8314696123, -0.8331701647, -0.8348628750, -0.8365477272, -0.8382247056, -0.8398937942, -0.8415549774, -0.8432082396, -0.8448535652, -0.8464909388, -0.8481203448, -0.8497417680, -0.8513551931, -0.8529606049, -0.8545579884, -0.8561473284, -0.8577286100, -0.8593018184, -0.8608669386, -0.8624239561, -0.8639728561, -0.8655136241, -0.8670462455, -0.8685707060, -0.8700869911, -0.8715950867, -0.8730949784, -0.8745866523, -0.8760700942, -0.8775452902, -0.8790122264, -0.8804708891, -0.8819212643, -0.8833633387, -0.8847970984, -0.8862225301, -0.8876396204, -0.8890483559, -0.8904487232, -0.8918407094, -0.8932243012, -0.8945994856, -0.8959662498, -0.8973245807, -0.8986744657, -0.9000158920, -0.9013488470, -0.9026733182, -0.9039892931, -0.9052967593, -0.9065957045, -0.9078861165, -0.9091679831, -0.9104412923, -0.9117060320, -0.9129621904, -0.9142097557, -0.9154487161, -0.9166790599, -0.9179007756, -0.9191138517, -0.9203182767, -0.9215140393, -0.9227011283, -0.9238795325, -0.9250492408, -0.9262102421, -0.9273625257, -0.9285060805, -0.9296408958, -0.9307669611, -0.9318842656, -0.9329927988, -0.9340925504, -0.9351835099, -0.9362656672, -0.9373390119, -0.9384035341, -0.9394592236, -0.9405060706, -0.9415440652, -0.9425731976, -0.9435934582, -0.9446048373, -0.9456073254, -0.9466009131, -0.9475855910, -0.9485613499, -0.9495281806, -0.9504860739, -0.9514350210, -0.9523750127, -0.9533060404, -0.9542280951, -0.9551411683, -0.9560452513, -0.9569403357, -0.9578264130, -0.9587034749, -0.9595715131, -0.9604305194, -0.9612804858, -0.9621214043, -0.9629532669, -0.9637760658, -0.9645897933, -0.9653944417, -0.9661900034, -0.9669764710, -0.9677538371, -0.9685220943, -0.9692812354, -0.9700312532, -0.9707721407, -0.9715038910, -0.9722264971, -0.9729399522, -0.9736442497, -0.9743393828, -0.9750253451, -0.9757021300, -0.9763697313, -0.9770281427, -0.9776773578, -0.9783173707, -0.9789481753, -0.9795697657, -0.9801821360, -0.9807852804, -0.9813791933, -0.9819638691, -0.9825393023, -0.9831054874, -0.9836624192, -0.9842100924, -0.9847485018, -0.9852776424, -0.9857975092, -0.9863080972, -0.9868094018, -0.9873014182, -0.9877841416, -0.9882575677, -0.9887216920, -0.9891765100, -0.9896220175, -0.9900582103, -0.9904850843, -0.9909026354, -0.9913108598, -0.9917097537, -0.9920993131, -0.9924795346, -0.9928504145, -0.9932119492, -0.9935641355, -0.9939069700, -0.9942404495, -0.9945645707, -0.9948793308, -0.9951847267, -0.9954807555, -0.9957674145, -0.9960447009, -0.9963126122, -0.9965711458, -0.9968202993, -0.9970600703, -0.9972904567, -0.9975114561, -0.9977230666, -0.9979252862, -0.9981181129, -0.9983015449, -0.9984755806, -0.9986402182, -0.9987954562, -0.9989412932, -0.9990777278, -0.9992047586, -0.9993223846, -0.9994306046, -0.9995294175, -0.9996188225, -0.9996988187, -0.9997694054, -0.9998305818, -0.9998823475, -0.9999247018, -0.9999576446, -0.9999811753, -0.9999952938}; + +value_type *cos_lut[11] = {cos_lut0, cos_lut1, cos_lut2, cos_lut3, cos_lut4, cos_lut5, cos_lut6, cos_lut7, cos_lut8, cos_lut9, cos_lut10}; value_type lookup_sin(int layer, int element) { diff --git a/src/main.cpp b/src/main.cpp index 9116858..e864990 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ extern "C" { } #define ENDLESS_LOOP() while(true) { delay(100); } +#define ARRAY_SIZE(x) ((size_t)(sizeof(x) / sizeof(x[0]))) #define OUTPUT_INTERVAL 10000 // milliseconds @@ -30,8 +31,12 @@ static bool wiFiConnectedToStation; static AutoAnalog recorder; // too large for the stack -static value_type timedomain[SAMPLES_PER_BLOCK]; -static value_type fft_re[BLOCK_LEN], fft_im[BLOCK_LEN], fft_abs[BLOCK_LEN]; +static size_t timedomain_write_offset; +static value_type timedomain[BLOCK_LEN]; +static value_type fft_re[BLOCK_LEN], fft_im[BLOCK_LEN]; + +const static uint16_t band_edges[] = {0, 40, 80, 120, 200, 400, 800, 1600, 3200, 6400, 12800, 20000}; +static value_type total_energy[ARRAY_SIZE(band_edges) - 1]; void wifi_setup(void) { @@ -85,7 +90,6 @@ void wifi_setup(void) } else { digitalWrite(LED_BUILTIN, true); // LED OFF (active low) } - } void setup() @@ -121,6 +125,9 @@ void setup() init_fft(); + timedomain_write_offset = 0; + memset(total_energy, 0, sizeof(total_energy)); + // start sampling recorder.enableAdcChannel(6); recorder.begin(true, false); @@ -135,78 +142,78 @@ void loop() { static uint32_t last_output_time = 0; static uint32_t nsamples = 0; - static value_type total_energy_0_to_300_hz = 0.0f; - static value_type total_energy_300_to_3500_hz = 0.0f; - static value_type total_energy_3500_to_8000_hz = 0.0f; - static value_type total_energy_8000_to_20000_hz = 0.0f; - wiFiMulti.run(); // maintain the WiFi connection recorder.getADC(SAMPLES_PER_BLOCK); // convert to Volt (float) for(size_t i = 0; i < SAMPLES_PER_BLOCK; i++) { - timedomain[i] = (value_type)recorder.adcBuffer16[i] / 4096.0f * 3.30f; + timedomain[i + timedomain_write_offset] = (value_type)recorder.adcBuffer16[i] / 4096.0f * 3.30f; } + timedomain_write_offset += SAMPLES_PER_BLOCK; - // calculate average value - value_type avg = 0; - for(size_t i = 0; i < SAMPLES_PER_BLOCK; i++) { - avg += timedomain[i]; + if(timedomain_write_offset >= ARRAY_SIZE(timedomain)) { + timedomain_write_offset = 0; + + // calculate average value + value_type avg = 0; + for(size_t i = 0; i < ARRAY_SIZE(timedomain); i++) { + avg += timedomain[i]; + } + + avg /= ARRAY_SIZE(timedomain); + + // and remove it from the data + for(size_t i = 0; i < ARRAY_SIZE(timedomain); i++) { + timedomain[i] -= avg; + } + + apply_hanning(timedomain); + fft_transform(timedomain, fft_re, fft_im); + + // HACK: reuse now unused timedomain memory for absolute FFT + value_type *fft_abs = timedomain; + + complex_to_absolute(fft_re, fft_im, fft_abs); + + // accumulate energy in bands + for(size_t i = 0; i < ARRAY_SIZE(total_energy); i++) { + total_energy[i] += get_spectral_density_in_band(fft_abs, band_edges[i], band_edges[i+1]); + } + + // force restart sampling due to calculation delay (might cause glitches) + recorder.getADC(SAMPLES_PER_BLOCK); + timedomain_write_offset = 0; + + nsamples++; } - avg /= SAMPLES_PER_BLOCK; - - // and remove it from the data - for(size_t i = 0; i < SAMPLES_PER_BLOCK; i++) { - timedomain[i] -= avg; - } - - apply_hanning(timedomain); - fft_transform(timedomain, fft_re, fft_im); - complex_to_absolute(fft_re, fft_im, fft_abs); - - value_type energy_0_to_300_hz = get_energy_density_in_band(fft_abs, 0, 300); - value_type energy_300_to_3500_hz = get_energy_density_in_band(fft_abs, 300, 3500); - value_type energy_3500_to_8000_hz = get_energy_density_in_band(fft_abs, 3500, 8000); - value_type energy_8000_to_20000_hz = get_energy_density_in_band(fft_abs, 8000, 20000); - - total_energy_0_to_300_hz += energy_0_to_300_hz; - total_energy_300_to_3500_hz += energy_300_to_3500_hz; - total_energy_3500_to_8000_hz += energy_3500_to_8000_hz; - total_energy_8000_to_20000_hz += energy_8000_to_20000_hz; - nsamples++; - uint32_t now = millis(); if(now - last_output_time > OUTPUT_INTERVAL) { - total_energy_0_to_300_hz /= nsamples; - total_energy_300_to_3500_hz /= nsamples; - total_energy_3500_to_8000_hz /= nsamples; - total_energy_8000_to_20000_hz /= nsamples; + String json_string = "{"; - // calculate dBV - value_type dBV_per_Hz_0_to_300_hz = 20*log10(total_energy_0_to_300_hz); - value_type dBV_per_Hz_300_to_3500_hz = 20*log10(total_energy_300_to_3500_hz); - value_type dBV_per_Hz_3500_to_8000_hz = 20*log10(total_energy_3500_to_8000_hz); - value_type dBV_per_Hz_8000_to_20000_hz = 20*log10(total_energy_8000_to_20000_hz); + Serial.print("Samples taken: "); + Serial.println(nsamples); - Serial.print(" 0 - 300 Hz [dBV/Hz]: "); - Serial.println(dBV_per_Hz_0_to_300_hz); - Serial.print(" 300 - 3500 Hz [dBV/Hz]: "); - Serial.println(dBV_per_Hz_300_to_3500_hz); - Serial.print(" 3500 - 8000 Hz [dBV/Hz]: "); - Serial.println(dBV_per_Hz_3500_to_8000_hz); - Serial.print(" 8000 - 20000 Hz [dBV/Hz]: "); - Serial.println(dBV_per_Hz_8000_to_20000_hz); + for(size_t i = 0; i < ARRAY_SIZE(total_energy); i++) { + value_type dBV_per_sqrt_Hz = 20*log10f(total_energy[i] / nsamples); - Serial.println(); + uint16_t fstart = band_edges[i]; + uint16_t fend = band_edges[i+1]; - // encode the data into JSON - String json_string = "{" - "\"0_to_300_hz\":" + String(dBV_per_Hz_0_to_300_hz, 2) + "," - "\"300_to_3500_hz\":" + String(dBV_per_Hz_300_to_3500_hz, 2) + "," - "\"3500_to_8000_hz\":" + String(dBV_per_Hz_3500_to_8000_hz, 2) + "," - "\"8000_to_20000_hz\":" + String(dBV_per_Hz_8000_to_20000_hz, 2) + "}"; + Serial.printf("%5d - %5d Hz: %.2f dBV/√Hz / %f Vrms\r\n", fstart, fend, dBV_per_sqrt_Hz, total_energy[i]); + + if(i != 0) { + json_string += ", "; + } + + // encode the data into JSON + char indexstr[5]; + snprintf(indexstr, sizeof(indexstr), "%03zu_", i); + json_string += "\"" + String(indexstr) + String(fstart) + "_to_" + String(fend) + "_hz\": " + String(dBV_per_sqrt_Hz, 2); + } + + json_string += "}"; // send the data to graphite HTTPClient client; @@ -227,12 +234,13 @@ void loop() { } // reset accumulation - total_energy_0_to_300_hz = 0.0f; - total_energy_300_to_3500_hz = 0.0f; - total_energy_3500_to_8000_hz = 0.0f; - total_energy_8000_to_20000_hz = 0.0f; + memset(total_energy, 0, sizeof(total_energy)); nsamples = 0; + // force restart sampling due to transmit delay (causes glitches) + recorder.getADC(SAMPLES_PER_BLOCK); + timedomain_write_offset = 0; + last_output_time = now; }