Change channel_spectrum type to std::complex<float>.

Move FFT bit-reversal to complex<int16_t> -> complex<float> copy.
Change window so that adjacent bins have constant(-ish) gain.
Change window to float.
Change time domain samples to accumulate at even intervals over the FFT interval.
This commit is contained in:
Jared Boone 2015-09-17 17:37:05 -07:00
parent 882fbbef31
commit 291de8f869
4 changed files with 294 additions and 162 deletions

View File

@ -38,14 +38,12 @@ void BasebandProcessor::update_spectrum() {
// Called from idle thread (after EVT_MASK_SPECTRUM is flagged)
if( channel_spectrum_request_update ) {
/* Decimated buffer is full. Compute spectrum. */
std::array<std::complex<float>, 256> samples_swapped;
fft_swap(channel_spectrum, samples_swapped);
channel_spectrum_request_update = false;
fft_c_preswapped(samples_swapped);
fft_c_preswapped(channel_spectrum);
ChannelSpectrumMessage spectrum_message;
for(size_t i=0; i<spectrum_message.spectrum.db.size(); i++) {
const auto mag2 = magnitude_squared(samples_swapped[i]);
const auto mag2 = magnitude_squared(channel_spectrum[i]);
const float db = complex16_mag_squared_to_dbv_norm(mag2);
constexpr float mag_scale = 5.0f;
const unsigned int v = (db * mag_scale) + 255.0f;
@ -102,9 +100,9 @@ void BasebandProcessor::post_channel_stats_message(const ChannelStatistics stati
void BasebandProcessor::post_channel_spectrum_message(const buffer_c16_t data) {
if( !channel_spectrum_request_update ) {
channel_spectrum_request_update = true;
std::copy(&data.p[0], &data.p[data.count], channel_spectrum.begin());
fft_swap(data, channel_spectrum);
channel_spectrum_sampling_rate = data.sampling_rate;
channel_spectrum_request_update = true;
events_flag(EVT_MASK_SPECTRUM);
}
}

View File

@ -31,6 +31,7 @@
#include <array>
#include <cstdint>
#include <complex>
class BasebandProcessor {
public:
@ -52,7 +53,7 @@ protected:
void fill_audio_buffer(const buffer_s16_t audio);
volatile bool channel_spectrum_request_update { false };
std::array<complex16_t, 256> channel_spectrum;
std::array<std::complex<float>, 256> channel_spectrum;
uint32_t channel_spectrum_sampling_rate { 0 };
uint32_t channel_filter_pass_frequency { 0 };
uint32_t channel_filter_stop_frequency { 0 };

View File

@ -26,6 +26,8 @@
#include "i2s.hpp"
using namespace lpc43xx;
#include "dsp_fft.hpp"
#include <cstdint>
#include <cstddef>
@ -35,173 +37,300 @@ using namespace lpc43xx;
Employ window-presum technique with a window constructed to act like a bin filter.
See: http://www.embedded.com/design/real-time-and-performance/4007611/DSP-Tricks-Building-a-practical-spectrum-analyzer
import scipy.signal
20MHz / 256 bins = 78.125kHz/bin
d = scipy.signal.remez(1024, (0.0, 32000, 48000, 10000000), (1, 0), Hz=20000000)
for n in range(0, len(d), 8): print(' '.join(['%5d,' % int(round(v * 32768 * 128)) for v in d[n:n+8]]))
Taps made with IPython Notebook "specan_lpf", 26041.666667Hz pass, 53400Hz stop, 1024 taps, Remez, gain of 4 * 128.
*/
static constexpr std::array<int16_t, 1024> window_wideband_bin_lpf { {
0, -3409, -3284, -3358, -3235, -3312, -3187, -3270,
-3143, -3233, -3100, -3202, -3057, -3186, -3009, -3261,
-2777, -2904, -3087, -3076, -3058, -3069, -3013, -3037,
-2969, -3004, -2931, -2976, -2898, -2956, -2870, -2957,
-2871, -2830, -2866, -2914, -2874, -2919, -2864, -2911,
-2854, -2905, -2849, -2905, -2851, -2910, -2858, -2917,
-2893, -2901, -2866, -2949, -2901, -2970, -2914, -2979,
-2923, -2987, -2932, -2997, -2945, -3009, -2960, -3020,
-2986, -3043, -2971, -3059, -3005, -3082, -3023, -3094,
-3035, -3105, -3048, -3119, -3064, -3135, -3083, -3153,
-3102, -3186, -3111, -3193, -3141, -3221, -3166, -3242,
-3186, -3260, -3204, -3280, -3225, -3302, -3249, -3327,
-3269, -3358, -3296, -3367, -3318, -3395, -3344, -3418,
-3364, -3436, -3381, -3455, -3400, -3474, -3420, -3495,
-3437, -3515, -3464, -3527, -3475, -3546, -3494, -3564,
-3510, -3578, -3523, -3591, -3535, -3604, -3549, -3618,
-3563, -3628, -3581, -3641, -3585, -3650, -3596, -3661,
-3605, -3668, -3610, -3672, -3615, -3676, -3619, -3680,
-3624, -3680, -3626, -3686, -3622, -3680, -3619, -3677,
-3616, -3672, -3609, -3663, -3600, -3653, -3590, -3642,
-3580, -3630, -3564, -3619, -3550, -3599, -3531, -3581,
-3513, -3561, -3492, -3538, -3468, -3513, -3443, -3487,
-3417, -3461, -3386, -3432, -3358, -3398, -3323, -3362,
-3288, -3326, -3251, -3287, -3210, -3245, -3168, -3202,
-3123, -3158, -3076, -3108, -3030, -3059, -2976, -3004,
-2922, -2949, -2866, -2892, -2808, -2832, -2746, -2770,
-2683, -2706, -2619, -2637, -2552, -2570, -2481, -2497,
-2407, -2423, -2333, -2347, -2256, -2269, -2177, -2188,
-2095, -2104, -2012, -2018, -1924, -1931, -1835, -1839,
-1742, -1745, -1648, -1650, -1552, -1552, -1452, -1451,
-1351, -1347, -1247, -1243, -1139, -1135, -1031, -1024,
-919, -910, -805, -795, -689, -678, -571, -558,
-451, -436, -327, -313, -202, -186, -75, -57,
55, 75, 187, 208, 320, 342, 456, 480,
594, 619, 735, 760, 877, 905, 1021, 1050,
1168, 1199, 1317, 1349, 1467, 1500, 1619, 1653,
1773, 1808, 1930, 1966, 2086, 2125, 2247, 2285,
2407, 2448, 2570, 2611, 2734, 2776, 2899, 2942,
3066, 3110, 3234, 3280, 3403, 3450, 3575, 3622,
3746, 3795, 3920, 3970, 4095, 4145, 4270, 4321,
4446, 4499, 4624, 4678, 4803, 4856, 4983, 5037,
5163, 5218, 5344, 5400, 5526, 5582, 5708, 5765,
5891, 5948, 6074, 6133, 6259, 6316, 6442, 6502,
6627, 6686, 6811, 6871, 6996, 7057, 7181, 7241,
7365, 7427, 7550, 7612, 7736, 7797, 7920, 7982,
8105, 8167, 8288, 8351, 8473, 8536, 8656, 8719,
8839, 8902, 9022, 9084, 9204, 9267, 9385, 9448,
9566, 9629, 9745, 9808, 9924, 9987, 10102, 10165,
10279, 10341, 10455, 10517, 10629, 10692, 10803, 10864,
10974, 11036, 11145, 11206, 11314, 11375, 11482, 11542,
11648, 11708, 11812, 11872, 11975, 12035, 12137, 12195,
12296, 12354, 12453, 12511, 12609, 12666, 12762, 12819,
12914, 12970, 13063, 13119, 13210, 13265, 13356, 13409,
13498, 13551, 13639, 13690, 13776, 13827, 13911, 13962,
14044, 14094, 14174, 14223, 14302, 14349, 14427, 14474,
14549, 14595, 14669, 14713, 14785, 14828, 14899, 14941,
15010, 15051, 15117, 15158, 15223, 15261, 15324, 15363,
15423, 15460, 15519, 15555, 15611, 15646, 15700, 15734,
15787, 15819, 15870, 15900, 15949, 15978, 16024, 16053,
16098, 16125, 16166, 16193, 16232, 16257, 16294, 16317,
16353, 16375, 16409, 16429, 16460, 16480, 16508, 16526,
16553, 16570, 16594, 16609, 16632, 16645, 16665, 16677,
16696, 16707, 16723, 16732, 16745, 16754, 16765, 16771,
16780, 16786, 16792, 16796, 16801, 16803, 16805, 16805,
16805, 16805, 16803, 16801, 16796, 16792, 16786, 16780,
16771, 16765, 16754, 16745, 16732, 16723, 16707, 16696,
16677, 16665, 16645, 16632, 16609, 16594, 16570, 16553,
16526, 16508, 16480, 16460, 16429, 16409, 16375, 16353,
16317, 16294, 16257, 16232, 16193, 16166, 16125, 16098,
16053, 16024, 15978, 15949, 15900, 15870, 15819, 15787,
15734, 15700, 15646, 15611, 15555, 15519, 15460, 15423,
15363, 15324, 15261, 15223, 15158, 15117, 15051, 15010,
14941, 14899, 14828, 14785, 14713, 14669, 14595, 14549,
14474, 14427, 14349, 14302, 14223, 14174, 14094, 14044,
13962, 13911, 13827, 13776, 13690, 13639, 13551, 13498,
13409, 13356, 13265, 13210, 13119, 13063, 12970, 12914,
12819, 12762, 12666, 12609, 12511, 12453, 12354, 12296,
12195, 12137, 12035, 11975, 11872, 11812, 11708, 11648,
11542, 11482, 11375, 11314, 11206, 11145, 11036, 10974,
10864, 10803, 10692, 10629, 10517, 10455, 10341, 10279,
10165, 10102, 9987, 9924, 9808, 9745, 9629, 9566,
9448, 9385, 9267, 9204, 9084, 9022, 8902, 8839,
8719, 8656, 8536, 8473, 8351, 8288, 8167, 8105,
7982, 7920, 7797, 7736, 7612, 7550, 7427, 7365,
7241, 7181, 7057, 6996, 6871, 6811, 6686, 6627,
6502, 6442, 6316, 6259, 6133, 6074, 5948, 5891,
5765, 5708, 5582, 5526, 5400, 5344, 5218, 5163,
5037, 4983, 4856, 4803, 4678, 4624, 4499, 4446,
4321, 4270, 4145, 4095, 3970, 3920, 3795, 3746,
3622, 3575, 3450, 3403, 3280, 3234, 3110, 3066,
2942, 2899, 2776, 2734, 2611, 2570, 2448, 2407,
2285, 2247, 2125, 2086, 1966, 1930, 1808, 1773,
1653, 1619, 1500, 1467, 1349, 1317, 1199, 1168,
1050, 1021, 905, 877, 760, 735, 619, 594,
480, 456, 342, 320, 208, 187, 75, 55,
-57, -75, -186, -202, -313, -327, -436, -451,
-558, -571, -678, -689, -795, -805, -910, -919,
-1024, -1031, -1135, -1139, -1243, -1247, -1347, -1351,
-1451, -1452, -1552, -1552, -1650, -1648, -1745, -1742,
-1839, -1835, -1931, -1924, -2018, -2012, -2104, -2095,
-2188, -2177, -2269, -2256, -2347, -2333, -2423, -2407,
-2497, -2481, -2570, -2552, -2637, -2619, -2706, -2683,
-2770, -2746, -2832, -2808, -2892, -2866, -2949, -2922,
-3004, -2976, -3059, -3030, -3108, -3076, -3158, -3123,
-3202, -3168, -3245, -3210, -3287, -3251, -3326, -3288,
-3362, -3323, -3398, -3358, -3432, -3386, -3461, -3417,
-3487, -3443, -3513, -3468, -3538, -3492, -3561, -3513,
-3581, -3531, -3599, -3550, -3619, -3564, -3630, -3580,
-3642, -3590, -3653, -3600, -3663, -3609, -3672, -3616,
-3677, -3619, -3680, -3622, -3686, -3626, -3680, -3624,
-3680, -3619, -3676, -3615, -3672, -3610, -3668, -3605,
-3661, -3596, -3650, -3585, -3641, -3581, -3628, -3563,
-3618, -3549, -3604, -3535, -3591, -3523, -3578, -3510,
-3564, -3494, -3546, -3475, -3527, -3464, -3515, -3437,
-3495, -3420, -3474, -3400, -3455, -3381, -3436, -3364,
-3418, -3344, -3395, -3318, -3367, -3296, -3358, -3269,
-3327, -3249, -3302, -3225, -3280, -3204, -3260, -3186,
-3242, -3166, -3221, -3141, -3193, -3111, -3186, -3102,
-3153, -3083, -3135, -3064, -3119, -3048, -3105, -3035,
-3094, -3023, -3082, -3005, -3059, -2971, -3043, -2986,
-3020, -2960, -3009, -2945, -2997, -2932, -2987, -2923,
-2979, -2914, -2970, -2901, -2949, -2866, -2901, -2893,
-2917, -2858, -2910, -2851, -2905, -2849, -2905, -2854,
-2911, -2864, -2919, -2874, -2914, -2866, -2830, -2871,
-2957, -2870, -2956, -2898, -2976, -2931, -3004, -2969,
-3037, -3013, -3069, -3058, -3076, -3087, -2904, -2777,
-3261, -3009, -3186, -3057, -3202, -3100, -3233, -3143,
-3270, -3187, -3312, -3235, -3358, -3284, -3409, 0,
static constexpr std::array<float, 1024> window_wideband_bin_lpf { {
0.0000000000f, -0.1215729938f, -0.1213842597f, -0.1201684429f,
-0.1201208291f, -0.1190024264f, -0.1190858794f, -0.1180910084f,
-0.1182902140f, -0.1173947314f, -0.1177379144f, -0.1169320615f,
-0.1174165122f, -0.1166760717f, -0.1173065305f, -0.1166353753f,
-0.1174295604f, -0.1168115435f, -0.1177737061f, -0.1171681501f,
-0.1183154633f, -0.1176885372f, -0.1190734477f, -0.1183823726f,
-0.1200564042f, -0.1191925052f, -0.1212624937f, -0.1200347844f,
-0.1227782673f, -0.1205369109f, -0.1247875900f, -0.1173893915f,
-0.1356269751f, -0.1333820215f, -0.1230013683f, -0.1270419996f,
-0.1248521391f, -0.1280766855f, -0.1275474455f, -0.1303677621f,
-0.1305094750f, -0.1330985791f, -0.1335694857f, -0.1359864220f,
-0.1366453783f, -0.1389458751f, -0.1397338876f, -0.1419434716f,
-0.1428068116f, -0.1449481895f, -0.1458627832f, -0.1479788256f,
-0.1489403301f, -0.1510623954f, -0.1520476681f, -0.1541795914f,
-0.1551676484f, -0.1573540028f, -0.1583282171f, -0.1606274956f,
-0.1614806858f, -0.1640690747f, -0.1645983125f, -0.1683593655f,
-0.1685811576f, -0.1666149935f, -0.1723006308f, -0.1738005522f,
-0.1764397529f, -0.1778294249f, -0.1798377067f, -0.1812660021f,
-0.1831168886f, -0.1846305866f, -0.1864679413f, -0.1881030278f,
-0.1899836720f, -0.1917311189f, -0.1936526632f, -0.1954904285f,
-0.1974621775f, -0.1993785604f, -0.2013983100f, -0.2033652690f,
-0.2054038199f, -0.2073919547f, -0.2094317510f, -0.2114475228f,
-0.2134958020f, -0.2155244502f, -0.2175598198f, -0.2195723764f,
-0.2216212397f, -0.2236245172f, -0.2256330226f, -0.2276718013f,
-0.2285011851f, -0.2330266272f, -0.2341760732f, -0.2355468158f,
-0.2372897729f, -0.2390892017f, -0.2410984360f, -0.2430630996f,
-0.2451131271f, -0.2470901019f, -0.2491104380f, -0.2510271295f,
-0.2529788379f, -0.2548171418f, -0.2567089643f, -0.2584896769f,
-0.2603277216f, -0.2620527778f, -0.2638390865f, -0.2655133466f,
-0.2672727018f, -0.2689155628f, -0.2706716369f, -0.2722769142f,
-0.2740080396f, -0.2755608442f, -0.2772761254f, -0.2787902978f,
-0.2804988036f, -0.2818896819f, -0.2836812630f, -0.2847616987f,
-0.2872351631f, -0.2879411883f, -0.2887415908f, -0.2908411467f,
-0.2922042842f, -0.2938671020f, -0.2950580040f, -0.2964174081f,
-0.2974931002f, -0.2987161065f, -0.2997260603f, -0.3008800902f,
-0.3018593574f, -0.3029682798f, -0.3039122280f, -0.3049525345f,
-0.3058372184f, -0.3068011429f, -0.3076169401f, -0.3085060392f,
-0.3092353383f, -0.3100296179f, -0.3106447420f, -0.3113288653f,
-0.3118458639f, -0.3124439347f, -0.3128663068f, -0.3133679403f,
-0.3136545108f, -0.3141297440f, -0.3142523940f, -0.3147549076f,
-0.3146688330f, -0.3145152697f, -0.3154945639f, -0.3152392795f,
-0.3152146050f, -0.3149481827f, -0.3148580017f, -0.3146624743f,
-0.3145480407f, -0.3143048413f, -0.3140959719f, -0.3137462882f,
-0.3133944699f, -0.3129048624f, -0.3123958369f, -0.3117751598f,
-0.3111336729f, -0.3103913733f, -0.3096257208f, -0.3087558210f,
-0.3078644089f, -0.3068771119f, -0.3058756301f, -0.3047953307f,
-0.3036791840f, -0.3024750370f, -0.3012206975f, -0.2998832522f,
-0.2985327732f, -0.2970457316f, -0.2955408715f, -0.2939578995f,
-0.2921271926f, -0.2909536921f, -0.2886979015f, -0.2867034021f,
-0.2848865889f, -0.2829509809f, -0.2809996598f, -0.2788599641f,
-0.2766682382f, -0.2743418063f, -0.2719823809f, -0.2695102609f,
-0.2670290887f, -0.2644425265f, -0.2618581518f, -0.2591571117f,
-0.2564433319f, -0.2536057399f, -0.2507463340f, -0.2477656128f,
-0.2447669078f, -0.2416375134f, -0.2384901545f, -0.2351846242f,
-0.2318685842f, -0.2284043787f, -0.2249483716f, -0.2213504338f,
-0.2177326536f, -0.2139529315f, -0.2102567274f, -0.2062425510f,
-0.2025752799f, -0.1982312400f, -0.1941135048f, -0.1902676621f,
-0.1859484086f, -0.1816310071f, -0.1771140890f, -0.1726183100f,
-0.1680332327f, -0.1634326051f, -0.1587317239f, -0.1539912234f,
-0.1491346512f, -0.1442198838f, -0.1391845207f, -0.1340828639f,
-0.1288821834f, -0.1236191798f, -0.1182710743f, -0.1128619755f,
-0.1073604731f, -0.1018001799f, -0.0961440884f, -0.0904454283f,
-0.0846659246f, -0.0788312843f, -0.0729015436f, -0.0668947833f,
-0.0607956180f, -0.0546891309f, -0.0483829023f, -0.0421512920f,
-0.0356596108f, -0.0291537434f, -0.0229218816f, -0.0160240942f,
-0.0093228281f, -0.0025108764f, 0.0042491810f, 0.0111402133f,
0.0180789645f, 0.0251689168f, 0.0322938011f, 0.0395537898f,
0.0468355725f, 0.0542297395f, 0.0616418371f, 0.0691492555f,
0.0766873597f, 0.0843282945f, 0.0920097856f, 0.0998030288f,
0.1076300783f, 0.1155633999f, 0.1235258532f, 0.1315923511f,
0.1397136271f, 0.1479358113f, 0.1562017822f, 0.1645454321f,
0.1729007855f, 0.1814067004f, 0.1898938500f, 0.1984767185f,
0.2071598962f, 0.2156750628f, 0.2246834377f, 0.2334738679f,
0.2422305215f, 0.2511740186f, 0.2601619588f, 0.2692982077f,
0.2784363297f, 0.2876515447f, 0.2968698668f, 0.3061706020f,
0.3154820195f, 0.3248945791f, 0.3343234494f, 0.3438662338f,
0.3534259170f, 0.3630855246f, 0.3727544495f, 0.3825072994f,
0.3922658126f, 0.4021151299f, 0.4119710813f, 0.4219304098f,
0.4318755419f, 0.4419066050f, 0.4519266790f, 0.4620411273f,
0.4721924196f, 0.4824099358f, 0.4925918161f, 0.5029672026f,
0.5131676220f, 0.5237112702f, 0.5340474666f, 0.5443687487f,
0.5549596923f, 0.5655037792f, 0.5760846623f, 0.5866412762f,
0.5972195405f, 0.6078470214f, 0.6185164530f, 0.6292346029f,
0.6399890869f, 0.6507775481f, 0.6615869909f, 0.6724215836f,
0.6832601692f, 0.6941326055f, 0.7050115342f, 0.7159351783f,
0.7268750405f, 0.7378519124f, 0.7488402816f, 0.7598478405f,
0.7708626189f, 0.7819213638f, 0.7929898181f, 0.8041032024f,
0.8151863856f, 0.8262675846f, 0.8374347030f, 0.8485124885f,
0.8596901081f, 0.8708298046f, 0.8818521053f, 0.8932043400f,
0.9043106868f, 0.9154712945f, 0.9265928796f, 0.9377943260f,
0.9489884395f, 0.9602246825f, 0.9714051258f, 0.9826151929f,
0.9937649659f, 1.0049460392f, 1.0160814715f, 1.0272496293f,
1.0383880993f, 1.0495571434f, 1.0606883842f, 1.0718420204f,
1.0829385916f, 1.0940532343f, 1.1051116703f, 1.1161955290f,
1.1272425119f, 1.1382946085f, 1.1492896227f, 1.1602787038f,
1.1712107201f, 1.1822261399f, 1.1931082102f, 1.2040321660f,
1.2149338949f, 1.2257216453f, 1.2366886195f, 1.2474232220f,
1.2581260885f, 1.2689166363f, 1.2796266048f, 1.2903413723f,
1.3009452557f, 1.3115347597f, 1.3220588330f, 1.3325885128f,
1.3430577723f, 1.3535351287f, 1.3639358829f, 1.3743362159f,
1.3846448962f, 1.3949381321f, 1.4051428918f, 1.4153304829f,
1.4254416597f, 1.4355455123f, 1.4455694200f, 1.4555829383f,
1.4654880955f, 1.4753745521f, 1.4851755647f, 1.4949664411f,
1.5047009642f, 1.5143471956f, 1.5238981621f, 1.5335015901f,
1.5428771970f, 1.5523880267f, 1.5616442576f, 1.5708923706f,
1.5801889794f, 1.5893352932f, 1.5983995178f, 1.6073964215f,
1.6163275268f, 1.6252361387f, 1.6340558312f, 1.6428196478f,
1.6514803963f, 1.6600728279f, 1.6685645243f, 1.6769969948f,
1.6853322111f, 1.6936257655f, 1.7018206388f, 1.7099724793f,
1.7180180271f, 1.7260006052f, 1.7338708023f, 1.7416709937f,
1.7493721167f, 1.7570307435f, 1.7645736334f, 1.7720587141f,
1.7793864240f, 1.7866595518f, 1.7939083209f, 1.8009680396f,
1.8080175914f, 1.8149423807f, 1.8217244084f, 1.8285934275f,
1.8351580541f, 1.8417084040f, 1.8481458306f, 1.8545405038f,
1.8608040839f, 1.8669819454f, 1.8730100097f, 1.8789794347f,
1.8848148272f, 1.8906028239f, 1.8962629246f, 1.9018629597f,
1.9073312666f, 1.9127216689f, 1.9179684698f, 1.9231368617f,
1.9281575220f, 1.9331147367f, 1.9379346294f, 1.9426980945f,
1.9473253537f, 1.9518608547f, 1.9562473102f, 1.9605563249f,
1.9647377083f, 1.9689130417f, 1.9728201948f, 1.9767204935f,
1.9804869777f, 1.9840965410f, 1.9877044695f, 1.9910612418f,
1.9943519434f, 1.9976117863f, 2.0006898142f, 2.0036817820f,
2.0065068911f, 2.0092612533f, 2.0118899336f, 2.0144381201f,
2.0168403950f, 2.0191500613f, 2.0212978024f, 2.0233571150f,
2.0252586877f, 2.0270797012f, 2.0287613011f, 2.0303632435f,
2.0318318976f, 2.0332139460f, 2.0344458593f, 2.0355811762f,
2.0365507956f, 2.0374411193f, 2.0382032761f, 2.0388791314f,
2.0394289467f, 2.0397935314f, 2.0400654417f, 2.0403149729f,
2.0402865682f, 2.0403149729f, 2.0400654417f, 2.0397935314f,
2.0394289467f, 2.0388791314f, 2.0382032761f, 2.0374411193f,
2.0365507956f, 2.0355811762f, 2.0344458593f, 2.0332139460f,
2.0318318976f, 2.0303632435f, 2.0287613011f, 2.0270797012f,
2.0252586877f, 2.0233571150f, 2.0212978024f, 2.0191500613f,
2.0168403950f, 2.0144381201f, 2.0118899336f, 2.0092612533f,
2.0065068911f, 2.0036817820f, 2.0006898142f, 1.9976117863f,
1.9943519434f, 1.9910612418f, 1.9877044695f, 1.9840965410f,
1.9804869777f, 1.9767204935f, 1.9728201948f, 1.9689130417f,
1.9647377083f, 1.9605563249f, 1.9562473102f, 1.9518608547f,
1.9473253537f, 1.9426980945f, 1.9379346294f, 1.9331147367f,
1.9281575220f, 1.9231368617f, 1.9179684698f, 1.9127216689f,
1.9073312666f, 1.9018629597f, 1.8962629246f, 1.8906028239f,
1.8848148272f, 1.8789794347f, 1.8730100097f, 1.8669819454f,
1.8608040839f, 1.8545405038f, 1.8481458306f, 1.8417084040f,
1.8351580541f, 1.8285934275f, 1.8217244084f, 1.8149423807f,
1.8080175914f, 1.8009680396f, 1.7939083209f, 1.7866595518f,
1.7793864240f, 1.7720587141f, 1.7645736334f, 1.7570307435f,
1.7493721167f, 1.7416709937f, 1.7338708023f, 1.7260006052f,
1.7180180271f, 1.7099724793f, 1.7018206388f, 1.6936257655f,
1.6853322111f, 1.6769969948f, 1.6685645243f, 1.6600728279f,
1.6514803963f, 1.6428196478f, 1.6340558312f, 1.6252361387f,
1.6163275268f, 1.6073964215f, 1.5983995178f, 1.5893352932f,
1.5801889794f, 1.5708923706f, 1.5616442576f, 1.5523880267f,
1.5428771970f, 1.5335015901f, 1.5238981621f, 1.5143471956f,
1.5047009642f, 1.4949664411f, 1.4851755647f, 1.4753745521f,
1.4654880955f, 1.4555829383f, 1.4455694200f, 1.4355455123f,
1.4254416597f, 1.4153304829f, 1.4051428918f, 1.3949381321f,
1.3846448962f, 1.3743362159f, 1.3639358829f, 1.3535351287f,
1.3430577723f, 1.3325885128f, 1.3220588330f, 1.3115347597f,
1.3009452557f, 1.2903413723f, 1.2796266048f, 1.2689166363f,
1.2581260885f, 1.2474232220f, 1.2366886195f, 1.2257216453f,
1.2149338949f, 1.2040321660f, 1.1931082102f, 1.1822261399f,
1.1712107201f, 1.1602787038f, 1.1492896227f, 1.1382946085f,
1.1272425119f, 1.1161955290f, 1.1051116703f, 1.0940532343f,
1.0829385916f, 1.0718420204f, 1.0606883842f, 1.0495571434f,
1.0383880993f, 1.0272496293f, 1.0160814715f, 1.0049460392f,
0.9937649659f, 0.9826151929f, 0.9714051258f, 0.9602246825f,
0.9489884395f, 0.9377943260f, 0.9265928796f, 0.9154712945f,
0.9043106868f, 0.8932043400f, 0.8818521053f, 0.8708298046f,
0.8596901081f, 0.8485124885f, 0.8374347030f, 0.8262675846f,
0.8151863856f, 0.8041032024f, 0.7929898181f, 0.7819213638f,
0.7708626189f, 0.7598478405f, 0.7488402816f, 0.7378519124f,
0.7268750405f, 0.7159351783f, 0.7050115342f, 0.6941326055f,
0.6832601692f, 0.6724215836f, 0.6615869909f, 0.6507775481f,
0.6399890869f, 0.6292346029f, 0.6185164530f, 0.6078470214f,
0.5972195405f, 0.5866412762f, 0.5760846623f, 0.5655037792f,
0.5549596923f, 0.5443687487f, 0.5340474666f, 0.5237112702f,
0.5131676220f, 0.5029672026f, 0.4925918161f, 0.4824099358f,
0.4721924196f, 0.4620411273f, 0.4519266790f, 0.4419066050f,
0.4318755419f, 0.4219304098f, 0.4119710813f, 0.4021151299f,
0.3922658126f, 0.3825072994f, 0.3727544495f, 0.3630855246f,
0.3534259170f, 0.3438662338f, 0.3343234494f, 0.3248945791f,
0.3154820195f, 0.3061706020f, 0.2968698668f, 0.2876515447f,
0.2784363297f, 0.2692982077f, 0.2601619588f, 0.2511740186f,
0.2422305215f, 0.2334738679f, 0.2246834377f, 0.2156750628f,
0.2071598962f, 0.1984767185f, 0.1898938500f, 0.1814067004f,
0.1729007855f, 0.1645454321f, 0.1562017822f, 0.1479358113f,
0.1397136271f, 0.1315923511f, 0.1235258532f, 0.1155633999f,
0.1076300783f, 0.0998030288f, 0.0920097856f, 0.0843282945f,
0.0766873597f, 0.0691492555f, 0.0616418371f, 0.0542297395f,
0.0468355725f, 0.0395537898f, 0.0322938011f, 0.0251689168f,
0.0180789645f, 0.0111402133f, 0.0042491810f, -0.0025108764f,
-0.0093228281f, -0.0160240942f, -0.0229218816f, -0.0291537434f,
-0.0356596108f, -0.0421512920f, -0.0483829023f, -0.0546891309f,
-0.0607956180f, -0.0668947833f, -0.0729015436f, -0.0788312843f,
-0.0846659246f, -0.0904454283f, -0.0961440884f, -0.1018001799f,
-0.1073604731f, -0.1128619755f, -0.1182710743f, -0.1236191798f,
-0.1288821834f, -0.1340828639f, -0.1391845207f, -0.1442198838f,
-0.1491346512f, -0.1539912234f, -0.1587317239f, -0.1634326051f,
-0.1680332327f, -0.1726183100f, -0.1771140890f, -0.1816310071f,
-0.1859484086f, -0.1902676621f, -0.1941135048f, -0.1982312400f,
-0.2025752799f, -0.2062425510f, -0.2102567274f, -0.2139529315f,
-0.2177326536f, -0.2213504338f, -0.2249483716f, -0.2284043787f,
-0.2318685842f, -0.2351846242f, -0.2384901545f, -0.2416375134f,
-0.2447669078f, -0.2477656128f, -0.2507463340f, -0.2536057399f,
-0.2564433319f, -0.2591571117f, -0.2618581518f, -0.2644425265f,
-0.2670290887f, -0.2695102609f, -0.2719823809f, -0.2743418063f,
-0.2766682382f, -0.2788599641f, -0.2809996598f, -0.2829509809f,
-0.2848865889f, -0.2867034021f, -0.2886979015f, -0.2909536921f,
-0.2921271926f, -0.2939578995f, -0.2955408715f, -0.2970457316f,
-0.2985327732f, -0.2998832522f, -0.3012206975f, -0.3024750370f,
-0.3036791840f, -0.3047953307f, -0.3058756301f, -0.3068771119f,
-0.3078644089f, -0.3087558210f, -0.3096257208f, -0.3103913733f,
-0.3111336729f, -0.3117751598f, -0.3123958369f, -0.3129048624f,
-0.3133944699f, -0.3137462882f, -0.3140959719f, -0.3143048413f,
-0.3145480407f, -0.3146624743f, -0.3148580017f, -0.3149481827f,
-0.3152146050f, -0.3152392795f, -0.3154945639f, -0.3145152697f,
-0.3146688330f, -0.3147549076f, -0.3142523940f, -0.3141297440f,
-0.3136545108f, -0.3133679403f, -0.3128663068f, -0.3124439347f,
-0.3118458639f, -0.3113288653f, -0.3106447420f, -0.3100296179f,
-0.3092353383f, -0.3085060392f, -0.3076169401f, -0.3068011429f,
-0.3058372184f, -0.3049525345f, -0.3039122280f, -0.3029682798f,
-0.3018593574f, -0.3008800902f, -0.2997260603f, -0.2987161065f,
-0.2974931002f, -0.2964174081f, -0.2950580040f, -0.2938671020f,
-0.2922042842f, -0.2908411467f, -0.2887415908f, -0.2879411883f,
-0.2872351631f, -0.2847616987f, -0.2836812630f, -0.2818896819f,
-0.2804988036f, -0.2787902978f, -0.2772761254f, -0.2755608442f,
-0.2740080396f, -0.2722769142f, -0.2706716369f, -0.2689155628f,
-0.2672727018f, -0.2655133466f, -0.2638390865f, -0.2620527778f,
-0.2603277216f, -0.2584896769f, -0.2567089643f, -0.2548171418f,
-0.2529788379f, -0.2510271295f, -0.2491104380f, -0.2470901019f,
-0.2451131271f, -0.2430630996f, -0.2410984360f, -0.2390892017f,
-0.2372897729f, -0.2355468158f, -0.2341760732f, -0.2330266272f,
-0.2285011851f, -0.2276718013f, -0.2256330226f, -0.2236245172f,
-0.2216212397f, -0.2195723764f, -0.2175598198f, -0.2155244502f,
-0.2134958020f, -0.2114475228f, -0.2094317510f, -0.2073919547f,
-0.2054038199f, -0.2033652690f, -0.2013983100f, -0.1993785604f,
-0.1974621775f, -0.1954904285f, -0.1936526632f, -0.1917311189f,
-0.1899836720f, -0.1881030278f, -0.1864679413f, -0.1846305866f,
-0.1831168886f, -0.1812660021f, -0.1798377067f, -0.1778294249f,
-0.1764397529f, -0.1738005522f, -0.1723006308f, -0.1666149935f,
-0.1685811576f, -0.1683593655f, -0.1645983125f, -0.1640690747f,
-0.1614806858f, -0.1606274956f, -0.1583282171f, -0.1573540028f,
-0.1551676484f, -0.1541795914f, -0.1520476681f, -0.1510623954f,
-0.1489403301f, -0.1479788256f, -0.1458627832f, -0.1449481895f,
-0.1428068116f, -0.1419434716f, -0.1397338876f, -0.1389458751f,
-0.1366453783f, -0.1359864220f, -0.1335694857f, -0.1330985791f,
-0.1305094750f, -0.1303677621f, -0.1275474455f, -0.1280766855f,
-0.1248521391f, -0.1270419996f, -0.1230013683f, -0.1333820215f,
-0.1356269751f, -0.1173893915f, -0.1247875900f, -0.1205369109f,
-0.1227782673f, -0.1200347844f, -0.1212624937f, -0.1191925052f,
-0.1200564042f, -0.1183823726f, -0.1190734477f, -0.1176885372f,
-0.1183154633f, -0.1171681501f, -0.1177737061f, -0.1168115435f,
-0.1174295604f, -0.1166353753f, -0.1173065305f, -0.1166760717f,
-0.1174165122f, -0.1169320615f, -0.1177379144f, -0.1173947314f,
-0.1182902140f, -0.1180910084f, -0.1190858794f, -0.1190024264f,
-0.1201208291f, -0.1201684429f, -0.1213842597f, -0.1215729938f,
} };
void WidebandSpectrum::execute(buffer_c8_t buffer) {
sample_count += buffer.count;
if( sample_count > 400000 ) {
sample_count -= 400000;
// 2048 complex8_t samples per buffer.
// 102.4us per buffer. 20480 instruction cycles per buffer.
static int phase = 0;
if( phase == 0 ) {
std::fill(spectrum.begin(), spectrum.end(), 0);
}
if( (phase & 7) == 0 ) {
const size_t window_offset = (phase >> 3) * 256;
const auto window_p = &window_wideband_bin_lpf[window_offset];
for(size_t i=0; i<channel_spectrum.size(); i++) {
spectrum[i] += std::complex<float> { buffer.p[i].real() * window_p[i], buffer.p[i].imag() * window_p[i] };
}
}
if( phase == 23 ) {
if( channel_spectrum_request_update == false ) {
channel_spectrum_request_update = true;
constexpr int32_t k = 128 * 16;
const auto& window = window_wideband_bin_lpf;
for(size_t i=0; i<channel_spectrum.size(); i++) {
int64_t real = 0;
int64_t imag = 0;
real += buffer.p[i + 0].real() * window[i + 0];
imag += buffer.p[i + 0].imag() * window[i + 0];
real += buffer.p[i + 256].real() * window[i + 256];
imag += buffer.p[i + 256].imag() * window[i + 256];
real += buffer.p[i + 512].real() * window[i + 512];
imag += buffer.p[i + 512].imag() * window[i + 512];
real += buffer.p[i + 768].real() * window[i + 768];
imag += buffer.p[i + 768].imag() * window[i + 768];
channel_spectrum[i].real(real / k);
channel_spectrum[i].imag(imag / k);
}
fft_swap(spectrum, channel_spectrum);
channel_spectrum_sampling_rate = buffer.sampling_rate;
channel_filter_pass_frequency = 0;
channel_filter_stop_frequency = 0;
channel_spectrum_request_update = true;
events_flag(EVT_MASK_SPECTRUM);
phase = 0;
}
} else {
phase++;
}
i2s::i2s0::tx_mute();
}

View File

@ -25,6 +25,8 @@
#include "baseband_processor.hpp"
#include <cstddef>
#include <array>
#include <complex>
class WidebandSpectrum : public BasebandProcessor {
public:
@ -32,6 +34,8 @@ public:
private:
size_t sample_count = 0;
std::array<std::complex<float>, 256> spectrum;
};
#endif/*__PROC_WIDEBAND_SPECTRUM_H__*/