B3M38SPD seminar project - beehive monitor with LoRa reporting
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spd-lorabees/Src/audio.c

446 lines
50 KiB

/*
* audio.c
*
* Created on: Dec 31, 2017
* Author: ondra
*/
#include "audio.h"
#include <stdint.h>
#include <stdbool.h>
#include "main.h"
#include "tim.h"
#include "dma.h"
#include "adc.h"
#include "stm32l0xx_hal.h"
#include <string.h>
#include "arm_math.h"
#include <math.h>
#include <float.h>
#include "arm_const_structs.h"
#include "debug.h"
#define print PRINTF
extern DMA_HandleTypeDef hdma_adc;
extern ADC_HandleTypeDef hadc;
void ftoa(float n, char *res, int afterpoint);
//static const float win_hamming_2048[] = {0.08000000f, 0.08000217f, 0.08000867f, 0.08001950f, 0.08003467f, 0.08005417f, 0.08007801f, 0.08010618f, 0.08013868f, 0.08017551f, 0.08021668f, 0.08026218f, 0.08031201f, 0.08036617f, 0.08042466f, 0.08048748f, 0.08055463f, 0.08062611f, 0.08070192f, 0.08078205f, 0.08086651f, 0.08095530f, 0.08104841f, 0.08114585f, 0.08124761f, 0.08135369f, 0.08146409f, 0.08157881f, 0.08169786f, 0.08182121f, 0.08194889f, 0.08208088f, 0.08221719f, 0.08235781f, 0.08250274f, 0.08265198f, 0.08280553f, 0.08296339f, 0.08312555f, 0.08329202f, 0.08346279f, 0.08363786f, 0.08381724f, 0.08400090f, 0.08418887f, 0.08438113f, 0.08457769f, 0.08477853f, 0.08498366f, 0.08519308f, 0.08540679f, 0.08562478f, 0.08584704f, 0.08607359f, 0.08630442f, 0.08653952f, 0.08677889f, 0.08702253f, 0.08727044f, 0.08752261f, 0.08777905f, 0.08803975f, 0.08830470f, 0.08857392f, 0.08884738f, 0.08912510f, 0.08940706f, 0.08969327f, 0.08998372f, 0.09027841f, 0.09057734f, 0.09088050f, 0.09118790f, 0.09149952f, 0.09181537f, 0.09213544f, 0.09245973f, 0.09278824f, 0.09312096f, 0.09345789f, 0.09379903f, 0.09414437f, 0.09449391f, 0.09484765f, 0.09520559f, 0.09556771f, 0.09593402f, 0.09630452f, 0.09667920f, 0.09705805f, 0.09744107f, 0.09782827f, 0.09821963f, 0.09861515f, 0.09901484f, 0.09941867f, 0.09982666f, 0.10023880f, 0.10065508f, 0.10107549f, 0.10150005f, 0.10192873f, 0.10236154f, 0.10279848f, 0.10323953f, 0.10368470f, 0.10413398f, 0.10458737f, 0.10504486f, 0.10550644f, 0.10597213f, 0.10644189f, 0.10691575f, 0.10739368f, 0.10787569f, 0.10836178f, 0.10885193f, 0.10934614f, 0.10984440f, 0.11034673f, 0.11085309f, 0.11136351f, 0.11187796f, 0.11239644f, 0.11291895f, 0.11344549f, 0.11397605f, 0.11451062f, 0.11504919f, 0.11559178f, 0.11613836f, 0.11668893f, 0.11724349f, 0.11780204f, 0.11836456f, 0.11893106f, 0.11950152f, 0.12007594f, 0.12065432f, 0.12123665f, 0.12182293f, 0.12241315f, 0.12300730f, 0.12360538f, 0.12420738f, 0.12481330f, 0.12542313f, 0.12603687f, 0.12665451f, 0.12727604f, 0.12790146f, 0.12853077f, 0.12916395f, 0.12980100f, 0.13044192f, 0.13108669f, 0.13173532f, 0.13238779f, 0.13304410f, 0.13370425f, 0.13436823f, 0.13503603f, 0.13570764f, 0.13638306f, 0.13706229f, 0.13774531f, 0.13843212f, 0.13912271f, 0.13981709f, 0.14051523f, 0.14121713f, 0.14192280f, 0.14263221f, 0.14334537f, 0.14406226f, 0.14478289f, 0.14550723f, 0.14623530f, 0.14696707f, 0.14770255f, 0.14844173f, 0.14918459f, 0.14993113f, 0.15068135f, 0.15143524f, 0.15219279f, 0.15295399f, 0.15371884f, 0.15448733f, 0.15525945f, 0.15603520f, 0.15681456f, 0.15759754f, 0.15838411f, 0.15917428f, 0.15996804f, 0.16076538f, 0.16156630f, 0.16237078f, 0.16317881f, 0.16399040f, 0.16480553f, 0.16562419f, 0.16644638f, 0.16727209f, 0.16810132f, 0.16893404f, 0.16977027f, 0.17060998f, 0.17145317f, 0.17229983f, 0.17314996f, 0.17400354f, 0.17486058f, 0.17572105f, 0.17658495f, 0.17745228f, 0.17832302f, 0.17919718f, 0.18007473f, 0.18095567f, 0.18183999f, 0.18272769f, 0.18361876f, 0.18451318f, 0.18541095f, 0.18631207f, 0.18721651f, 0.18812428f, 0.18903537f, 0.18994976f, 0.19086745f, 0.19178843f, 0.19271268f, 0.19364022f, 0.19457101f, 0.19550506f, 0.19644235f, 0.19738288f, 0.19832664f, 0.19927362f, 0.20022381f, 0.20117720f, 0.20213378f, 0.20309355f, 0.20405649f, 0.20502259f, 0.20599185f, 0.20696426f, 0.20793981f, 0.20891848f, 0.20990027f, 0.21088518f, 0.21187318f, 0.21286428f, 0.21385845f, 0.21485570f, 0.21585602f, 0.21685939f, 0.21786580f, 0.21887525f, 0.21988772f, 0.22090321f, 0.22192170f, 0.22294319f, 0.22396767f, 0.22499513f, 0.22602555f, 0.22705894f, 0.22809527f, 0.22913454f, 0.23017674f, 0.23122185f, 0.23226988f, 0.23332081f, 0.23437462f, 0.23543132f, 0.23649088f, 0.23755330f, 0.23861858f, 0.23968669f, 0.24075763f, 0.24183139f, 0.24290797f, 0.24398734f, 0.24506949f, 0.24615443f, 0.24724214f, 0.24833260f, 0.24942581f, 0.25052176f, 0.25162044f, 0.25272184f, 0.25382594f, 0.25493273f, 0.25604222f, 0.25715437f, 0.25826920f, 0.25938668f, 0.26050680f, 0.26162955f, 0.26275493f, 0.26388292f, 0.26501351f, 0.26614669f, 0.26728245f, 0.26842078f, 0.26956167f, 0.27070511f, 0.27185109f, 0.27299959f, 0.27415060f, 0.27530413f, 0.27646014f, 0.27761864f, 0.27877961f, 0.27994304f, 0.28110892f, 0.28227724f, 0.28344799f, 0.28462116f, 0.28579673f, 0.28697470f, 0.28815505f, 0.28933777f, 0.29052286f, 0.29171030f, 0.29290007f, 0.29409217f, 0.29528659f, 0.29648332f, 0.29768234f, 0.29888364f, 0.30008722f, 0.30129305f, 0.30250114f, 0.30371146f, 0.30492401f, 0.30613877f, 0.30735574f, 0.30857489f, 0.30979623f, 0.31101974f, 0.31224540f, 0.31347321f, 0.31470316f, 0.31593523f, 0.31716941f, 0.31840568f, 0.31964405f, 0.32088449f, 0.32212700f, 0.32337156f, 0.32461815f, 0.32586678f, 0.32711743f, 0.32837008f, 0.32962473f, 0.33088136f, 0.33213996f, 0.33340051f, 0.33466302f, 0.33592745f, 0.33719381f, 0.33846208f, 0.33973225f, 0.34100431f, 0.34227824f, 0.34355404f, 0.34483168f, 0.34611117f, 0.34739248f, 0.34867560f, 0.34996053f, 0.35124725f, 0.35253575f, 0.35382601f, 0.35511803f, 0.35641179f, 0.35770728f, 0.35900448f, 0.36030339f, 0.36160400f, 0.36290629f, 0.36421024f, 0.36551585f, 0.36682310f, 0.36813199f, 0.36944249f, 0.37075461f, 0.37206831f, 0.37338360f, 0.37470046f, 0.37601887f, 0.37733884f, 0.37866033f, 0.37998334f, 0.38130786f, 0.38263388f, 0.38396138f, 0.38529035f, 0.38662077f, 0.38795264f, 0.38928595f, 0.39062067f, 0.39195680f, 0.39329433f, 0.39463324f, 0.39597352f, 0.39731515f, 0.39865813f, 0.40000244f, 0.40134807f, 0.40269501f, 0.40404324f, 0.40539275f, 0.40674353f, 0.40809556f, 0.40944884f, 0.41080335f, 0.41215907f, 0.41351600f, 0.41487412f, 0.41623342f, 0.41759389f, 0.41895550f, 0.42031826f, 0.42168215f, 0.42304715f, 0.42441326f, 0.42578045f, 0.42714872f, 0.42851805f, 0.42988843f, 0.43125985f, 0.43263229f, 0.43400575f, 0.43538020f, 0.43675564f, 0.43813206f, 0.43950943f, 0.44088775f, 0.44226700f, 0.44364718f, 0.44502826f, 0.44641023f, 0.44779309f, 0.44917682f, 0.45056140f, 0.45194683f, 0.45333308f, 0.45472015f, 0.45610803f, 0.45749669f, 0.45888614f, 0.46027634f, 0.46166730f, 0.46305900f, 0.46445142f, 0.46584455f, 0.46723838f, 0.46863290f, 0.47002809f, 0.47142394f, 0.47282043f, 0.47421756f, 0.47561531f, 0.47701366f, 0.47841261f, 0.47981213f, 0.48121223f, 0.48261288f, 0.48401407f, 0.48541578f, 0.48681801f, 0.48822075f, 0.48962397f, 0.49102766f, 0.49243182f, 0.49383642f, 0.49524146f, 0.49664692f, 0.49805279f, 0.49945905f, 0.50086570f, 0.50227272f, 0.50368009f, 0.50508780f, 0.50649584f, 0.50790420f, 0.50931286f, 0.51072181f, 0.51213103f, 0.51354052f, 0.51495025f, 0.51636023f, 0.51777042f, 0.51918083f, 0.52059143f, 0.52200221f, 0.52341316f, 0.52482427f, 0.52623553f, 0.52764691f, 0.52905841f, 0.53047001f, 0.53188170f, 0.53329347f, 0.53470530f, 0.53611718f, 0.53752910f, 0.53894104f, 0.54035299f, 0.54176494f, 0.54317687f, 0.54458877f, 0.54600062f, 0.54741243f, 0.54882416f, 0.55023581f, 0.55164736f, 0.55305880f, 0.55447012f, 0.55588130f, 0.55729233f, 0.55870320f, 0.56011390f, 0.56152440f, 0.56293470f, 0.56434479f, 0.56575465f, 0.56716426f, 0.56857362f, 0.56998270f, 0.57139151f, 0.57280002f, 0.57420822f, 0.57561610f, 0.57702364f, 0.57843084f, 0.57983767f, 0.58124413f, 0.58265020f, 0.58405586f, 0.58546111f, 0.58686594f, 0.58827032f, 0.58967424f, 0.59107770f, 0.59248068f, 0.59388316f, 0.59528514f, 0.59668659f, 0.59808751f, 0.59948789f, 0.60088770f, 0.60228694f, 0.60368559f, 0.60508364f, 0.60648108f, 0.60787790f, 0.60927407f, 0.61066959f, 0.61206444f, 0.61345862f, 0.61485210f, 0.61624488f, 0.61763694f, 0.61902827f, 0.62041886f, 0.62180868f, 0.62319774f, 0.62458601f, 0.62597348f, 0.62736015f, 0.62874599f, 0.63013100f, 0.63151515f, 0.63289845f, 0.63428087f, 0.63566240f, 0.63704303f, 0.63842274f, 0.63980153f, 0.64117938f, 0.64255627f, 0.64393220f, 0.64530715f, 0.64668110f, 0.64805405f, 0.64942599f, 0.65079689f, 0.65216675f, 0.65353555f, 0.65490328f, 0.65626993f, 0.65763549f, 0.65899993f, 0.66036326f, 0.66172545f, 0.66308649f, 0.66444638f, 0.66580509f, 0.66716261f, 0.66851894f, 0.66987406f, 0.67122795f, 0.67258061f, 0.67393202f, 0.67528217f, 0.67663104f, 0.67797862f, 0.67932491f, 0.68066988f, 0.68201353f, 0.68335583f, 0.68469679f, 0.68603639f, 0.68737461f, 0.68871144f, 0.69004687f, 0.69138088f, 0.69271347f, 0.69404462f, 0.69537432f, 0.69670256f, 0.69802932f, 0.69935459f, 0.70067835f, 0.70200061f, 0.70332134f, 0.70464053f, 0.70595817f, 0.70727424f, 0.70858874f, 0.70990165f, 0.71121296f, 0.71252266f, 0.71383073f, 0.71513716f, 0.71644195f, 0.71774507f, 0.71904651f, 0.72034627f, 0.72164433f, 0.72294068f, 0.72423531f, 0.72552820f, 0.72681934f, 0.72810872f, 0.72939633f, 0.73068216f, 0.73196618f, 0.73324840f, 0.73452880f, 0.73580737f, 0.73708409f, 0.73835896f, 0.73963195f, 0.74090307f, 0.74217229f, 0.74343961f, 0.74470501f, 0.74596848f, 0.74723001f, 0.74848959f, 0.74974720f, 0.75100284f, 0.75225649f, 0.75350814f, 0.75475778f, 0.75600540f, 0.75725098f, 0.75849451f, 0.75973599f, 0.76097539f, 0.76221272f, 0.76344795f, 0.76468107f, 0.76591208f, 0.76714096f, 0.76836770f, 0.76959228f, 0.77081471f, 0.77203496f, 0.77325302f, 0.77446889f, 0.77568254f, 0.77689398f, 0.77810319f, 0.77931015f, 0.78051485f, 0.78171729f, 0.78291746f, 0.78411533f, 0.78531091f, 0.78650417f, 0.78769511f, 0.78888372f, 0.79006998f, 0.79125388f, 0.79243542f, 0.79361458f, 0.79479136f, 0.79596573f, 0.79713768f, 0.79830722f, 0.79947432f, 0.80063898f, 0.80180118f, 0.80296092f, 0.80411818f, 0.80527295f, 0.80642522f, 0.80757498f, 0.80872222f, 0.80986693f, 0.81100909f, 0.81214870f, 0.81328575f, 0.81442022f, 0.81555211f, 0.81668140f, 0.81780809f, 0.81893215f, 0.82005359f, 0.82117239f, 0.82228855f, 0.82340204f, 0.82451286f, 0.82562100f, 0.82672645f, 0.82782920f, 0.82892924f, 0.83002655f, 0.83112113f, 0.83221297f, 0.83330206f, 0.83438838f, 0.83547193f, 0.83655270f, 0.83763067f, 0.83870584f, 0.83977819f, 0.84084772f, 0.84191441f, 0.84297826f, 0.84403926f, 0.84509739f, 0.84615265f, 0.84720502f, 0.84825450f, 0.84930107f, 0.85034473f, 0.85138546f, 0.85242327f, 0.85345812f, 0.85449003f, 0.85551897f, 0.85654494f, 0.85756793f, 0.85858792f, 0.85960491f, 0.86061890f, 0.86162986f, 0.86263779f, 0.86364268f, 0.86464452f, 0.86564330f, 0.86663902f, 0.86763166f, 0.86862121f, 0.86960766f, 0.87059101f, 0.87157125f, 0.87254836f, 0.87352234f, 0.87449317f, 0.87546085f, 0.87642538f, 0.87738673f, 0.87834491f, 0.87929989f, 0.88025168f, 0.88120027f, 0.88214564f, 0.88308779f, 0.88402670f, 0.88496237f, 0.88589479f, 0.88682396f, 0.88774985f, 0.88867247f, 0.88959181f, 0.89050785f, 0.89142059f, 0.89233002f, 0.89323613f, 0.89413891f, 0.89503835f, 0.89593445f, 0.89682719f, 0.89771658f, 0.89860259f, 0.89948522f, 0.90036447f, 0.90124032f, 0.90211277f, 0.90298181f, 0.90384743f, 0.90470962f, 0.90556837f, 0.90642368f, 0.90727554f, 0.90812393f, 0.90896886f, 0.90981031f, 0.91064828f, 0.91148276f, 0.91231373f, 0.91314120f, 0.91396515f, 0.91478558f, 0.91560248f, 0.91641584f, 0.91722565f, 0.91803191f, 0.91883461f, 0.91963373f, 0.92042928f, 0.92122125f, 0.92200963f, 0.92279440f, 0.92357557f, 0.92435313f, 0.92512706f, 0.92589737f, 0.92666404f, 0.92742706f, 0.92818644f, 0.92894216f, 0.92969422f, 0.93044260f, 0.93118730f, 0.93192832f, 0.93266565f, 0.93339928f, 0.93412920f, 0.93485540f, 0.93557789f, 0.93629665f, 0.93701168f, 0.93772297f, 0.93843050f, 0.93913429f, 0.93983431f, 0.94053057f, 0.94122306f, 0.94191176f, 0.94259668f, 0.94327780f, 0.94395512f, 0.94462864f, 0.94529835f, 0.94596424f, 0.94662630f, 0.94728453f, 0.94793893f, 0.94858948f, 0.94923618f, 0.94987903f, 0.95051801f, 0.95115313f, 0.95178437f, 0.95241173f, 0.95303521f, 0.95365480f, 0.95427048f, 0.95488227f, 0.95549015f, 0.95609411f, 0.95669415f, 0.95729027f, 0.95788245f, 0.95847070f, 0.95905501f, 0.95963536f, 0.96021177f, 0.96078421f, 0.96135269f, 0.96191720f, 0.96247773f, 0.96303429f, 0.96358686f, 0.96413543f, 0.96468002f, 0.96522060f, 0.96575717f, 0.96628973f, 0.96681828f, 0.96734281f, 0.96786330f, 0.96837977f, 0.96889220f, 0.96940060f, 0.96990494f, 0.97040524f, 0.97090148f, 0.97139366f, 0.97188177f, 0.97236582f, 0.97284579f, 0.97332169f, 0.97379350f, 0.97426123f, 0.97472486f, 0.97518440f, 0.97563984f, 0.97609117f, 0.97653840f, 0.97698151f, 0.97742050f, 0.97785538f, 0.97828613f, 0.97871275f, 0.97913523f, 0.97955358f, 0.97996779f, 0.98037785f, 0.98078376f, 0.98118552f, 0.98158313f, 0.98197657f, 0.98236585f, 0.98275096f, 0.98313190f, 0.98350867f, 0.98388125f, 0.98424966f, 0.98461387f, 0.98497390f, 0.98532974f, 0.98568138f, 0.98602883f, 0.98637207f, 0.98671110f, 0.98704593f, 0.98737654f, 0.98770294f, 0.98802512f, 0.98834308f, 0.98865682f, 0.98896633f, 0.98927161f, 0.98957265f, 0.98986946f, 0.99016203f, 0.99045037f, 0.99073445f, 0.99101429f, 0.99128988f, 0.99156122f, 0.99182831f, 0.99209113f, 0.99234970f, 0.99260401f, 0.99285405f, 0.99309983f, 0.99334133f, 0.99357857f, 0.99381153f, 0.99404022f, 0.99426463f, 0.99448475f, 0.99470060f, 0.99491216f, 0.99511944f, 0.99532243f, 0.99552113f, 0.99571554f, 0.99590565f, 0.99609147f, 0.99627299f, 0.99645021f, 0.99662313f, 0.99679175f, 0.99695607f, 0.99711608f, 0.99727178f, 0.99742318f, 0.99757027f, 0.99771304f, 0.99785150f, 0.99798565f, 0.99811549f, 0.99824100f, 0.99836221f, 0.99847909f, 0.99859165f, 0.99869989f, 0.99880381f, 0.99890341f, 0.99899868f, 0.99908963f, 0.99917626f, 0.99925856f, 0.99933653f, 0.99941017f, 0.99947948f, 0.99954447f, 0.99960513f, 0.99966145f, 0.99971345f, 0.99976111f, 0.99980445f, 0.99984345f, 0.99987811f, 0.99990845f, 0.99993445f, 0.99995612f, 0.99997345f, 0.99998646f, 0.99999512f, 0.99999946f, 0.99999946f, 0.99999512f, 0.99998646f, 0.99997345f, 0.99995612f, 0.99993445f, 0.99990845f, 0.99987811f, 0.99984345f, 0.99980445f, 0.99976111f, 0.99971345f, 0.99966145f, 0.99960513f, 0.99954447f, 0.99947948f, 0.99941017f, 0.99933653f, 0.99925856f, 0.99917626f, 0.99908963f, 0.99899868f, 0.99890341f, 0.99880381f, 0.99869989f, 0.99859165f, 0.99847909f, 0.99836221f, 0.99824100f, 0.99811549f, 0.99798565f, 0.99785150f, 0.99771304f, 0.99757027f, 0.99742318f, 0.99727178f, 0.99711608f, 0.99695607f, 0.99679175f, 0.99662313f, 0.99645021f, 0.99627299f, 0.99609147f, 0.99590565f, 0.99571554f, 0.99552113f, 0.99532243f, 0.99511944f, 0.99491216f, 0.99470060f, 0.99448475f, 0.99426463f, 0.99404022f, 0.99381153f, 0.99357857f, 0.99334133f, 0.99309983f, 0.99285405f, 0.99260401f, 0.99234970f, 0.99209113f, 0.99182831f, 0.99156122f, 0.99128988f, 0.99101429f, 0.99073445f, 0.99045037f, 0.99016203f, 0.98986946f, 0.98957265f, 0.98927161f, 0.98896633f, 0.98865682f, 0.98834308f, 0.98802512f, 0.98770294f, 0.98737654f, 0.98704593f, 0.98671110f, 0.98637207f, 0.98602883f, 0.98568138f, 0.98532974f, 0.98497390f, 0.98461387f, 0.98424966f, 0.98388125f, 0.98350867f, 0.98313190f, 0.98275096f, 0.98236585f, 0.98197657f, 0.98158313f, 0.98118552f, 0.98078376f, 0.98037785f, 0.97996779f, 0.97955358f, 0.97913523f, 0.97871275f, 0.97828613f, 0.97785538f, 0.97742050f, 0.97698151f, 0.97653840f, 0.97609117f, 0.97563984f, 0.97518440f, 0.97472486f, 0.97426123f, 0.97379350f, 0.97332169f, 0.97284579f, 0.97236582f, 0.97188177f, 0.97139366f, 0.97090148f, 0.97040524f, 0.96990494f, 0.96940060f, 0.96889220f, 0.96837977f, 0.96786330f, 0.96734281f, 0.96681828f, 0.96628973f, 0.96575717f, 0.96522060f, 0.96468002f, 0.96413543f, 0.96358686f, 0.96303429f, 0.96247773f, 0.96191720f, 0.96135269f, 0.96078421f, 0.96021177f, 0.95963536f, 0.95905501f, 0.95847070f, 0.95788245f, 0.95729027f, 0.95669415f, 0.95609411f, 0.95549015f, 0.95488227f, 0.95427048f, 0.95365480f, 0.95303521f, 0.95241173f, 0.95178437f, 0.95115313f, 0.95051801f, 0.94987903f, 0.94923618f, 0.94858948f, 0.94793893f, 0.94728453f, 0.94662630f, 0.94596424f, 0.94529835f, 0.94462864f, 0.94395512f, 0.94327780f, 0.94259668f, 0.94191176f, 0.94122306f, 0.94053057f, 0.93983431f, 0.93913429f, 0.93843050f, 0.93772297f, 0.93701168f, 0.93629665f, 0.93557789f, 0.93485540f, 0.93412920f, 0.93339928f, 0.93266565f, 0.93192832f, 0.93118730f, 0.93044260f, 0.92969422f, 0.92894216f, 0.92818644f, 0.92742706f, 0.92666404f, 0.92589737f, 0.92512706f, 0.92435313f, 0.92357557f, 0.92279440f, 0.92200963f, 0.92122125f, 0.92042928f, 0.91963373f, 0.91883461f, 0.91803191f, 0.91722565f, 0.91641584f, 0.91560248f, 0.91478558f, 0.91396515f, 0.91314120f, 0.91231373f, 0.91148276f, 0.91064828f, 0.90981031f, 0.90896886f, 0.90812393f, 0.90727554f, 0.90642368f, 0.90556837f, 0.90470962f, 0.90384743f, 0.90298181f, 0.90211277f, 0.90124032f, 0.90036447f, 0.89948522f, 0.89860259f, 0.89771658f, 0.89682719f, 0.89593445f, 0.89503835f, 0.89413891f, 0.89323613f, 0.89233002f, 0.89142059f, 0.89050785f, 0.88959181f, 0.88867247f, 0.88774985f, 0.88682396f, 0.88589479f, 0.88496237f, 0.88402670f, 0.88308779f, 0.88214564f, 0.88120027f, 0.88025168f, 0.87929989f, 0.87834491f, 0.87738673f, 0.87642538f, 0.87546085f, 0.87449317f, 0.87352234f, 0.87254836f, 0.87157125f, 0.87059101f, 0.86960766f, 0.86862121f, 0.86763166f, 0.86663902f, 0.86564330f, 0.86464452f, 0.86364268f, 0.86263779f, 0.86162986f, 0.86061890f, 0.85960491f, 0.85858792f, 0.85756793f, 0.85654494f, 0.85551897f, 0.85449003f, 0.85345812f, 0.85242327f, 0.85138546f, 0.85034473f, 0.84930107f, 0.84825450f, 0.84720502f, 0.84615265f, 0.84509739f, 0.84403926f, 0.84297826f, 0.84191441f, 0.84084772f, 0.83977819f, 0.83870584f, 0.83763067f, 0.83655270f, 0.83547193f, 0.83438838f, 0.83330206f, 0.83221297f, 0.83112113f, 0.83002655f, 0.82892924f, 0.82782920f, 0.82672645f, 0.82562100f, 0.82451286f, 0.82340204f, 0.82228855f, 0.82117239f, 0.82005359f, 0.81893215f, 0.81780809f, 0.81668140f, 0.81555211f, 0.81442022f, 0.81328575f, 0.81214870f, 0.81100909f, 0.80986693f, 0.80872222f, 0.80757498f, 0.80642522f, 0.80527295f, 0.80411818f, 0.80296092f, 0.80180118f, 0.80063898f, 0.79947432f, 0.79830722f, 0.79713768f, 0.79596573f, 0.79479136f, 0.79361458f, 0.79243542f, 0.79125388f, 0.79006998f, 0.78888372f, 0.78769511f, 0.78650417f, 0.78531091f, 0.78411533f, 0.78291746f, 0.78171729f, 0.78051485f, 0.77931015f, 0.77810319f, 0.77689398f, 0.77568254f, 0.77446889f, 0.77325302f, 0.77203496f, 0.77081471f, 0.76959228f, 0.76836770f, 0.76714096f, 0.76591208f, 0.76468107f, 0.76344795f, 0.76221272f, 0.76097539f, 0.75973599f, 0.75849451f, 0.75725098f, 0.75600540f, 0.75475778f, 0.75350814f, 0.75225649f, 0.75100284f, 0.74974720f, 0.74848959f, 0.74723001f, 0.74596848f, 0.74470501f, 0.74343961f, 0.74217229f, 0.74090307f, 0.73963195f, 0.73835896f, 0.73708409f, 0.73580737f, 0.73452880f, 0.73324840f, 0.73196618f, 0.73068216f, 0.72939633f, 0.72810872f, 0.72681934f, 0.72552820f, 0.72423531f, 0.72294068f, 0.72164433f, 0.72034627f, 0.71904651f, 0.71774507f, 0.71644195f, 0.71513716f, 0.71383073f, 0.71252266f, 0.71121296f, 0.70990165f, 0.70858874f, 0.70727424f, 0.70595817f, 0.70464053f, 0.70332134f, 0.70200061f, 0.70067835f, 0.69935459f, 0.69802932f, 0.69670256f, 0.69537432f, 0.69404462f, 0.69271347f, 0.69138088f, 0.69004687f, 0.68871144f, 0.68737461f, 0.68603639f, 0.68469679f, 0.68335583f, 0.68201353f, 0.68066988f, 0.67932491f, 0.67797862f, 0.67663104f, 0.67528217f, 0.67393202f, 0.67258061f, 0.67122795f, 0.66987406f, 0.66851894f, 0.66716261f, 0.66580509f, 0.66444638f, 0.66308649f, 0.66172545f, 0.66036326f, 0.65899993f, 0.65763549f, 0.65626993f, 0.65490328f, 0.65353555f, 0.65216675f, 0.65079689f, 0.64942599f, 0.64805405f, 0.64668110f, 0.64530715f, 0.64393220f, 0.64255627f, 0.64117938f, 0.63980153f, 0.63842274f, 0.63704303f, 0.63566240f, 0.63428087f, 0.63289845f, 0.63151515f, 0.63013100f, 0.62874599f, 0.62736015f, 0.62597348f, 0.62458601f, 0.62319774f, 0.62180868f, 0.62041886f, 0.61902827f, 0.61763694f, 0.61624488f, 0.61485210f, 0.61345862f, 0.61206444f, 0.61066959f, 0.60927407f, 0.60787790f, 0.60648108f, 0.60508364f, 0.60368559f, 0.60228694f, 0.60088770f, 0.59948789f, 0.59808751f, 0.59668659f, 0.59528514f, 0.59388316f, 0.59248068f, 0.59107770f, 0.58967424f, 0.58827032f, 0.58686594f, 0.58546111f, 0.58405586f, 0.58265020f, 0.58124413f, 0.57983767f, 0.57843084f, 0.57702364f, 0.57561610f, 0.57420822f, 0.57280002f, 0.57139151f, 0.56998270f, 0.56857362f, 0.56716426f, 0.56575465f, 0.56434479f, 0.56293470f, 0.56152440f, 0.56011390f, 0.55870320f, 0.55729233f, 0.55588130f, 0.55447012f, 0.55305880f, 0.55164736f, 0.55023581f, 0.54882416f, 0.54741243f, 0.54600062f, 0.54458877f, 0.54317687f, 0.54176494f, 0.54035299f, 0.53894104f, 0.53752910f, 0.53611718f, 0.53470530f, 0.53329347f, 0.53188170f, 0.53047001f, 0.52905841f, 0.52764691f, 0.52623553f, 0.52482427f, 0.52341316f, 0.52200221f, 0.52059143f, 0.51918083f, 0.51777042f, 0.51636023f, 0.51495025f, 0.51354052f, 0.51213103f, 0.51072181f, 0.50931286f, 0.50790420f, 0.50649584f, 0.50508780f, 0.50368009f, 0.50227272f, 0.50086570f, 0.49945905f, 0.49805279f, 0.49664692f, 0.49524146f, 0.49383642f, 0.49243182f, 0.49102766f, 0.48962397f, 0.48822075f, 0.48681801f, 0.48541578f, 0.48401407f, 0.48261288f, 0.48121223f, 0.47981213f, 0.47841261f, 0.47701366f, 0.47561531f, 0.47421756f, 0.47282043f, 0.47142394f, 0.47002809f, 0.46863290f, 0.46723838f, 0.46584455f, 0.46445142f, 0.46305900f, 0.46166730f, 0.46027634f, 0.45888614f, 0.45749669f, 0.45610803f, 0.45472015f, 0.45333308f, 0.45194683f, 0.45056140f, 0.44917682f, 0.44779309f, 0.44641023f, 0.44502826f, 0.44364718f, 0.44226700f, 0.44088775f, 0.43950943f, 0.43813206f, 0.43675564f, 0.43538020f, 0.43400575f, 0.43263229f, 0.43125985f, 0.42988843f, 0.42851805f, 0.42714872f, 0.42578045f, 0.42441326f, 0.42304715f, 0.42168215f, 0.42031826f, 0.41895550f, 0.41759389f, 0.41623342f, 0.41487412f, 0.41351600f, 0.41215907f, 0.41080335f, 0.40944884f, 0.40809556f, 0.40674353f, 0.40539275f, 0.40404324f, 0.40269501f, 0.40134807f, 0.40000244f, 0.39865813f, 0.39731515f, 0.39597352f, 0.39463324f, 0.39329433f, 0.39195680f, 0.39062067f, 0.38928595f, 0.38795264f, 0.38662077f, 0.38529035f, 0.38396138f, 0.38263388f, 0.38130786f, 0.37998334f, 0.37866033f, 0.37733884f, 0.37601887f, 0.37470046f, 0.37338360f, 0.37206831f, 0.37075461f, 0.36944249f, 0.36813199f, 0.36682310f, 0.36551585f, 0.36421024f, 0.36290629f, 0.36160400f, 0.36030339f, 0.35900448f, 0.35770728f, 0.35641179f, 0.35511803f, 0.35382601f, 0.35253575f, 0.35124725f, 0.34996053f, 0.34867560f, 0.34739248f, 0.34611117f, 0.34483168f, 0.34355404f, 0.34227824f, 0.34100431f, 0.33973225f, 0.33846208f, 0.33719381f, 0.33592745f, 0.33466302f, 0.33340051f, 0.33213996f, 0.33088136f, 0.32962473f, 0.32837008f, 0.32711743f, 0.32586678f, 0.32461815f, 0.32337156f, 0.32212700f, 0.32088449f, 0.31964405f, 0.31840568f, 0.31716941f, 0.31593523f, 0.31470316f, 0.31347321f, 0.31224540f, 0.31101974f, 0.30979623f, 0.30857489f, 0.30735574f, 0.30613877f, 0.30492401f, 0.30371146f, 0.30250114f, 0.30129305f, 0.30008722f, 0.29888364f, 0.29768234f, 0.29648332f, 0.29528659f, 0.29409217f, 0.29290007f, 0.29171030f, 0.29052286f, 0.28933777f, 0.28815505f, 0.28697470f, 0.28579673f, 0.28462116f, 0.28344799f, 0.28227724f, 0.28110892f, 0.27994304f, 0.27877961f, 0.27761864f, 0.27646014f, 0.27530413f, 0.27415060f, 0.27299959f, 0.27185109f, 0.27070511f, 0.26956167f, 0.26842078f, 0.26728245f, 0.26614669f, 0.26501351f, 0.26388292f, 0.26275493f, 0.26162955f, 0.26050680f, 0.25938668f, 0.25826920f, 0.25715437f, 0.25604222f, 0.25493273f, 0.25382594f, 0.25272184f, 0.25162044f, 0.25052176f, 0.24942581f, 0.24833260f, 0.24724214f, 0.24615443f, 0.24506949f, 0.24398734f, 0.24290797f, 0.24183139f, 0.24075763f, 0.23968669f, 0.23861858f, 0.23755330f, 0.23649088f, 0.23543132f, 0.23437462f, 0.23332081f, 0.23226988f, 0.23122185f, 0.23017674f, 0.22913454f, 0.22809527f, 0.22705894f, 0.22602555f, 0.22499513f, 0.22396767f, 0.22294319f, 0.22192170f, 0.22090321f, 0.21988772f, 0.21887525f, 0.21786580f, 0.21685939f, 0.21585602f, 0.21485570f, 0.21385845f, 0.21286428f, 0.21187318f, 0.21088518f, 0.20990027f, 0.20891848f, 0.20793981f, 0.20696426f, 0.20599185f, 0.20502259f, 0.20405649f, 0.20309355f, 0.20213378f, 0.20117720f, 0.20022381f, 0.19927362f, 0.19832664f, 0.19738288f, 0.19644235f, 0.19550506f, 0.19457101f, 0.19364022f, 0.19271268f, 0.19178843f, 0.19086745f, 0.18994976f, 0.18903537f, 0.18812428f, 0.18721651f, 0.18631207f, 0.18541095f, 0.18451318f, 0.18361876f, 0.18272769f, 0.18183999f, 0.18095567f, 0.18007473f, 0.17919718f, 0.17832302f, 0.17745228f, 0.17658495f, 0.17572105f, 0.17486058f, 0.17400354f, 0.17314996f, 0.17229983f, 0.17145317f, 0.17060998f, 0.16977027f, 0.16893404f, 0.16810132f, 0.16727209f, 0.16644638f, 0.16562419f, 0.16480553f, 0.16399040f, 0.16317881f, 0.16237078f, 0.16156630f, 0.16076538f, 0.15996804f, 0.15917428f, 0.15838411f, 0.15759754f, 0.15681456f, 0.15603520f, 0.15525945f, 0.15448733f, 0.15371884f, 0.15295399f, 0.15219279f, 0.15143524f, 0.15068135f, 0.14993113f, 0.14918459f, 0.14844173f, 0.14770255f, 0.14696707f, 0.14623530f, 0.14550723f, 0.14478289f, 0.14406226f, 0.14334537f, 0.14263221f, 0.14192280f, 0.14121713f, 0.14051523f, 0.13981709f, 0.13912271f, 0.13843212f, 0.13774531f, 0.13706229f, 0.13638306f, 0.13570764f, 0.13503603f, 0.13436823f, 0.13370425f, 0.13304410f, 0.13238779f, 0.13173532f, 0.13108669f, 0.13044192f, 0.12980100f, 0.12916395f, 0.12853077f, 0.12790146f, 0.12727604f, 0.12665451f, 0.12603687f, 0.12542313f, 0.12481330f, 0.12420738f, 0.12360538f, 0.12300730f, 0.12241315f, 0.12182293f, 0.12123665f, 0.12065432f, 0.12007594f, 0.11950152f, 0.11893106f, 0.11836456f, 0.11780204f, 0.11724349f, 0.11668893f, 0.11613836f, 0.11559178f, 0.11504919f, 0.11451062f, 0.11397605f, 0.11344549f, 0.11291895f, 0.11239644f, 0.11187796f, 0.11136351f, 0.11085309f, 0.11034673f, 0.10984440f, 0.10934614f, 0.10885193f, 0.10836178f, 0.10787569f, 0.10739368f, 0.10691575f, 0.10644189f, 0.10597213f, 0.10550644f, 0.10504486f, 0.10458737f, 0.10413398f, 0.10368470f, 0.10323953f, 0.10279848f, 0.10236154f, 0.10192873f, 0.10150005f, 0.10107549f, 0.10065508f, 0.10023880f, 0.09982666f, 0.09941867f, 0.09901484f, 0.09861515f, 0.09821963f, 0.09782827f, 0.09744107f, 0.09705805f, 0.09667920f, 0.09630452f, 0.09593402f, 0.09556771f, 0.09520559f, 0.09484765f, 0.09449391f, 0.09414437f, 0.09379903f, 0.09345789f, 0.09312096f, 0.09278824f, 0.09245973f, 0.09213544f, 0.09181537f, 0.09149952f, 0.09118790f, 0.09088050f, 0.09057734f, 0.09027841f, 0.08998372f, 0.08969327f, 0.08940706f, 0.08912510f, 0.08884738f, 0.08857392f, 0.08830470f, 0.08803975f, 0.08777905f, 0.08752261f, 0.08727044f, 0.08702253f, 0.08677889f, 0.08653952f, 0.08630442f, 0.08607359f, 0.08584704f, 0.08562478f, 0.08540679f, 0.08519308f, 0.08498366f, 0.08477853f, 0.08457769f, 0.08438113f, 0.08418887f, 0.08400090f, 0.08381724f, 0.08363786f, 0.08346279f, 0.08329202f, 0.08312555f, 0.08296339f, 0.08280553f, 0.08265198f, 0.08250274f, 0.08235781f, 0.08221719f, 0.08208088f, 0.08194889f, 0.08182121f, 0.08169786f, 0.08157881f, 0.08146409f, 0.08135369f, 0.08124761f, 0.08114585f, 0.08104841f, 0.08095530f, 0.08086651f, 0.08078205f, 0.08070192f, 0.08062611f, 0.08055463f, 0.08048748f, 0.08042466f, 0.08036617f, 0.08031201f, 0.08026218f, 0.08021668f, 0.08017551f, 0.08013868f, 0.08010618f, 0.08007801f, 0.08005417f, 0.08003467f, 0.08001950f, 0.08000867f, 0.08000217f, 0.08000000f};
static const float win_hamming_1024[] = {0.08000000f, 0.08000868f, 0.08003470f, 0.08007808f, 0.08013881f, 0.08021689f, 0.08031231f, 0.08042507f, 0.08055517f, 0.08070260f, 0.08086736f, 0.08104944f, 0.08124883f, 0.08146552f, 0.08169951f, 0.08195079f, 0.08221935f, 0.08250518f, 0.08280827f, 0.08312860f, 0.08346617f, 0.08382096f, 0.08419296f, 0.08458215f, 0.08498853f, 0.08541206f, 0.08585275f, 0.08631057f, 0.08678550f, 0.08727753f, 0.08778663f, 0.08831280f, 0.08885600f, 0.08941623f, 0.08999345f, 0.09058764f, 0.09119879f, 0.09182687f, 0.09247186f, 0.09313373f, 0.09381245f, 0.09450801f, 0.09522037f, 0.09594951f, 0.09669540f, 0.09745802f, 0.09823733f, 0.09903330f, 0.09984591f, 0.10067512f, 0.10152090f, 0.10238323f, 0.10326206f, 0.10415737f, 0.10506912f, 0.10599728f, 0.10694181f, 0.10790267f, 0.10887984f, 0.10987326f, 0.11088292f, 0.11190876f, 0.11295075f, 0.11400885f, 0.11508302f, 0.11617322f, 0.11727941f, 0.11840154f, 0.11953958f, 0.12069348f, 0.12186319f, 0.12304868f, 0.12424990f, 0.12546680f, 0.12669934f, 0.12794747f, 0.12921114f, 0.13049031f, 0.13178493f, 0.13309495f, 0.13442031f, 0.13576098f, 0.13711690f, 0.13848801f, 0.13987427f, 0.14127562f, 0.14269202f, 0.14412340f, 0.14556972f, 0.14703091f, 0.14850693f, 0.14999772f, 0.15150322f, 0.15302337f, 0.15455813f, 0.15610742f, 0.15767120f, 0.15924939f, 0.16084195f, 0.16244882f, 0.16406992f, 0.16570521f, 0.16735462f, 0.16901808f, 0.17069554f, 0.17238693f, 0.17409219f, 0.17581125f, 0.17754405f, 0.17929052f, 0.18105060f, 0.18282422f, 0.18461131f, 0.18641181f, 0.18822565f, 0.19005275f, 0.19189306f, 0.19374650f, 0.19561301f, 0.19749250f, 0.19938492f, 0.20129018f, 0.20320822f, 0.20513897f, 0.20708234f, 0.20903828f, 0.21100670f, 0.21298753f, 0.21498070f, 0.21698613f, 0.21900374f, 0.22103346f, 0.22307522f, 0.22512893f, 0.22719452f, 0.22927190f, 0.23136101f, 0.23346177f, 0.23557408f, 0.23769788f, 0.23983308f, 0.24197961f, 0.24413738f, 0.24630631f, 0.24848632f, 0.25067733f, 0.25287925f, 0.25509200f, 0.25731549f, 0.25954966f, 0.26179440f, 0.26404964f, 0.26631528f, 0.26859125f, 0.27087746f, 0.27317382f, 0.27548025f, 0.27779665f, 0.28012295f, 0.28245905f, 0.28480486f, 0.28716030f, 0.28952528f, 0.29189971f, 0.29428350f, 0.29667656f, 0.29907879f, 0.30149011f, 0.30391043f, 0.30633966f, 0.30877770f, 0.31122447f, 0.31367986f, 0.31614379f, 0.31861617f, 0.32109689f, 0.32358588f, 0.32608303f, 0.32858825f, 0.33110144f, 0.33362251f, 0.33615137f, 0.33868792f, 0.34123206f, 0.34378370f, 0.34634275f, 0.34890909f, 0.35148265f, 0.35406332f, 0.35665100f, 0.35924560f, 0.36184702f, 0.36445515f, 0.36706991f, 0.36969120f, 0.37231891f, 0.37495294f, 0.37759320f, 0.38023958f, 0.38289200f, 0.38555034f, 0.38821450f, 0.39088439f, 0.39355991f, 0.39624095f, 0.39892741f, 0.40161920f, 0.40431620f, 0.40701833f, 0.40972547f, 0.41243752f, 0.41515439f, 0.41787596f, 0.42060215f, 0.42333283f, 0.42606792f, 0.42880731f, 0.43155089f, 0.43429856f, 0.43705022f, 0.43980576f, 0.44256509f, 0.44532808f, 0.44809465f, 0.45086469f, 0.45363809f, 0.45641474f, 0.45919455f, 0.46197741f, 0.46476321f, 0.46755185f, 0.47034322f, 0.47313722f, 0.47593374f, 0.47873268f, 0.48153393f, 0.48433739f, 0.48714294f, 0.48995049f, 0.49275993f, 0.49557115f, 0.49838404f, 0.50119851f, 0.50401444f, 0.50683172f, 0.50965026f, 0.51246994f, 0.51529067f, 0.51811232f, 0.52093480f, 0.52375800f, 0.52658181f, 0.52940612f, 0.53223084f, 0.53505585f, 0.53788104f, 0.54070632f, 0.54353157f, 0.54635669f, 0.54918156f, 0.55200609f, 0.55483017f, 0.55765369f, 0.56047654f, 0.56329862f, 0.56611982f, 0.56894003f, 0.57175916f, 0.57457708f, 0.57739370f, 0.58020891f, 0.58302261f, 0.58583468f, 0.58864502f, 0.59145352f, 0.59426009f, 0.59706461f, 0.59986697f, 0.60266708f, 0.60546483f, 0.60826010f, 0.61105280f, 0.61384282f, 0.61663005f, 0.61941439f, 0.62219574f, 0.62497399f, 0.62774903f, 0.63052076f, 0.63328907f, 0.63605387f, 0.63881504f, 0.64157249f, 0.64432610f, 0.64707578f, 0.64982142f, 0.65256291f, 0.65530016f, 0.65803307f, 0.66076151f, 0.66348541f, 0.66620464f, 0.66891911f, 0.67162872f, 0.67433337f, 0.67703295f, 0.67972735f, 0.68241649f, 0.68510026f, 0.68777855f, 0.69045126f, 0.69311830f, 0.69577957f, 0.69843496f, 0.70108437f, 0.70372770f, 0.70636486f, 0.70899575f, 0.71162025f, 0.71423829f, 0.71684975f, 0.71945454f, 0.72205256f, 0.72464371f, 0.72722790f, 0.72980502f, 0.73237499f, 0.73493769f, 0.73749305f, 0.74004095f, 0.74258131f, 0.74511403f, 0.74763900f, 0.75015615f, 0.75266537f, 0.75516656f, 0.75765964f, 0.76014451f, 0.76262107f, 0.76508924f, 0.76754891f, 0.77000000f, 0.77244241f, 0.77487606f, 0.77730084f, 0.77971668f, 0.78212347f, 0.78452113f, 0.78690956f, 0.78928868f, 0.79165839f, 0.79401861f, 0.79636925f, 0.79871022f, 0.80104143f, 0.80336279f, 0.80567422f, 0.80797562f, 0.81026692f, 0.81254802f, 0.81481884f, 0.81707929f, 0.81932929f, 0.82156875f, 0.82379759f, 0.82601573f, 0.82822307f, 0.83041955f, 0.83260506f, 0.83477954f, 0.83694290f, 0.83909506f, 0.84123594f, 0.84336545f, 0.84548352f, 0.84759006f, 0.84968500f, 0.85176826f, 0.85383976f, 0.85589942f, 0.85794716f, 0.85998291f, 0.86200658f, 0.86401812f, 0.86601742f, 0.86800443f, 0.86997907f, 0.87194125f, 0.87389092f, 0.87582799f, 0.87775239f, 0.87966405f, 0.88156290f, 0.88344887f, 0.88532187f, 0.88718185f, 0.88902874f, 0.89086245f, 0.89268294f, 0.89449011f, 0.89628392f, 0.89806428f, 0.89983114f, 0.90158442f, 0.90332407f, 0.90505000f, 0.90676217f, 0.90846050f, 0.91014494f, 0.91181540f, 0.91347185f, 0.91511420f, 0.91674241f, 0.91835640f, 0.91995612f, 0.92154150f, 0.92311250f, 0.92466904f, 0.92621107f, 0.92773853f, 0.92925137f, 0.93074952f, 0.93223293f, 0.93370154f, 0.93515530f, 0.93659416f, 0.93801806f, 0.93942694f, 0.94082075f, 0.94219944f, 0.94356296f, 0.94491126f, 0.94624428f, 0.94756198f, 0.94886431f, 0.95015121f, 0.95142263f, 0.95267854f, 0.95391888f, 0.95514361f, 0.95635267f, 0.95754603f, 0.95872364f, 0.95988545f, 0.96103143f, 0.96216152f, 0.96327568f, 0.96437388f, 0.96545607f, 0.96652221f, 0.96757226f, 0.96860618f, 0.96962393f, 0.97062548f, 0.97161078f, 0.97257980f, 0.97353250f, 0.97446885f, 0.97538881f, 0.97629234f, 0.97717942f, 0.97805000f, 0.97890406f, 0.97974156f, 0.98056247f, 0.98136677f, 0.98215441f, 0.98292538f, 0.98367963f, 0.98441715f, 0.98513791f, 0.98584187f, 0.98652902f, 0.98719932f, 0.98785275f, 0.98848928f, 0.98910890f, 0.98971157f, 0.99029729f, 0.99086601f, 0.99141773f, 0.99195241f, 0.99247005f, 0.99297062f, 0.99345411f, 0.99392048f, 0.99436974f, 0.99480185f, 0.99521681f, 0.99561459f, 0.99599519f, 0.99635858f, 0.99670477f, 0.99703372f, 0.99734543f, 0.99763989f, 0.99791708f, 0.99817701f, 0.99841964f, 0.99864499f, 0.99885303f, 0.99904377f, 0.99921718f, 0.99937328f, 0.99951204f, 0.99963347f, 0.99973757f, 0.99982432f, 0.99989372f, 0.99994577f, 0.99998048f, 0.99999783f, 0.99999783f, 0.99998048f, 0.99994577f, 0.99989372f, 0.99982432f, 0.99973757f, 0.99963347f, 0.99951204f, 0.99937328f, 0.99921718f, 0.99904377f, 0.99885303f, 0.99864499f, 0.99841964f, 0.99817701f, 0.99791708f, 0.99763989f, 0.99734543f, 0.99703372f, 0.99670477f, 0.99635858f, 0.99599519f, 0.99561459f, 0.99521681f, 0.99480185f, 0.99436974f, 0.99392048f, 0.99345411f, 0.99297062f, 0.99247005f, 0.99195241f, 0.99141773f, 0.99086601f, 0.99029729f, 0.98971157f, 0.98910890f, 0.98848928f, 0.98785275f, 0.98719932f, 0.98652902f, 0.98584187f, 0.98513791f, 0.98441715f, 0.98367963f, 0.98292538f, 0.98215441f, 0.98136677f, 0.98056247f, 0.97974156f, 0.97890406f, 0.97805000f, 0.97717942f, 0.97629234f, 0.97538881f, 0.97446885f, 0.97353250f, 0.97257980f, 0.97161078f, 0.97062548f, 0.96962393f, 0.96860618f, 0.96757226f, 0.96652221f, 0.96545607f, 0.96437388f, 0.96327568f, 0.96216152f, 0.96103143f, 0.95988545f, 0.95872364f, 0.95754603f, 0.95635267f, 0.95514361f, 0.95391888f, 0.95267854f, 0.95142263f, 0.95015121f, 0.94886431f, 0.94756198f, 0.94624428f, 0.94491126f, 0.94356296f, 0.94219944f, 0.94082075f, 0.93942694f, 0.93801806f, 0.93659416f, 0.93515530f, 0.93370154f, 0.93223293f, 0.93074952f, 0.92925137f, 0.92773853f, 0.92621107f, 0.92466904f, 0.92311250f, 0.92154150f, 0.91995612f, 0.91835640f, 0.91674241f, 0.91511420f, 0.91347185f, 0.91181540f, 0.91014494f, 0.90846050f, 0.90676217f, 0.90505000f, 0.90332407f, 0.90158442f, 0.89983114f, 0.89806428f, 0.89628392f, 0.89449011f, 0.89268294f, 0.89086245f, 0.88902874f, 0.88718185f, 0.88532187f, 0.88344887f, 0.88156290f, 0.87966405f, 0.87775239f, 0.87582799f, 0.87389092f, 0.87194125f, 0.86997907f, 0.86800443f, 0.86601742f, 0.86401812f, 0.86200658f, 0.85998291f, 0.85794716f, 0.85589942f, 0.85383976f, 0.85176826f, 0.84968500f, 0.84759006f, 0.84548352f, 0.84336545f, 0.84123594f, 0.83909506f, 0.83694290f, 0.83477954f, 0.83260506f, 0.83041955f, 0.82822307f, 0.82601573f, 0.82379759f, 0.82156875f, 0.81932929f, 0.81707929f, 0.81481884f, 0.81254802f, 0.81026692f, 0.80797562f, 0.80567422f, 0.80336279f, 0.80104143f, 0.79871022f, 0.79636925f, 0.79401861f, 0.79165839f, 0.78928868f, 0.78690956f, 0.78452113f, 0.78212347f, 0.77971668f, 0.77730084f, 0.77487606f, 0.77244241f, 0.77000000f, 0.76754891f, 0.76508924f, 0.76262107f, 0.76014451f, 0.75765964f, 0.75516656f, 0.75266537f, 0.75015615f, 0.74763900f, 0.74511403f, 0.74258131f, 0.74004095f, 0.73749305f, 0.73493769f, 0.73237499f, 0.72980502f, 0.72722790f, 0.72464371f, 0.72205256f, 0.71945454f, 0.71684975f, 0.71423829f, 0.71162025f, 0.70899575f, 0.70636486f, 0.70372770f, 0.70108437f, 0.69843496f, 0.69577957f, 0.69311830f, 0.69045126f, 0.68777855f, 0.68510026f, 0.68241649f, 0.67972735f, 0.67703295f, 0.67433337f, 0.67162872f, 0.66891911f, 0.66620464f, 0.66348541f, 0.66076151f, 0.65803307f, 0.65530016f, 0.65256291f, 0.64982142f, 0.64707578f, 0.64432610f, 0.64157249f, 0.63881504f, 0.63605387f, 0.63328907f, 0.63052076f, 0.62774903f, 0.62497399f, 0.62219574f, 0.61941439f, 0.61663005f, 0.61384282f, 0.61105280f, 0.60826010f, 0.60546483f, 0.60266708f, 0.59986697f, 0.59706461f, 0.59426009f, 0.59145352f, 0.58864502f, 0.58583468f, 0.58302261f, 0.58020891f, 0.57739370f, 0.57457708f, 0.57175916f, 0.56894003f, 0.56611982f, 0.56329862f, 0.56047654f, 0.55765369f, 0.55483017f, 0.55200609f, 0.54918156f, 0.54635669f, 0.54353157f, 0.54070632f, 0.53788104f, 0.53505585f, 0.53223084f, 0.52940612f, 0.52658181f, 0.52375800f, 0.52093480f, 0.51811232f, 0.51529067f, 0.51246994f, 0.50965026f, 0.50683172f, 0.50401444f, 0.50119851f, 0.49838404f, 0.49557115f, 0.49275993f, 0.48995049f, 0.48714294f, 0.48433739f, 0.48153393f, 0.47873268f, 0.47593374f, 0.47313722f, 0.47034322f, 0.46755185f, 0.46476321f, 0.46197741f, 0.45919455f, 0.45641474f, 0.45363809f, 0.45086469f, 0.44809465f, 0.44532808f, 0.44256509f, 0.43980576f, 0.43705022f, 0.43429856f, 0.43155089f, 0.42880731f, 0.42606792f, 0.42333283f, 0.42060215f, 0.41787596f, 0.41515439f, 0.41243752f, 0.40972547f, 0.40701833f, 0.40431620f, 0.40161920f, 0.39892741f, 0.39624095f, 0.39355991f, 0.39088439f, 0.38821450f, 0.38555034f, 0.38289200f, 0.38023958f, 0.37759320f, 0.37495294f, 0.37231891f, 0.36969120f, 0.36706991f, 0.36445515f, 0.36184702f, 0.35924560f, 0.35665100f, 0.35406332f, 0.35148265f, 0.34890909f, 0.34634275f, 0.34378370f, 0.34123206f, 0.33868792f, 0.33615137f, 0.33362251f, 0.33110144f, 0.32858825f, 0.32608303f, 0.32358588f, 0.32109689f, 0.31861617f, 0.31614379f, 0.31367986f, 0.31122447f, 0.30877770f, 0.30633966f, 0.30391043f, 0.30149011f, 0.29907879f, 0.29667656f, 0.29428350f, 0.29189971f, 0.28952528f, 0.28716030f, 0.28480486f, 0.28245905f, 0.28012295f, 0.27779665f, 0.27548025f, 0.27317382f, 0.27087746f, 0.26859125f, 0.26631528f, 0.26404964f, 0.26179440f, 0.25954966f, 0.25731549f, 0.25509200f, 0.25287925f, 0.25067733f, 0.24848632f, 0.24630631f, 0.24413738f, 0.24197961f, 0.23983308f, 0.23769788f, 0.23557408f, 0.23346177f, 0.23136101f, 0.22927190f, 0.22719452f, 0.22512893f, 0.22307522f, 0.22103346f, 0.21900374f, 0.21698613f, 0.21498070f, 0.21298753f, 0.21100670f, 0.20903828f, 0.20708234f, 0.20513897f, 0.20320822f, 0.20129018f, 0.19938492f, 0.19749250f, 0.19561301f, 0.19374650f, 0.19189306f, 0.19005275f, 0.18822565f, 0.18641181f, 0.18461131f, 0.18282422f, 0.18105060f, 0.17929052f, 0.17754405f, 0.17581125f, 0.17409219f, 0.17238693f, 0.17069554f, 0.16901808f, 0.16735462f, 0.16570521f, 0.16406992f, 0.16244882f, 0.16084195f, 0.15924939f, 0.15767120f, 0.15610742f, 0.15455813f, 0.15302337f, 0.15150322f, 0.14999772f, 0.14850693f, 0.14703091f, 0.14556972f, 0.14412340f, 0.14269202f, 0.14127562f, 0.13987427f, 0.13848801f, 0.13711690f, 0.13576098f, 0.13442031f, 0.13309495f, 0.13178493f, 0.13049031f, 0.12921114f, 0.12794747f, 0.12669934f, 0.12546680f, 0.12424990f, 0.12304868f, 0.12186319f, 0.12069348f, 0.11953958f, 0.11840154f, 0.11727941f, 0.11617322f, 0.11508302f, 0.11400885f, 0.11295075f, 0.11190876f, 0.11088292f, 0.10987326f, 0.10887984f, 0.10790267f, 0.10694181f, 0.10599728f, 0.10506912f, 0.10415737f, 0.10326206f, 0.10238323f, 0.10152090f, 0.10067512f, 0.09984591f, 0.09903330f, 0.09823733f, 0.09745802f, 0.09669540f, 0.09594951f, 0.09522037f, 0.09450801f, 0.09381245f, 0.09313373f, 0.09247186f, 0.09182687f, 0.09119879f, 0.09058764f, 0.08999345f, 0.08941623f, 0.08885600f, 0.08831280f, 0.08778663f, 0.08727753f, 0.08678550f, 0.08631057f, 0.08585275f, 0.08541206f, 0.08498853f, 0.08458215f, 0.08419296f, 0.08382096f, 0.08346617f, 0.08312860f, 0.08280827f, 0.08250518f, 0.08221935f, 0.08195079f, 0.08169951f, 0.08146552f, 0.08124883f, 0.08104944f, 0.08086736f, 0.08070260f, 0.08055517f, 0.08042507f, 0.08031231f, 0.08021689f, 0.08013881f, 0.08007808f, 0.08003470f, 0.08000868f, 0.08000000f};
#define NUM_SAMPLES 1024
#define BIN_SIZE (44444.444f / (NUM_SAMPLES/2.0f))
#define PK_MINDIST 1.5f
#define PK_MAXFREQ 20000.0f
volatile bool dma_done = false;
void done_cb(DMA_HandleTypeDef*dma)
{
dma_done = true;
}
void graph(uint32_t width, uint32_t height, float *values, uint32_t count)
{
float max = FLT_MIN;
float min = FLT_MAX;
for (int i = 0; i < count; i++) {
float f = values[i];
if (f < min) min = f;
if (f > max) max = f;
}
int xstep = count / width;
float ystep = 1; //(float)(max - min) / (float)height;
// this somehow doenst work now
char buf[100];
sprintf(buf, "min %d max %d, ystep %d, h %d\r\n", (int)min*1000, (int)max*1000, (int)ystep*1000, height);
print(buf);
for (int i = height-1; i >= 0; i--) {
float thr = i*ystep;
for (int j = 0; j < width; j++) {
float acu = 0;
int cnt = 0;
for (int k = j*xstep; k < (j+1)*xstep && k < count; k++, cnt++) {
acu += values[k];
}
acu /= (float)cnt;
float sample = acu;//values[j*xstep];
if (sample >= thr) {
print("#");
} else {
print(" ");
}
}
print("\r\n");
}
}
/**
* Rolling average centered at a bin
*
* @param arr - array of bins
* @param count - number of bins
* @param pos - position we're intersted in
* @param len - size of the rolling window, centered around the position
* @return average within the window, excluding bin at position 'pos'
*/
static float ravg(float *arr, uint32_t count, uint32_t pos, uint32_t len)
{
// XXX this needs some adjustments, it's not perfectly centered
// if we're at the end or beginning, use only bins we have available
uint32_t from = (pos > len/2 ? pos-len/2 : 0);
uint32_t to = (pos < count-len/2 ? pos+len/2 : count-1);
float acu = 0;
for (uint32_t i = from; i <= to; i++) {
if (i == pos) continue;
acu += arr[i];
}
acu /= (to - from); // not +1 because we skip the middle
return acu;
}
/**
* Quadratic interpolation to find the real peak position and magnitude
*
* @param pk - peak struct to store the results in
* @param values - the bins array
* @param vcount - size of the bins array
* @param pos - position of the peak we're triyng to analyze
*/
static void qinterp(struct peak *pk, const float *values, uint32_t vcount, uint32_t pos)
{
float a = (pos>0?values[pos-1]:values[pos]);
float b = values[pos];
float c = (pos<vcount-2?values[pos+1]:values[pos]);
float p = 0.5 * (a-c)/(a-2*b+c);
// safeguard
if (p>0.5 || p<-0.5) p=0;
pk->position = pos + p;
pk->magnitude = b - 0.25 * (a - c) * p;
}
/**
* Detect peaks in a real float spectrum
*
* @param peaks - destination for the peak detect algorithm, peaks are sorted from the most important
* @param pcount - number of peaks to detect
* @param values - the spectrum as an array of bin magnitudes
* @param vcount - number of bins in the spectrum
* @return average level (excluding the peaks)
*/
float pkdetect(struct peak *peaks, uint32_t pcount, float *values, uint32_t vcount)
{
uint32_t used_peaks = 0;
// clear the table
for (uint32_t i = 0; i < pcount; i++) {
peaks[i].position
= peaks[i].magnitude
= peaks[i].weight = 0;
}
struct peak pk = {0}; // scratch peak
float prev = 0;
float sum = 0;
for (uint32_t i = 0; i < vcount; i++) {
float base = ravg(values, vcount, i, 32);
float raw = values[i];
float normed = raw / base;
if (i > 0) {
// difference from the previous bin (this serves as the primary peak detection factor)
float diff = normed - prev;
if (diff > 0) {
// find the precise position and magnitude
qinterp(&pk, values, vcount, i);
// weight for sorting the peaks
pk.weight = diff * pk.magnitude;
// !!!! This constant must be adjusted if bin is resized
if (pk.position >= (PK_MAXFREQ/BIN_SIZE)) {
// too high, discard
goto pk_done;
}
// try to fit it in the peak list
{
// first we look if there's one close enough to overwrite it or use instead
for (uint32_t j = 0; j < pcount; j++) {
if ((pk.position > peaks[j].position - PK_MINDIST) && (pk.position < peaks[j].position + PK_MINDIST)) { // this number determines the min distance of peaks in bin units
// replace if we have better weight
if (peaks[j].weight < pk.weight) {
peaks[j] = pk;
} // else discard it
goto pk_done; // exit the for and skip the following for loop
}
}
// look for a place for this new peak, shift what is behind it
for (uint32_t j = 0; j < pcount; j++) {
// peaks are sorted by weight
if (pk.weight > peaks[j].weight) {
// shift the tail to make room
if (used_peaks > 0) {
for (uint32_t k = used_peaks; k > j; k--) {
peaks[k] = peaks[k-1];
}
}
peaks[j] = pk;
if (used_peaks < pcount) used_peaks++; // increment the counter if the list wasn't full yet and grew
break;
}
}
}
pk_done:;
}
}
prev = normed;
sum += raw; // this is rms
}
// now remove some area around the found peaks (NOTE: this will cause double removal if two peaks happened to be very close together)
float pksum = 0;
const uint32_t pkexpand = 4;
for (uint32_t i = 0; i < pcount; i++) {
uint32_t pos = (uint32_t)roundf(peaks[i].position);
uint32_t from = (pos > pkexpand/2 ? pos-pkexpand/2 : 0);
uint32_t to = (pos < vcount-pkexpand/2 ? pos+pkexpand/2 : vcount-1);
for (uint32_t j = from; j <= to; j++) {
pksum += values[j];
}
}
float noise = (sum - pksum);
if (noise < 0) noise = 0;
noise /= vcount;
// sort the peaks by magnitude (they are now sorted by weight, which is useful for detecting prominence but confusing for practical use later)
for (uint32_t i = 0; i < pcount-1; i++) {
float bestmag = peaks[i].magnitude;
uint32_t bmpos = i;
for (uint32_t j = i+1; j < pcount; j++) {
if (peaks[j].magnitude > bestmag) {
bestmag = peaks[j].magnitude;
bmpos = j;
}
}
if (bmpos != i) {
// we found a better peak in the tail, let's swap
pk = peaks[i];
peaks[i] = peaks[bmpos];
peaks[bmpos] = pk;
}
}
return noise;
}
union {
uint16_t raw[NUM_SAMPLES];
float flt[NUM_SAMPLES*2];
} samples;
void audio_capture(struct peak *peaks, uint32_t pcount, float *noise, float *totalpower)
{
char buf[100];
print("AUDIO SAMPLING ...\r\n");
print("Starting capture...\r\n");
HAL_StatusTypeDef rv = HAL_ADC_Start_DMA(&hadc, (void*)samples.raw, (uint32_t)NUM_SAMPLES);
assert_param(rv == HAL_OK);
//__enable_irq();
hdma_adc.XferCpltCallback = done_cb;
dma_done = false;
rv = HAL_TIM_Base_Start(&htim2); // kick it off
assert_param(rv == HAL_OK);
print("Capture stared.\r\n");
// wait ...
while(!dma_done) {
HAL_Delay(100);
print("waiting... ");
}
print("\r\nCapture completed.\r\n");
// basic scaling
for (int i=NUM_SAMPLES-1; i >= 0; i--) {
samples.flt[i] = (float)samples.raw[i]/2048.0f;
}
// remove DC offset
float mean;
arm_mean_f32(samples.flt, NUM_SAMPLES, &mean);
for (int i = 0; i < NUM_SAMPLES; i++) {
samples.flt[i] -= mean;
}
// zero out the second half (this is needed because otherwise the fft is not padded by zeros and doesn't work right)
for (int i=NUM_SAMPLES; i < NUM_SAMPLES*2; i++) {
samples.flt[i] = 0;
}
uint32_t bin_count = NUM_SAMPLES/2;
uint32_t samp_count = NUM_SAMPLES;
for (int i = samp_count - 1; i >= 0; i--) {
samples.flt[i * 2 + 1] = 0; // imaginary
samples.flt[i * 2] = samples.flt[i] * win_hamming_1024[i]; // real
}
print("FFT...\r\n");
arm_cfft_f32(&arm_cfft_sR_f32_len1024, samples.flt, 0, true); // bit reversed FFT
print("Magnitude...\r\n");
arm_cmplx_mag_f32(samples.flt, samples.flt, bin_count); // get magnitude (extract real values)
// normalize
print("Scaling...\r\n");
arm_scale_f32(samples.flt, (1.0f/bin_count)*1000.0f, samples.flt, bin_count);
// now we have the spectrum computed in samples.flt
//graph(128, 22, samples.flt, bin_count/8); // doesnt work for some reason
// Find the peaks...
float sum = 0;
for(uint32_t i = 0; i < bin_count; i++) {
sum += samples.flt[i];
}
*totalpower = sum;
*noise = pkdetect(peaks, pcount, samples.flt, bin_count);
for (int i = 0; i < pcount; i++) {
sprintf(buf, "pk %d at %d Hz, mag ", i+1, (int)roundf((peaks[i].position) * BIN_SIZE));
print(buf);
ftoa(peaks[i].magnitude, buf, 6);
print(buf);
print("\r\n");
}
ftoa(*noise, buf, 6);
print("Mean noise per bin = ");
print(buf);
print("\r\n");
}
// ftoa stuff ---------------
// reverses a string 'str' of length 'len'
void reverse(char *str, int len)
{
int i=0, j=len-1, temp;
while (i<j)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++; j--;
}
}
// Converts a given integer x to string str[]. d is the number
// of digits required in output. If d is more than the number
// of digits in x, then 0s are added at the beginning.
int intToStr(int x, char str[], int d)
{
int i = 0;
while (x)
{
str[i++] = (x%10) + '0';
x = x/10;
}
// If number of digits required is more, then
// add 0s at the beginning
while (i < d)
str[i++] = '0';
reverse(str, i);
str[i] = '\0';
return i;
}
// Converts a floating point number to string.
void ftoa(float n, char *res, int afterpoint)
{
// Extract integer part
int ipart = (int)n;
// Extract floating part
float fpart = n - (float)ipart;
// convert integer part to string
int i = intToStr(ipart, res, 0);
// check for display option after point
if (afterpoint != 0)
{
res[i] = '.'; // add dot
// Get the value of fraction part upto given no.
// of points after dot. The third parameter is needed
// to handle cases like 233.007
fpart = fpart * pow(10, afterpoint);
intToStr((int)fpart, res + i + 1, afterpoint);
}
}