[feat][nmsis] add nmsis component and nn,dsp demo

This commit is contained in:
jzlv 2021-09-26 13:38:51 +08:00
parent b2aada479b
commit 5d1126d0f0
989 changed files with 286224 additions and 0 deletions

View file

@ -0,0 +1,5 @@
set(TARGET_REQUIRED_PRIVATE_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(TARGET_REQUIRED_LIBS nmsis)
list(APPEND TARGET_REQUIRED_SRCS cfft.c)
set(mains main.c)
generate_bin()

View file

@ -0,0 +1,469 @@
// Array for TransformFunctions cfftx4
#define ARRAY_SIZE 100
//float32_t
float32_t cfft_testinput_f32_50hz_200Hz[512] = {
2.00000000000000, 0.00000000000000, 1.79670533497009,
-0.744219717332704, 1.26007351067010, -1.26007351067010,
0.581989529813420, -1.40504701603470, 1.11022302462516e-16,
-1.17557050458495, -0.292893218813452, -0.707106781186548,
-0.221231742082474, -0.221231742082474, 0.144973505364599,
0.0600499921067857, 0.618033988749895, 1.11022302462516e-16,
0.965451459415178, -0.399903088302664, 1.00000000000000,
-1.00000000000000, 0.652582529334717, -1.57547359288761,
-7.21644966006352e-16, -1.90211303259031, -0.763007494114494,
-1.84206304048352, -1.39680224666742, -1.39680224666742,
-1.70710678118655, -0.707106781186548, -1.61803398874990,
-4.44089209850063e-16, -1.20002351856331, 0.497066016555608,
-0.642039521920207, 0.642039521920206, -0.178671346220191,
0.431350787252243, 0.00000000000000, 3.67394039744206e-16,
-0.178671346220191, -0.431350787252243, -0.642039521920206,
-0.642039521920206, -1.20002351856331, -0.497066016555607,
-1.61803398874990, 1.22124532708767e-15, -1.70710678118655,
0.707106781186549, -1.39680224666742, 1.39680224666742,
-0.763007494114495, 1.84206304048352, -7.77156117237610e-16,
1.90211303259031, 0.652582529334716, 1.57547359288761,
1.00000000000000, 1.00000000000000, 0.965451459415179,
0.399903088302665, 0.618033988749895, 3.33066907387547e-16,
0.144973505364597, -0.0600499921067852, -0.221231742082475,
0.221231742082476, -0.292893218813452, 0.707106781186550,
-5.55111512312578e-16, 1.17557050458495, 0.581989529813419,
1.40504701603470, 1.26007351067010, 1.26007351067010,
1.79670533497008, 0.744219717332705, 2.00000000000000,
1.22464679914735e-15, 1.79670533497008, -0.744219717332707,
1.26007351067010, -1.26007351067010, 0.581989529813422,
-1.40504701603470, 7.77156117237610e-16, -1.17557050458495,
-0.292893218813452, -0.707106781186549, -0.221231742082475,
-0.221231742082475, 0.144973505364599, 0.0600499921067854,
0.618033988749897, -8.88178419700125e-16, 0.965451459415179,
-0.399903088302667, 0.999999999999999, -1.00000000000000,
0.652582529334721, -1.57547359288761, 1.49880108324396e-15,
-1.90211303259031, -0.763007494114497, -1.84206304048352,
-1.39680224666742, -1.39680224666742, -1.70710678118655,
-0.707106781186545, -1.61803398874990, -1.33226762955019e-15,
-1.20002351856331, 0.497066016555608, -0.642039521920207,
0.642039521920206, -0.178671346220193, 0.431350787252245,
0.00000000000000, 1.10218211923262e-15, -0.178671346220191,
-0.431350787252243, -0.642039521920205, -0.642039521920206,
-1.20002351856332, -0.497066016555606, -1.61803398874989,
-1.55431223447522e-15, -1.70710678118655, 0.707106781186550,
-1.39680224666742, 1.39680224666743, -0.763007494114492,
1.84206304048352, 6.49480469405717e-15, 1.90211303259031,
0.652582529334718, 1.57547359288761, 1.00000000000000,
0.999999999999995, 0.965451459415180, 0.399903088302669,
0.618033988749896, 7.77156117237610e-16, 0.144973505364603,
-0.0600499921067867, -0.221231742082474, 0.221231742082473,
-0.292893218813452, 0.707106781186549, -1.44328993201270e-15,
1.17557050458495, 0.581989529813422, 1.40504701603470,
1.26007351067010, 1.26007351067010, 1.79670533497009,
0.744219717332702, 2.00000000000000, 2.44929359829471e-15,
1.79670533497008, -0.744219717332706, 1.26007351067010,
-1.26007351067010, 0.581989529813419, -1.40504701603470,
-3.77475828372553e-15, -1.17557050458494, -0.292893218813453,
-0.707106781186546, -0.221231742082475, -0.221231742082476,
0.144973505364595, 0.0600499921067846, 0.618033988749893,
7.77156117237610e-16, 0.965451459415176, -0.399903088302660,
1.00000000000000, -0.999999999999998, 0.652582529334716,
-1.57547359288761, 2.66453525910038e-15, -1.90211303259031,
-0.763007494114496, -1.84206304048352, -1.39680224666742,
-1.39680224666742, -1.70710678118655, -0.707106781186546,
-1.61803398874989, 4.88498130835069e-15, -1.20002351856331,
0.497066016555607, -0.642039521920202, 0.642039521920206,
-0.178671346220190, 0.431350787252242, 0.00000000000000,
-3.49210031947972e-15, -0.178671346220191, -0.431350787252243,
-0.642039521920198, -0.642039521920206, -1.20002351856331,
-0.497066016555610, -1.61803398874989, -2.55351295663786e-15,
-1.70710678118655, 0.707106781186549, -1.39680224666742,
1.39680224666742, -0.763007494114502, 1.84206304048352,
-3.16413562018170e-15, 1.90211303259031, 0.652582529334717,
1.57547359288761, 1.00000000000000, 0.999999999999996,
0.965451459415176, 0.399903088302658, 0.618033988749897,
9.99200722162641e-16, 0.144973505364599, -0.0600499921067855,
-0.221231742082476, 0.221231742082477, -0.292893218813451,
0.707106781186554, -2.10942374678780e-15, 1.17557050458494,
0.581989529813421, 1.40504701603470, 1.26007351067009,
1.26007351067011, 1.79670533497008, 0.744219717332711,
2.00000000000000, 3.67394039744206e-15, 1.79670533497008,
-0.744219717332705, 1.26007351067010, -1.26007351067010,
0.581989529813427, -1.40504701603470, 2.22044604925031e-15,
-1.17557050458495, -0.292893218813453, -0.707106781186547,
-0.221231742082473, -0.221231742082472, 0.144973505364605,
0.0600499921067872, 0.618033988749893, 1.22124532708767e-15,
0.965451459415178, -0.399903088302665, 0.999999999999999,
-1.00000000000000, 0.652582529334710, -1.57547359288762,
-1.31006316905768e-14, -1.90211303259031, -0.763007494114495,
-1.84206304048352, -1.39680224666742, -1.39680224666742,
-1.70710678118655, -0.707106781186539, -1.61803398874989,
1.09912079437891e-14, -1.20002351856332, 0.497066016555607,
-0.642039521920203, 0.642039521920206, -0.178671346220186,
0.431350787252238, 0.00000000000000, -8.08638275819206e-15,
-0.178671346220183, -0.431350787252234, -0.642039521920197,
-0.642039521920205, -1.20002351856331, -0.497066016555611,
-1.61803398874989, -3.55271367880050e-15, -1.70710678118655,
0.707106781186548, -1.39680224666743, 1.39680224666741,
-0.763007494114503, 1.84206304048352, -4.32986979603811e-15,
1.90211303259031, 0.652582529334717, 1.57547359288761,
1.00000000000000, 0.999999999999997, 0.965451459415181,
0.399903088302671, 0.618033988749898, 1.44328993201270e-15,
0.144973505364600, -0.0600499921067857, -0.221231742082476,
0.221231742082476, -0.292893218813451, 0.707106781186553,
-2.77555756156289e-15, 1.17557050458494, 0.581989529813420,
1.40504701603470, 1.26007351067010, 1.26007351067010,
1.79670533497009, 0.744219717332697, 2.00000000000000,
4.89858719658941e-15, 1.79670533497009, -0.744219717332704,
1.26007351067010, -1.26007351067010, 0.581989529813413,
-1.40504701603470, -7.54951656745106e-15, -1.17557050458494,
-0.292893218813452, -0.707106781186548, -0.221231742082473,
-0.221231742082472, 0.144973505364604, 0.0600499921067871,
0.618033988749902, -3.88578058618805e-15, 0.965451459415183,
-0.399903088302676, 0.999999999999999, -1.00000000000000,
0.652582529334711, -1.57547359288762, 5.05151476204446e-15,
-1.90211303259031, -0.763007494114493, -1.84206304048352,
-1.39680224666741, -1.39680224666743, -1.70710678118655,
-0.707106781186557, -1.61803398874990, -4.44089209850063e-15,
-1.20002351856332, 0.497066016555606, -0.642039521920216,
0.642039521920207, -0.178671346220195, 0.431350787252247,
0.00000000000000, 3.30654635769785e-15, -0.178671346220190,
-0.431350787252242, -0.642039521920209, -0.642039521920206,
-1.20002351856331, -0.497066016555611, -1.61803398874989,
-4.55191440096314e-15, -1.70710678118655, 0.707106781186546,
-1.39680224666742, 1.39680224666742, -0.763007494114487,
1.84206304048352, -5.44009282066327e-15, 1.90211303259031,
0.652582529334716, 1.57547359288761, 1.00000000000000,
0.999999999999998, 0.965451459415176, 0.399903088302660,
0.618033988749888, -3.66373598126302e-15, 0.144973505364600,
-0.0600499921067860, -0.221231742082475, 0.221231742082476,
-0.292893218813451, 0.707106781186552, 6.88338275267597e-15,
1.17557050458495, 0.581989529813434, 1.40504701603470,
1.26007351067010, 1.26007351067010, 1.79670533497009,
0.744219717332698, 2.00000000000000, -1.16403343982657e-14,
1.79670533497008, -0.744219717332718, 1.26007351067010,
-1.26007351067010, 0.581989529813414, -1.40504701603470,
1.40998324127395e-14, -1.17557050458496, -0.292893218813450,
-0.707106781186561, -0.221231742082479, -0.221231742082482,
0.144973505364593, 0.0600499921067840, 0.618033988749891,
1.99840144432528e-15, 0.965451459415178, -0.399903088302663,
1.00000000000000, -1.00000000000000, 0.652582529334712,
-1.57547359288762, -1.07136521876328e-14, -1.90211303259031,
-0.763007494114476, -1.84206304048353, -1.39680224666741,
-1.39680224666743, -1.70710678118655, -0.707106781186558,
-1.61803398874990, -5.44009282066327e-15, -1.20002351856332,
0.497066016555606, -0.642039521920205, 0.642039521920206,
-0.178671346220187, 0.431350787252239, 0.00000000000000,
-6.61680659921524e-15, -0.178671346220197, -0.431350787252249,
-0.642039521920220, -0.642039521920207, -1.20002351856331,
-0.497066016555612, -1.61803398874989, -5.55111512312578e-15,
-1.70710678118655, 0.707106781186545, -1.39680224666742,
1.39680224666742, -0.763007494114488, 1.84206304048352,
1.02140518265514e-14, 1.90211303259031, 0.652582529334727,
1.57547359288760, 1.00000000000000, 0.999999999999984,
0.965451459415172, 0.399903088302648, 0.618033988749899,
2.10942374678780e-15, 0.144973505364601, -0.0600499921067861,
-0.221231742082475, 0.221231742082475, -0.292893218813452,
0.707106781186552, -1.47659662275146e-14, 1.17557050458493,
0.581989529813403, 1.40504701603470, 1.26007351067009,
1.26007351067011, 1.79670533497008, 0.744219717332714,
2.00000000000000, 7.34788079488412e-15, 1.79670533497009,
-0.744219717332702, 1.26007351067010, -1.26007351067010,
0.581989529813416, -1.40504701603470, -5.99520433297585e-15,
-1.17557050458494, -0.292893218813455, -0.707106781186538,
-0.221231742082479, -0.221231742082483, 0.144973505364592,
0.0600499921067839, 0.618033988749891, 2.33146835171283e-15,
0.965451459415177, -0.399903088302663, 1.00000000000000,
-1.00000000000000, 0.652582529334713, -1.57547359288761,
-9.54791801177635e-15, -1.90211303259031, -0.763007494114508,
-1.84206304048352, -1.39680224666743, -1.39680224666741,
-1.70710678118655, -0.707106781186559};
float32_t cfft_testinput_f32_50hz_200Hz_ref[512] = {
2.00000000000000, 0.00000000000000, 1.79670533497009,
-0.744219717332704, 1.26007351067010, -1.26007351067010,
0.581989529813420, -1.40504701603470, 1.11022302462516e-16,
-1.17557050458495, -0.292893218813452, -0.707106781186548,
-0.221231742082474, -0.221231742082474, 0.144973505364599,
0.0600499921067857, 0.618033988749895, 1.11022302462516e-16,
0.965451459415178, -0.399903088302664, 1.00000000000000,
-1.00000000000000, 0.652582529334717, -1.57547359288761,
-7.21644966006352e-16, -1.90211303259031, -0.763007494114494,
-1.84206304048352, -1.39680224666742, -1.39680224666742,
-1.70710678118655, -0.707106781186548, -1.61803398874990,
-4.44089209850063e-16, -1.20002351856331, 0.497066016555608,
-0.642039521920207, 0.642039521920206, -0.178671346220191,
0.431350787252243, 0.00000000000000, 3.67394039744206e-16,
-0.178671346220191, -0.431350787252243, -0.642039521920206,
-0.642039521920206, -1.20002351856331, -0.497066016555607,
-1.61803398874990, 1.22124532708767e-15, -1.70710678118655,
0.707106781186549, -1.39680224666742, 1.39680224666742,
-0.763007494114495, 1.84206304048352, -7.77156117237610e-16,
1.90211303259031, 0.652582529334716, 1.57547359288761,
1.00000000000000, 1.00000000000000, 0.965451459415179,
0.399903088302665, 0.618033988749895, 3.33066907387547e-16,
0.144973505364597, -0.0600499921067852, -0.221231742082475,
0.221231742082476, -0.292893218813452, 0.707106781186550,
-5.55111512312578e-16, 1.17557050458495, 0.581989529813419,
1.40504701603470, 1.26007351067010, 1.26007351067010,
1.79670533497008, 0.744219717332705, 2.00000000000000,
1.22464679914735e-15, 1.79670533497008, -0.744219717332707,
1.26007351067010, -1.26007351067010, 0.581989529813422,
-1.40504701603470, 7.77156117237610e-16, -1.17557050458495,
-0.292893218813452, -0.707106781186549, -0.221231742082475,
-0.221231742082475, 0.144973505364599, 0.0600499921067854,
0.618033988749897, -8.88178419700125e-16, 0.965451459415179,
-0.399903088302667, 0.999999999999999, -1.00000000000000,
0.652582529334721, -1.57547359288761, 1.49880108324396e-15,
-1.90211303259031, -0.763007494114497, -1.84206304048352,
-1.39680224666742, -1.39680224666742, -1.70710678118655,
-0.707106781186545, -1.61803398874990, -1.33226762955019e-15,
-1.20002351856331, 0.497066016555608, -0.642039521920207,
0.642039521920206, -0.178671346220193, 0.431350787252245,
0.00000000000000, 1.10218211923262e-15, -0.178671346220191,
-0.431350787252243, -0.642039521920205, -0.642039521920206,
-1.20002351856332, -0.497066016555606, -1.61803398874989,
-1.55431223447522e-15, -1.70710678118655, 0.707106781186550,
-1.39680224666742, 1.39680224666743, -0.763007494114492,
1.84206304048352, 6.49480469405717e-15, 1.90211303259031,
0.652582529334718, 1.57547359288761, 1.00000000000000,
0.999999999999995, 0.965451459415180, 0.399903088302669,
0.618033988749896, 7.77156117237610e-16, 0.144973505364603,
-0.0600499921067867, -0.221231742082474, 0.221231742082473,
-0.292893218813452, 0.707106781186549, -1.44328993201270e-15,
1.17557050458495, 0.581989529813422, 1.40504701603470,
1.26007351067010, 1.26007351067010, 1.79670533497009,
0.744219717332702, 2.00000000000000, 2.44929359829471e-15,
1.79670533497008, -0.744219717332706, 1.26007351067010,
-1.26007351067010, 0.581989529813419, -1.40504701603470,
-3.77475828372553e-15, -1.17557050458494, -0.292893218813453,
-0.707106781186546, -0.221231742082475, -0.221231742082476,
0.144973505364595, 0.0600499921067846, 0.618033988749893,
7.77156117237610e-16, 0.965451459415176, -0.399903088302660,
1.00000000000000, -0.999999999999998, 0.652582529334716,
-1.57547359288761, 2.66453525910038e-15, -1.90211303259031,
-0.763007494114496, -1.84206304048352, -1.39680224666742,
-1.39680224666742, -1.70710678118655, -0.707106781186546,
-1.61803398874989, 4.88498130835069e-15, -1.20002351856331,
0.497066016555607, -0.642039521920202, 0.642039521920206,
-0.178671346220190, 0.431350787252242, 0.00000000000000,
-3.49210031947972e-15, -0.178671346220191, -0.431350787252243,
-0.642039521920198, -0.642039521920206, -1.20002351856331,
-0.497066016555610, -1.61803398874989, -2.55351295663786e-15,
-1.70710678118655, 0.707106781186549, -1.39680224666742,
1.39680224666742, -0.763007494114502, 1.84206304048352,
-3.16413562018170e-15, 1.90211303259031, 0.652582529334717,
1.57547359288761, 1.00000000000000, 0.999999999999996,
0.965451459415176, 0.399903088302658, 0.618033988749897,
9.99200722162641e-16, 0.144973505364599, -0.0600499921067855,
-0.221231742082476, 0.221231742082477, -0.292893218813451,
0.707106781186554, -2.10942374678780e-15, 1.17557050458494,
0.581989529813421, 1.40504701603470, 1.26007351067009,
1.26007351067011, 1.79670533497008, 0.744219717332711,
2.00000000000000, 3.67394039744206e-15, 1.79670533497008,
-0.744219717332705, 1.26007351067010, -1.26007351067010,
0.581989529813427, -1.40504701603470, 2.22044604925031e-15,
-1.17557050458495, -0.292893218813453, -0.707106781186547,
-0.221231742082473, -0.221231742082472, 0.144973505364605,
0.0600499921067872, 0.618033988749893, 1.22124532708767e-15,
0.965451459415178, -0.399903088302665, 0.999999999999999,
-1.00000000000000, 0.652582529334710, -1.57547359288762,
-1.31006316905768e-14, -1.90211303259031, -0.763007494114495,
-1.84206304048352, -1.39680224666742, -1.39680224666742,
-1.70710678118655, -0.707106781186539, -1.61803398874989,
1.09912079437891e-14, -1.20002351856332, 0.497066016555607,
-0.642039521920203, 0.642039521920206, -0.178671346220186,
0.431350787252238, 0.00000000000000, -8.08638275819206e-15,
-0.178671346220183, -0.431350787252234, -0.642039521920197,
-0.642039521920205, -1.20002351856331, -0.497066016555611,
-1.61803398874989, -3.55271367880050e-15, -1.70710678118655,
0.707106781186548, -1.39680224666743, 1.39680224666741,
-0.763007494114503, 1.84206304048352, -4.32986979603811e-15,
1.90211303259031, 0.652582529334717, 1.57547359288761,
1.00000000000000, 0.999999999999997, 0.965451459415181,
0.399903088302671, 0.618033988749898, 1.44328993201270e-15,
0.144973505364600, -0.0600499921067857, -0.221231742082476,
0.221231742082476, -0.292893218813451, 0.707106781186553,
-2.77555756156289e-15, 1.17557050458494, 0.581989529813420,
1.40504701603470, 1.26007351067010, 1.26007351067010,
1.79670533497009, 0.744219717332697, 2.00000000000000,
4.89858719658941e-15, 1.79670533497009, -0.744219717332704,
1.26007351067010, -1.26007351067010, 0.581989529813413,
-1.40504701603470, -7.54951656745106e-15, -1.17557050458494,
-0.292893218813452, -0.707106781186548, -0.221231742082473,
-0.221231742082472, 0.144973505364604, 0.0600499921067871,
0.618033988749902, -3.88578058618805e-15, 0.965451459415183,
-0.399903088302676, 0.999999999999999, -1.00000000000000,
0.652582529334711, -1.57547359288762, 5.05151476204446e-15,
-1.90211303259031, -0.763007494114493, -1.84206304048352,
-1.39680224666741, -1.39680224666743, -1.70710678118655,
-0.707106781186557, -1.61803398874990, -4.44089209850063e-15,
-1.20002351856332, 0.497066016555606, -0.642039521920216,
0.642039521920207, -0.178671346220195, 0.431350787252247,
0.00000000000000, 3.30654635769785e-15, -0.178671346220190,
-0.431350787252242, -0.642039521920209, -0.642039521920206,
-1.20002351856331, -0.497066016555611, -1.61803398874989,
-4.55191440096314e-15, -1.70710678118655, 0.707106781186546,
-1.39680224666742, 1.39680224666742, -0.763007494114487,
1.84206304048352, -5.44009282066327e-15, 1.90211303259031,
0.652582529334716, 1.57547359288761, 1.00000000000000,
0.999999999999998, 0.965451459415176, 0.399903088302660,
0.618033988749888, -3.66373598126302e-15, 0.144973505364600,
-0.0600499921067860, -0.221231742082475, 0.221231742082476,
-0.292893218813451, 0.707106781186552, 6.88338275267597e-15,
1.17557050458495, 0.581989529813434, 1.40504701603470,
1.26007351067010, 1.26007351067010, 1.79670533497009,
0.744219717332698, 2.00000000000000, -1.16403343982657e-14,
1.79670533497008, -0.744219717332718, 1.26007351067010,
-1.26007351067010, 0.581989529813414, -1.40504701603470,
1.40998324127395e-14, -1.17557050458496, -0.292893218813450,
-0.707106781186561, -0.221231742082479, -0.221231742082482,
0.144973505364593, 0.0600499921067840, 0.618033988749891,
1.99840144432528e-15, 0.965451459415178, -0.399903088302663,
1.00000000000000, -1.00000000000000, 0.652582529334712,
-1.57547359288762, -1.07136521876328e-14, -1.90211303259031,
-0.763007494114476, -1.84206304048353, -1.39680224666741,
-1.39680224666743, -1.70710678118655, -0.707106781186558,
-1.61803398874990, -5.44009282066327e-15, -1.20002351856332,
0.497066016555606, -0.642039521920205, 0.642039521920206,
-0.178671346220187, 0.431350787252239, 0.00000000000000,
-6.61680659921524e-15, -0.178671346220197, -0.431350787252249,
-0.642039521920220, -0.642039521920207, -1.20002351856331,
-0.497066016555612, -1.61803398874989, -5.55111512312578e-15,
-1.70710678118655, 0.707106781186545, -1.39680224666742,
1.39680224666742, -0.763007494114488, 1.84206304048352,
1.02140518265514e-14, 1.90211303259031, 0.652582529334727,
1.57547359288760, 1.00000000000000, 0.999999999999984,
0.965451459415172, 0.399903088302648, 0.618033988749899,
2.10942374678780e-15, 0.144973505364601, -0.0600499921067861,
-0.221231742082475, 0.221231742082475, -0.292893218813452,
0.707106781186552, -1.47659662275146e-14, 1.17557050458493,
0.581989529813403, 1.40504701603470, 1.26007351067009,
1.26007351067011, 1.79670533497008, 0.744219717332714,
2.00000000000000, 7.34788079488412e-15, 1.79670533497009,
-0.744219717332702, 1.26007351067010, -1.26007351067010,
0.581989529813416, -1.40504701603470, -5.99520433297585e-15,
-1.17557050458494, -0.292893218813455, -0.707106781186538,
-0.221231742082479, -0.221231742082483, 0.144973505364592,
0.0600499921067839, 0.618033988749891, 2.33146835171283e-15,
0.965451459415177, -0.399903088302663, 1.00000000000000,
-1.00000000000000, 0.652582529334713, -1.57547359288761,
-9.54791801177635e-15, -1.90211303259031, -0.763007494114508,
-1.84206304048352, -1.39680224666743, -1.39680224666741,
-1.70710678118655, -0.707106781186559};
//q31_t
q31_t cfft_testinput_q31_50hz_200Hz[512] = {0},
cfft_testinput_q31_50hz_200Hz_ref[512] = {0};
//q15_t
q15_t cfft_testinput_q15_50hz_200Hz[512] = {
32767, 0, 32767, -24386, 32767, -32768, 19070, -32768, 0,
-32768, -9597, -23170, -7249, -7249, 4750, 1967, 20251, 0,
31635, -13104, 32767, -32768, 21383, -32768, 0, -32768, -25002,
-32768, -32768, -32768, -32768, -23170, -32768, 0, -32768, 16287,
-21038, 21038, -5854, 14134, 0, 0, -5854, -14134, -21038,
-21038, -32768, -16287, -32768, 0, -32768, 23170, -32768, 32767,
-25002, 32767, 0, 32767, 21383, 32767, 32767, 32767, 31635,
13104, 20251, 0, 4750, -1967, -7249, 7249, -9597, 23170,
0, 32767, 19070, 32767, 32767, 32767, 32767, 24386, 32767,
0, 32767, -24386, 32767, -32768, 19070, -32768, 0, -32768,
-9597, -23170, -7249, -7249, 4750, 1967, 20251, 0, 31635,
-13104, 32767, -32768, 21383, -32768, 0, -32768, -25002, -32768,
-32768, -32768, -32768, -23170, -32768, 0, -32768, 16287, -21038,
21038, -5854, 14134, 0, 0, -5854, -14134, -21038, -21038,
-32768, -16287, -32768, 0, -32768, 23170, -32768, 32767, -25002,
32767, 0, 32767, 21383, 32767, 32767, 32767, 31635, 13104,
20251, 0, 4750, -1967, -7249, 7249, -9597, 23170, 0,
32767, 19070, 32767, 32767, 32767, 32767, 24386, 32767, 0,
32767, -24386, 32767, -32768, 19070, -32768, 0, -32768, -9597,
-23170, -7249, -7249, 4750, 1967, 20251, 0, 31635, -13104,
32767, -32768, 21383, -32768, 0, -32768, -25002, -32768, -32768,
-32768, -32768, -23170, -32768, 0, -32768, 16287, -21038, 21038,
-5854, 14134, 0, 0, -5854, -14134, -21038, -21038, -32768,
-16287, -32768, 0, -32768, 23170, -32768, 32767, -25002, 32767,
0, 32767, 21383, 32767, 32767, 32767, 31635, 13104, 20251,
0, 4750, -1967, -7249, 7249, -9597, 23170, 0, 32767,
19070, 32767, 32767, 32767, 32767, 24386, 32767, 0, 32767,
-24386, 32767, -32768, 19070, -32768, 0, -32768, -9597, -23170,
-7249, -7249, 4750, 1967, 20251, 0, 31635, -13104, 32767,
-32768, 21383, -32768, 0, -32768, -25002, -32768, -32768, -32768,
-32768, -23170, -32768, 0, -32768, 16287, -21038, 21038, -5854,
14134, 0, 0, -5854, -14134, -21038, -21038, -32768, -16287,
-32768, 0, -32768, 23170, -32768, 32767, -25002, 32767, 0,
32767, 21383, 32767, 32767, 32767, 31635, 13104, 20251, 0,
4750, -1967, -7249, 7249, -9597, 23170, 0, 32767, 19070,
32767, 32767, 32767, 32767, 24386, 32767, 0, 32767, -24386,
32767, -32768, 19070, -32768, 0, -32768, -9597, -23170, -7249,
-7249, 4750, 1967, 20251, 0, 31635, -13104, 32767, -32768,
21383, -32768, 0, -32768, -25002, -32768, -32768, -32768, -32768,
-23170, -32768, 0, -32768, 16287, -21038, 21038, -5854, 14134,
0, 0, -5854, -14134, -21038, -21038, -32768, -16287, -32768,
0, -32768, 23170, -32768, 32767, -25002, 32767, 0, 32767,
21383, 32767, 32767, 32767, 31635, 13104, 20251, 0, 4750,
-1967, -7249, 7249, -9597, 23170, 0, 32767, 19070, 32767,
32767, 32767, 32767, 24386, 32767, 0, 32767, -24386, 32767,
-32768, 19070, -32768, 0, -32768, -9597, -23170, -7249, -7249,
4750, 1967, 20251, 0, 31635, -13104, 32767, -32768, 21383,
-32768, 0, -32768, -25002, -32768, -32768, -32768, -32768, -23170,
-32768, 0, -32768, 16287, -21038, 21038, -5854, 14134, 0,
0, -5854, -14134, -21038, -21038, -32768, -16287, -32768, 0,
-32768, 23170, -32768, 32767, -25002, 32767, 0, 32767, 21383,
32767, 32767, 32767, 31635, 13104, 20251, 0, 4750, -1967,
-7249, 7249, -9597, 23170, 0, 32767, 19070, 32767, 32767,
32767, 32767, 24386, 32767, 0, 32767, -24386, 32767, -32768,
19070, -32768, 0, -32768, -9597, -23170, -7249, -7249, 4750,
1967, 20251, 0, 31635, -13104, 32767, -32768, 21383, -32768,
0, -32768, -25002, -32768, -32768, -32768, -32768, -23170};
q15_t cfft_testinput_q15_50hz_200Hz_ref[512] = {
32767, 0, 32767, -24386, 32767, -32768, 19070, -32768, 0,
-32768, -9597, -23170, -7249, -7249, 4750, 1967, 20251, 0,
31635, -13104, 32767, -32768, 21383, -32768, 0, -32768, -25002,
-32768, -32768, -32768, -32768, -23170, -32768, 0, -32768, 16287,
-21038, 21038, -5854, 14134, 0, 0, -5854, -14134, -21038,
-21038, -32768, -16287, -32768, 0, -32768, 23170, -32768, 32767,
-25002, 32767, 0, 32767, 21383, 32767, 32767, 32767, 31635,
13104, 20251, 0, 4750, -1967, -7249, 7249, -9597, 23170,
0, 32767, 19070, 32767, 32767, 32767, 32767, 24386, 32767,
0, 32767, -24386, 32767, -32768, 19070, -32768, 0, -32768,
-9597, -23170, -7249, -7249, 4750, 1967, 20251, 0, 31635,
-13104, 32767, -32768, 21383, -32768, 0, -32768, -25002, -32768,
-32768, -32768, -32768, -23170, -32768, 0, -32768, 16287, -21038,
21038, -5854, 14134, 0, 0, -5854, -14134, -21038, -21038,
-32768, -16287, -32768, 0, -32768, 23170, -32768, 32767, -25002,
32767, 0, 32767, 21383, 32767, 32767, 32767, 31635, 13104,
20251, 0, 4750, -1967, -7249, 7249, -9597, 23170, 0,
32767, 19070, 32767, 32767, 32767, 32767, 24386, 32767, 0,
32767, -24386, 32767, -32768, 19070, -32768, 0, -32768, -9597,
-23170, -7249, -7249, 4750, 1967, 20251, 0, 31635, -13104,
32767, -32768, 21383, -32768, 0, -32768, -25002, -32768, -32768,
-32768, -32768, -23170, -32768, 0, -32768, 16287, -21038, 21038,
-5854, 14134, 0, 0, -5854, -14134, -21038, -21038, -32768,
-16287, -32768, 0, -32768, 23170, -32768, 32767, -25002, 32767,
0, 32767, 21383, 32767, 32767, 32767, 31635, 13104, 20251,
0, 4750, -1967, -7249, 7249, -9597, 23170, 0, 32767,
19070, 32767, 32767, 32767, 32767, 24386, 32767, 0, 32767,
-24386, 32767, -32768, 19070, -32768, 0, -32768, -9597, -23170,
-7249, -7249, 4750, 1967, 20251, 0, 31635, -13104, 32767,
-32768, 21383, -32768, 0, -32768, -25002, -32768, -32768, -32768,
-32768, -23170, -32768, 0, -32768, 16287, -21038, 21038, -5854,
14134, 0, 0, -5854, -14134, -21038, -21038, -32768, -16287,
-32768, 0, -32768, 23170, -32768, 32767, -25002, 32767, 0,
32767, 21383, 32767, 32767, 32767, 31635, 13104, 20251, 0,
4750, -1967, -7249, 7249, -9597, 23170, 0, 32767, 19070,
32767, 32767, 32767, 32767, 24386, 32767, 0, 32767, -24386,
32767, -32768, 19070, -32768, 0, -32768, -9597, -23170, -7249,
-7249, 4750, 1967, 20251, 0, 31635, -13104, 32767, -32768,
21383, -32768, 0, -32768, -25002, -32768, -32768, -32768, -32768,
-23170, -32768, 0, -32768, 16287, -21038, 21038, -5854, 14134,
0, 0, -5854, -14134, -21038, -21038, -32768, -16287, -32768,
0, -32768, 23170, -32768, 32767, -25002, 32767, 0, 32767,
21383, 32767, 32767, 32767, 31635, 13104, 20251, 0, 4750,
-1967, -7249, 7249, -9597, 23170, 0, 32767, 19070, 32767,
32767, 32767, 32767, 24386, 32767, 0, 32767, -24386, 32767,
-32768, 19070, -32768, 0, -32768, -9597, -23170, -7249, -7249,
4750, 1967, 20251, 0, 31635, -13104, 32767, -32768, 21383,
-32768, 0, -32768, -25002, -32768, -32768, -32768, -32768, -23170,
-32768, 0, -32768, 16287, -21038, 21038, -5854, 14134, 0,
0, -5854, -14134, -21038, -21038, -32768, -16287, -32768, 0,
-32768, 23170, -32768, 32767, -25002, 32767, 0, 32767, 21383,
32767, 32767, 32767, 31635, 13104, 20251, 0, 4750, -1967,
-7249, 7249, -9597, 23170, 0, 32767, 19070, 32767, 32767,
32767, 32767, 24386, 32767, 0, 32767, -24386, 32767, -32768,
19070, -32768, 0, -32768, -9597, -23170, -7249, -7249, 4750,
1967, 20251, 0, 31635, -13104, 32767, -32768, 21383, -32768,
0, -32768, -25002, -32768, -32768, -32768, -32768, -23170};

View file

@ -0,0 +1,618 @@
#include "riscv_const_structs.h"
#include "ref.h"
void ref_cfft_f32(const riscv_cfft_instance_f32 *S, float32_t *p1,
uint8_t ifftFlag, uint8_t bitReverseFlag)
{
int n, mmax, m, j, istep, i;
float32_t wtemp, wr, wpr, wpi, wi, theta;
float32_t tempr, tempi;
float32_t *data = p1;
uint32_t N = S->fftLen;
int32_t dir = (ifftFlag) ? -1 : 1;
// decrement pointer since the original version used fortran style indexing.
data--;
n = N << 1;
j = 1;
for (i = 1; i < n; i += 2) {
if (j > i) {
tempr = data[j];
data[j] = data[i];
data[i] = tempr;
tempr = data[j + 1];
data[j + 1] = data[i + 1];
data[i + 1] = tempr;
}
m = n >> 1;
while (m >= 2 && j > m) {
j -= m;
m >>= 1;
}
j += m;
}
mmax = 2;
while (n > mmax) {
istep = 2 * mmax;
theta = -6.283185307179586f / (dir * mmax);
wtemp = sinf(0.5f * theta);
wpr = -2.0f * wtemp * wtemp;
wpi = sinf(theta);
wr = 1.0f;
wi = 0.0f;
for (m = 1; m < mmax; m += 2) {
for (i = m; i <= n; i += istep) {
j = i + mmax;
tempr = wr * data[j] - wi * data[j + 1];
tempi = wr * data[j + 1] + wi * data[j];
data[j] = data[i] - tempr;
data[j + 1] = data[i + 1] - tempi;
data[i] += tempr;
data[i + 1] += tempi;
}
wr = (wtemp = wr) * wpr - wi * wpi + wr;
wi = wi * wpr + wtemp * wpi + wi;
}
mmax = istep;
}
// Inverse transform is scaled by 1/N
if (ifftFlag) {
data++;
for (i = 0; i < 2 * N; i++) {
data[i] /= N;
}
}
}
void ref_cfft_q31(const riscv_cfft_instance_q31 *S, q31_t *p1, uint8_t ifftFlag,
uint8_t bitReverseFlag)
{
uint32_t i;
// float32_t *fSrc = (float32_t*)p1;
float32_t fSrc[S->fftLen * 2];
riscv_q31_to_float(p1, fSrc, S->fftLen * 2);
for (i = 0; i < S->fftLen * 2; i++) {
// read the q31 data, cast to float, scale down for float
fSrc[i] = (float32_t)p1[i] / 2147483648.0f;
}
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, fSrc, ifftFlag,
bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, fSrc, ifftFlag,
bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, fSrc, ifftFlag,
bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, fSrc, ifftFlag,
bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, fSrc, ifftFlag,
bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, fSrc, ifftFlag,
bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, fSrc, ifftFlag,
bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, fSrc, ifftFlag,
bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, fSrc, ifftFlag,
bitReverseFlag);
break;
}
if (ifftFlag) {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q31, cast to q31
p1[i] = (q31_t)(fSrc[i] * 2147483648.0f);
}
} else {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q31, cast to q31
p1[i] = (q31_t)(fSrc[i] * 2147483648.0f / (float32_t)S->fftLen);
}
}
}
void ref_cfft_q15(const riscv_cfft_instance_q15 *S, q15_t *pSrc, uint8_t ifftFlag,
uint8_t bitReverseFlag)
{
uint32_t i;
// float32_t *fSrc = (float32_t*)pSrc;
float32_t fSrc[S->fftLen * 2];
riscv_q15_to_float(pSrc, fSrc, S->fftLen * 2);
for (i = 0; i < S->fftLen * 2; i++) {
// read the q15 data, cast to float, scale down for float, place in
// temporary buffer
scratchArray[i] = (float32_t)pSrc[i] / 32768.0f;
}
for (i = 0; i < S->fftLen * 2; i++) {
// copy from temp buffer to final buffer
fSrc[i] = scratchArray[i];
}
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, fSrc, ifftFlag,
bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, fSrc, ifftFlag,
bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, fSrc, ifftFlag,
bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, fSrc, ifftFlag,
bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, fSrc, ifftFlag,
bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, fSrc, ifftFlag,
bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, fSrc, ifftFlag,
bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, fSrc, ifftFlag,
bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, fSrc, ifftFlag,
bitReverseFlag);
break;
}
if (ifftFlag) {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q15, cast to q15
pSrc[i] = (q15_t)(fSrc[i] * 32768.0f);
}
} else {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q15, cast to q15
pSrc[i] = (q15_t)(fSrc[i] * 32768.0f / (float32_t)S->fftLen);
}
}
}
void ref_cfft_radix2_f32(const riscv_cfft_radix2_instance_f32 *S, float32_t *pSrc)
{
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
}
}
void ref_cfft_radix2_q31(const riscv_cfft_radix2_instance_q31 *S, q31_t *pSrc)
{
uint32_t i;
// float32_t *fSrc = (float32_t*)pSrc;
float32_t fSrc[S->fftLen * 2];
riscv_q31_to_float(pSrc, fSrc, S->fftLen * 2);
for (i = 0; i < S->fftLen * 2; i++) {
// read the q31 data, cast to float, scale down for float
fSrc[i] = (float32_t)pSrc[i] / 2147483648.0f;
}
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
}
if (S->ifftFlag) {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q31, cast to q31
pSrc[i] = (q31_t)(fSrc[i] * 2147483648.0f);
}
} else {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q31, cast to q31
pSrc[i] = (q31_t)(fSrc[i] * 2147483648.0f / (float32_t)S->fftLen);
}
}
}
void ref_cfft_radix2_q15(const riscv_cfft_radix2_instance_q15 *S, q15_t *pSrc)
{
uint32_t i;
// float32_t *fSrc = (float32_t*)pSrc;
float32_t fSrc[S->fftLen * 2];
riscv_q15_to_float(pSrc, fSrc, S->fftLen * 2);
for (i = 0; i < S->fftLen * 2; i++) {
// read the q15 data, cast to float, scale down for float, place in
// temporary buffer
scratchArray[i] = (float32_t)pSrc[i] / 32768.0f;
}
for (i = 0; i < S->fftLen * 2; i++) {
// copy from temp buffer to final buffer
fSrc[i] = scratchArray[i];
}
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
}
if (S->ifftFlag) {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q15, cast to q15
pSrc[i] = (q15_t)(fSrc[i] * 32768.0f);
}
} else {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q15, cast to q15
pSrc[i] = (q15_t)(fSrc[i] * 32768.0f / (float32_t)S->fftLen);
}
}
}
void ref_cfft_radix4_f32(const riscv_cfft_radix4_instance_f32 *S, float32_t *pSrc)
{
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, pSrc, S->ifftFlag,
S->bitReverseFlag);
break;
}
}
void ref_cfft_radix4_q31(const riscv_cfft_radix4_instance_q31 *S, q31_t *pSrc)
{
uint32_t i;
// float32_t *fSrc = (float32_t*)pSrc;
float32_t fSrc[S->fftLen * 2];
riscv_q31_to_float(pSrc, fSrc, S->fftLen * 2);
for (i = 0; i < S->fftLen * 2; i++) {
// read the q31 data, cast to float, scale down for float
fSrc[i] = (float32_t)pSrc[i] / 2147483648.0f;
}
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
}
if (S->ifftFlag) {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q31, cast to q31
pSrc[i] = (q31_t)(fSrc[i] * 2147483648.0f);
}
} else {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q31, cast to q31
pSrc[i] = (q31_t)(fSrc[i] * 2147483648.0f / (float32_t)S->fftLen);
}
}
}
void ref_cfft_radix4_q15(const riscv_cfft_radix4_instance_q15 *S, q15_t *pSrc)
{
uint32_t i;
// float32_t *fSrc = (float32_t*)pSrc;
float32_t fSrc[S->fftLen * 2];
riscv_q15_to_float(pSrc, fSrc, S->fftLen * 2);
for (i = 0; i < S->fftLen * 2; i++) {
// read the q15 data, cast to float, scale down for float, place in
// temporary buffer
scratchArray[i] = (float32_t)pSrc[i] / 32768.0f;
}
for (i = 0; i < S->fftLen * 2; i++) {
// copy from temp buffer to final buffer
fSrc[i] = scratchArray[i];
}
switch (S->fftLen) {
case 16:
ref_cfft_f32(&riscv_cfft_sR_f32_len16, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 32:
ref_cfft_f32(&riscv_cfft_sR_f32_len32, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 64:
ref_cfft_f32(&riscv_cfft_sR_f32_len64, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 128:
ref_cfft_f32(&riscv_cfft_sR_f32_len128, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 256:
ref_cfft_f32(&riscv_cfft_sR_f32_len256, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 512:
ref_cfft_f32(&riscv_cfft_sR_f32_len512, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 1024:
ref_cfft_f32(&riscv_cfft_sR_f32_len1024, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 2048:
ref_cfft_f32(&riscv_cfft_sR_f32_len2048, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
case 4096:
ref_cfft_f32(&riscv_cfft_sR_f32_len4096, fSrc, S->ifftFlag,
S->bitReverseFlag);
break;
}
if (S->ifftFlag) {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q15, cast to q15
pSrc[i] = (q15_t)(fSrc[i] * 32768.0f);
}
} else {
for (i = 0; i < S->fftLen * 2; i++) {
// read the float data, scale up for q15, cast to q15
pSrc[i] = (q15_t)(fSrc[i] * 32768.0f / (float32_t)S->fftLen);
}
}
}

View file

@ -0,0 +1,125 @@
//
// Created by lujun on 19-6-28.
//
// This contains SIN_COS , clarke, inv_clarke, park, inv_park and pid
// each one has it's own function.
// All function can be found in main function.
// If you don't want to use it, then comment it.
#include "riscv_common_tables.h"
#include "riscv_const_structs.h"
#include "riscv_math.h"
#include "array.h"
#include <stdint.h>
#include "../common.h"
#include "../HelperFunctions/math_helper.c"
#include "../HelperFunctions/ref_helper.c"
#include <stdio.h>
#define DELTAF32 (0.05f)
#define DELTAQ31 (63)
#define DELTAQ15 (1)
#define DELTAQ7 (1)
int test_flag_error = 0;
uint32_t fftSize = 1024;
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;
static int DSP_cfft_radix4_f32(void)
{
uint16_t i;
fftSize = 256;
riscv_cfft_radix4_instance_f32 S;
uint8_t ifftFlag = 0, doBitReverse = 1;
riscv_cfft_radix4_init_f32(&S, 256, ifftFlag, doBitReverse);
BENCH_START(riscv_cfft_radix4_f32);
riscv_cfft_radix4_f32(&S, cfft_testinput_f32_50hz_200Hz);
BENCH_END(riscv_cfft_radix4_f32);
ref_cfft_radix4_f32(&S, cfft_testinput_f32_50hz_200Hz_ref);
float32_t resault, resault_ref;
uint32_t index, index_ref;
riscv_max_f32(cfft_testinput_f32_50hz_200Hz, 256, &resault, &index);
riscv_max_f32(cfft_testinput_f32_50hz_200Hz_ref, 256, &resault_ref,
&index_ref);
if (index != index_ref) {
BENCH_ERROR(riscv_cfft_radix4_f32);
printf("expect: %d, actual: %d\n", index_ref, index);
test_flag_error = 1;
}
BENCH_STATUS(riscv_cfft_radix4_f32);
}
static int DSP_cfft_radix4_q15(void)
{
uint16_t i;
fftSize = 256;
riscv_cfft_radix4_instance_q15 S;
uint8_t ifftFlag = 0, doBitReverse = 1;
riscv_cfft_radix4_init_q15(&S, 256, ifftFlag, doBitReverse);
BENCH_START(riscv_cfft_radix4_q15);
riscv_cfft_radix4_q15(&S, cfft_testinput_q15_50hz_200Hz);
BENCH_END(riscv_cfft_radix4_q15);
ref_cfft_radix4_q15(&S, cfft_testinput_q15_50hz_200Hz_ref);
q15_t resault, resault_ref;
uint32_t index, index_ref = 117;
riscv_shift_q15(cfft_testinput_q15_50hz_200Hz, 8,
cfft_testinput_q15_50hz_200Hz, fftSize);
riscv_max_q15(cfft_testinput_q15_50hz_200Hz, 256, &resault, &index);
riscv_shift_q15(cfft_testinput_q15_50hz_200Hz_ref, 8,
cfft_testinput_q15_50hz_200Hz_ref, fftSize);
riscv_max_q15(cfft_testinput_q15_50hz_200Hz_ref, 256, &resault_ref,
&index_ref);
if (index != index_ref) {
BENCH_ERROR(riscv_cfft_radix4_q15);
printf("expect: %d, actual: %d\n", index_ref, index);
test_flag_error = 1;
}
BENCH_STATUS(riscv_cfft_radix4_q15);
}
static int DSP_cfft_radix4_q31(void)
{
uint16_t i;
riscv_float_to_q31(cfft_testinput_f32_50hz_200Hz,
cfft_testinput_q31_50hz_200Hz, 512);
riscv_float_to_q31(cfft_testinput_f32_50hz_200Hz_ref,
cfft_testinput_q31_50hz_200Hz_ref, 512);
fftSize = 256;
riscv_cfft_radix4_instance_q31 S;
uint8_t ifftFlag = 0, doBitReverse = 1;
riscv_cfft_radix4_init_q31(&S, 256, ifftFlag, doBitReverse);
BENCH_START(riscv_cfft_radix4_q31);
riscv_cfft_radix4_q31(&S, cfft_testinput_q31_50hz_200Hz);
BENCH_END(riscv_cfft_radix4_q31);
ref_cfft_radix4_q31(&S, cfft_testinput_q31_50hz_200Hz_ref);
q31_t resault, resault_ref;
uint32_t index, index_ref;
riscv_max_q31(cfft_testinput_q31_50hz_200Hz, 256, &resault, &index);
riscv_max_q31(cfft_testinput_q31_50hz_200Hz_ref, 256, &resault_ref,
&index_ref);
if (index != index_ref) {
BENCH_ERROR(riscv_cfft_radix4_q31);
printf("expect: %d, actual: %d\n", index_ref, index);
test_flag_error = 1;
}
BENCH_STATUS(riscv_cfft_radix4_q31);
}
int main()
{
BENCH_INIT;
DSP_cfft_radix4_f32();
DSP_cfft_radix4_q15();
DSP_cfft_radix4_q31();
BENCH_FINISH;
if (test_flag_error) {
printf("test error apprears, please recheck.\n");
return 1;
} else {
printf("all test are passed. Well done!\n");
}
return 0;
}