diff --git a/firmware/baseband/proc_fsk.cpp b/firmware/baseband/proc_fsk.cpp index ffb3e778..fd1e702e 100644 --- a/firmware/baseband/proc_fsk.cpp +++ b/firmware/baseband/proc_fsk.cpp @@ -21,6 +21,8 @@ #include "proc_fsk.hpp" +#include "ais_baseband.hpp" + #include "portapack_shared_memory.hpp" #include "i2s.hpp" @@ -43,10 +45,8 @@ FSKProcessor::~FSKProcessor() { } void FSKProcessor::configure(const FSKConfiguration new_configuration) { - // TODO: Matched filter characteristics are hard-coded for the moment. YUCK! - decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By16); - channel_filter.configure(channel_filter_taps.taps, 8); - mf.configure(baseband::ais::rrc_taps_128_decim_4_p, 1); + decimator.set_decimation_factor(ChannelDecimator::DecimationFactor::By32); + mf.configure(baseband::ais::rrc_taps_76k8_4t_p, 4); clock_recovery.configure(new_configuration.symbol_rate * 2, new_configuration.symbol_rate, { 0.0555f }); packet_builder.configure( { new_configuration.access_code, new_configuration.access_code_length, new_configuration.access_code_tolerance }, @@ -59,20 +59,8 @@ void FSKProcessor::execute(buffer_c8_t buffer) { auto decimator_out = decimator.execute(buffer); - /* 153.6kHz, 128 samples */ - - const buffer_c16_t work_baseband_buffer { - (complex16_t*)decimator_out.p, - decimator_out.count - }; - - /* 153.6kHz complex[128] - * -> FIR filter, 19.2kHz int16_t[16] */ - auto channel = channel_filter.execute(decimator_out, work_baseband_buffer); - /* 76.8kHz, 64 samples */ - feed_channel_stats(channel); + feed_channel_stats(decimator_out); /* No spectrum display while FSK decoding. feed_channel_spectrum( channel, @@ -80,14 +68,12 @@ void FSKProcessor::execute(buffer_c8_t buffer) { decimator_out.sampling_rate * channel_filter_taps.stop_frequency_normalized ); */ - // 76.8k - // TODO: Factor out this hidden decimation magic. - for(size_t i=0; ifloat is not allowed. const std::complex sample { - static_cast(channel.p[i].real()), - static_cast(channel.p[i].imag()) + static_cast(decimator_out.p[i].real()), + static_cast(decimator_out.p[i].imag()) }; if( mf.execute_once(sample) ) { clock_recovery(mf.get_output()); diff --git a/firmware/baseband/proc_fsk.hpp b/firmware/baseband/proc_fsk.hpp index 5e993c60..2e1dd568 100644 --- a/firmware/baseband/proc_fsk.hpp +++ b/firmware/baseband/proc_fsk.hpp @@ -25,9 +25,7 @@ #include "baseband_processor.hpp" #include "channel_decimator.hpp" -#include "dsp_decimate.hpp" #include "matched_filter.hpp" -#include "dsp_fir_taps.hpp" #include "clock_recovery.hpp" #include "symbol_coding.hpp" @@ -39,8 +37,6 @@ #include #include -#include "ais_baseband.hpp" - class FSKProcessor : public BasebandProcessor { public: using payload_t = std::bitset<1024>; @@ -54,8 +50,6 @@ public: private: ChannelDecimator decimator; - const fir_taps_real<64>& channel_filter_taps = taps_64_lp_042_078_tfilter; - dsp::decimate::FIRAndDecimateComplex channel_filter; dsp::matched_filter::MatchedFilter mf; clock_recovery::ClockRecovery clock_recovery { diff --git a/firmware/common/ais_baseband.hpp b/firmware/common/ais_baseband.hpp index 0dac7dd1..2be4753b 100644 --- a/firmware/common/ais_baseband.hpp +++ b/firmware/common/ais_baseband.hpp @@ -32,157 +32,29 @@ namespace baseband { namespace ais { -// RRC length should be about 4 x the symbol length to do a good job of +// RRC length should be about 4 x the symbol length (4T) to do a good job of // cleaning up ISI. -/* -constexpr std::array, 8> rrc_taps_8_p { { - { 0.00533687f, 0.00000000f }, { -0.00667109f, 0.00667109f }, - { 0.00000000f, 0.01334218f }, { -0.05145006f, -0.05145006f }, - { -0.14292666f, 0.00000000f }, { -0.05145006f, 0.05145006f }, - { 0.00000000f, -0.01334218f }, { -0.00667109f, -0.00667109f }, -} }; -*/ -// -// These came from GRC directly, and have a bit more gain, it appears. -// -constexpr std::array, 8> rrc_taps_128_decim_16_p { { - { 2.1046938375e-02f, 0.0000000000e+00f }, { -2.6308671336e-02f, -2.6308671336e-02f }, - { -3.2218829289e-18f, -5.2617341280e-02f }, { -2.0290270482e-01f, 2.0290270482e-01f }, - { -5.6365746260e-01f, 6.9028130738e-17f }, { -2.0290270482e-01f, -2.0290270482e-01f }, - { 9.6656487867e-18f, 5.2617341280e-02f }, { -2.6308671336e-02f, 2.6308671336e-02f }, -} }; - -constexpr std::array, 16> rrc_taps_128_decim_8_p { { - { -5.0682835281e-03f, 0.0000000000e+00f }, { 3.8012127427e-03f, 3.8012127427e-03f }, - { 9.3102863700e-20f, 1.5204851516e-03f }, { 5.3216978397e-03f, -5.3216978397e-03f }, - { -2.1286793053e-02f, 2.6068802977e-18f }, { 2.6608490845e-02f, 2.6608490845e-02f }, - { 9.7758004319e-18f, 5.3216978908e-02f }, { 2.0521502845e-01f, -2.0521502845e-01f }, - { 5.7008099556e-01f, -1.3962957329e-16f }, { 2.0521502845e-01f, 2.0521502845e-01f }, - { -1.6293000720e-17f, -5.3216978908e-02f }, { 2.6608490845e-02f, -2.6608490845e-02f }, - { -2.1286793053e-02f, 7.8206408930e-18f }, { 5.3216978397e-03f, 5.3216978397e-03f }, - { -6.5172004590e-19f, -1.5204851516e-03f }, { 3.8012127427e-03f, -3.8012127427e-03f }, -} }; - -constexpr std::array, 32> rrc_taps_128_decim_4_p { { - { -1.2495006667e-03f, 0.0000000000e+00f }, { 7.5862532786e-04f, 7.5862532786e-04f }, - { 7.1465238505e-21f, 1.1671159155e-04f }, { 8.7533694842e-04f, -8.7533694842e-04f }, - { -2.2281305864e-03f, 2.7286729908e-19f }, { 1.4482847468e-03f, 1.4482847468e-03f }, - { 5.9121245638e-20f, 3.2184107113e-04f }, { 1.7701258199e-03f, -1.7701258199e-03f }, - { -5.0575020723e-03f, 1.2387307449e-18f }, { 3.7931268039e-03f, 3.7931268039e-03f }, - { 4.6452407924e-19f, 1.5172507847e-03f }, { 5.3103774596e-03f, -5.3103774596e-03f }, - { -2.1241510287e-02f, 7.8040042746e-18f }, { 2.6551890262e-02f, 2.6551890262e-02f }, - { 2.2761678735e-17f, 5.3103774786e-02f }, { 2.0477849246e-01f, -2.0477849246e-01f }, - { 5.6886833906e-01f, -2.7866511623e-16f }, { 2.0477849246e-01f, 2.0477849246e-01f }, - { -2.9265015516e-17f, -5.3103774786e-02f }, { 2.6551890262e-02f, -2.6551890262e-02f }, - { -2.1241510287e-02f, 1.3006673791e-17f }, { 5.3103774596e-03f, 5.3103774596e-03f }, - { -3.7171317828e-18f, -1.5172507847e-03f }, { 3.7931268039e-03f, -3.7931268039e-03f }, - { -5.0575020723e-03f, 3.7161922347e-18f }, { 1.7701258199e-03f, 1.7701258199e-03f }, - { 3.1551252346e-19f, -3.2184107113e-04f }, { 1.4482847468e-03f, -1.4482847468e-03f }, - { -2.2281305864e-03f, 1.9100710935e-18f }, { 8.7533694842e-04f, 8.7533694842e-04f }, - { -3.1451929164e-19f, -1.1671159155e-04f }, { 7.5862532786e-04f, -7.5862532786e-04f }, -} }; - -constexpr std::array, 64> rrc_taps_128_decim_2_p { { - { -6.2437308952e-04f, 0.0000000000e+00f }, { -2.2010185825e-04f, -9.1169174792e-05f }, - { 3.7908365508e-04f, 3.7908365508e-04f }, { 2.8756602409e-04f, 6.9424579543e-04f }, - { 3.5711042529e-21f, 5.8320558310e-05f }, { 2.8756602409e-04f, -6.9424579543e-04f }, - { 4.3740419207e-04f, -4.3740419207e-04f }, { -3.9158988624e-04f, 1.6220184177e-04f }, - { -1.1133925291e-03f, 1.3635125969e-19f }, { -3.9158988624e-04f, -1.6220184177e-04f }, - { 7.2370509982e-04f, 7.2370509982e-04f }, { 5.6432127027e-04f, 1.3623920642e-03f }, - { 2.9542774240e-20f, 1.6082337243e-04f }, { 5.6432127027e-04f, -1.3623920642e-03f }, - { 8.8452850107e-04f, -8.8452850107e-04f }, { -8.8299684291e-04f, 3.6574926787e-04f }, - { -2.5272241328e-03f, 6.1899138899e-19f }, { -8.8299684291e-04f, -3.6574926787e-04f }, - { 1.8954181931e-03f, 1.8954181931e-03f }, { 1.5745747777e-03f, 3.8013597832e-03f }, - { 2.3212178869e-19f, 7.5816729805e-04f }, { 1.5745747777e-03f, -3.8013597832e-03f }, - { 2.6535855032e-03f, -2.6535855032e-03f }, { -3.5740348583e-03f, 1.4804137107e-03f }, - { -1.0614342056e-02f, 3.8996460073e-18f }, { -3.5740348583e-03f, -1.4804137107e-03f }, - { 1.3267928010e-02f, 1.3267928010e-02f }, { 1.5010946154e-02f, 3.6239629790e-02f }, - { 1.1373966922e-17f, 2.6535853744e-02f }, { 1.5010946154e-02f, -3.6239629790e-02f }, - { 1.0232741681e-01f, -1.0232741681e-01f }, { 2.2516419801e-01f, -9.3266064576e-02f }, - { 2.8426241875e-01f, -1.3924842449e-16f }, { 2.2516419801e-01f, 9.3266064576e-02f }, - { 1.0232741681e-01f, 1.0232741681e-01f }, { 1.5010946154e-02f, 3.6239629790e-02f }, - { -1.4623671757e-17f, -2.6535853744e-02f }, { 1.5010946154e-02f, -3.6239629790e-02f }, - { 1.3267928010e-02f, -1.3267928010e-02f }, { -3.5740348583e-03f, 1.4804137107e-03f }, - { -1.0614342056e-02f, 6.4994100121e-18f }, { -3.5740348583e-03f, -1.4804137107e-03f }, - { 2.6535855032e-03f, 2.6535855032e-03f }, { 1.5745747777e-03f, 3.8013597832e-03f }, - { -1.8574436004e-18f, -7.5816729805e-04f }, { 1.5745747777e-03f, -3.8013597832e-03f }, - { 1.8954181931e-03f, -1.8954181931e-03f }, { -8.8299684291e-04f, 3.6574926787e-04f }, - { -2.5272241328e-03f, 1.8569741670e-18f }, { -8.8299684291e-04f, -3.6574926787e-04f }, - { 8.8452850107e-04f, 8.8452850107e-04f }, { 5.6432127027e-04f, 1.3623920642e-03f }, - { 1.5766100917e-19f, -1.6082337243e-04f }, { 5.6432127027e-04f, -1.3623920642e-03f }, - { 7.2370509982e-04f, -7.2370509982e-04f }, { -3.9158988624e-04f, 1.6220184177e-04f }, - { -1.1133925291e-03f, 9.5445881785e-19f }, { -3.9158988624e-04f, -1.6220184177e-04f }, - { 4.3740419207e-04f, 4.3740419207e-04f }, { 2.8756602409e-04f, 6.9424579543e-04f }, - { -1.5716468643e-19f, -5.8320558310e-05f }, { 2.8756602409e-04f, -6.9424579543e-04f }, - { 3.7908365508e-04f, -3.7908365508e-04f }, { -2.2010185825e-04f, 9.1169174792e-05f }, -} }; - -constexpr std::array, 128> rrc_taps_128_decim_1_p { { - { -3.1209018198e-04f, 0.0000000000e+00f }, { -2.5877077742e-04f, -5.1472707944e-05f }, - { -1.1001696231e-04f, -4.5570517881e-05f }, { 6.6159029602e-05f, 4.4206050285e-05f }, - { 1.8948331997e-04f, 1.8948331997e-04f }, { 2.1174839450e-04f, 3.1690386745e-04f }, - { 1.4373864003e-04f, 3.4701577420e-04f }, { 4.7976800158e-05f, 2.4119566214e-04f }, - { 1.7850010134e-21f, 2.9151278795e-05f }, { 3.9977422839e-05f, -2.0098007663e-04f }, - { 1.4373864003e-04f, -3.4701577420e-04f }, { 2.3252332220e-04f, -3.4799574396e-04f }, - { 2.1863459522e-04f, -2.1863459522e-04f }, { 6.2056194319e-05f, -4.1464623394e-05f }, - { -1.9573451137e-04f, 8.1075889233e-05f }, { -4.4372297073e-04f, 8.8261986569e-05f }, - { -5.5652443552e-04f, 6.8154586861e-20f }, { -4.6404687472e-04f, -9.2304662425e-05f }, - { -1.9573451137e-04f, -8.1075889233e-05f }, { 1.2883682237e-04f, 8.6086012482e-05f }, - { 3.6174088546e-04f, 3.6174088546e-04f }, { 4.0837232524e-04f, 6.1117237526e-04f }, - { 2.8207356174e-04f, 6.8098581834e-04f }, { 9.7165906259e-05f, 4.8848599782e-04f }, - { 1.4766828074e-20f, 8.0386867921e-05f }, { 7.5098076010e-05f, -3.7754352331e-04f }, - { 2.8207356174e-04f, -6.8098581834e-04f }, { 4.6580996103e-04f, -6.9713387199e-04f }, - { 4.4212772603e-04f, -4.4212772603e-04f }, { 1.1524044836e-04f, -7.7001205821e-05f }, - { -4.4136215088e-04f, 1.8281818881e-04f }, { -9.9526783374e-04f, 1.9797108099e-04f }, - { -1.2632220751e-03f, 3.0940017417e-19f }, { -1.0655584755e-03f, -2.1195275894e-04f }, - { -4.4136215088e-04f, -1.8281818881e-04f }, { 3.4870278890e-04f, 2.3299575453e-04f }, - { 9.4741662045e-04f, 9.4741662045e-04f }, { 1.0953310298e-03f, 1.6392787312e-03f }, - { 7.8704441197e-04f, 1.9000932936e-03f }, { 2.9063040056e-04f, 1.4610976903e-03f }, - { 1.1602507422e-19f, 3.7896665162e-04f }, { 1.8643098041e-04f, -9.3725183036e-04f }, - { 7.8704441197e-04f, -1.9000932936e-03f }, { 1.3689220250e-03f, -2.0487365913e-03f }, - { 1.3263832192e-03f, -1.3263832192e-03f }, { 2.3975916158e-04f, -1.6020195001e-04f }, - { -1.7864658936e-03f, 7.3997840184e-04f }, { -4.0136172125e-03f, 7.9835810150e-04f }, - { -5.3055332974e-03f, 1.9492213111e-18f }, { -4.6575086796e-03f, -9.2643607755e-04f }, - { -1.7864658936e-03f, -7.3997840184e-04f }, { 2.5328987415e-03f, 1.6924288311e-03f }, - { 6.6319165901e-03f, 6.6319165901e-03f }, { 8.6449647610e-03f, 1.2938104079e-02f }, - { 7.5031564661e-03f, 1.8114222101e-02f }, { 3.7891721988e-03f, 1.9049455038e-02f }, - { 5.6852282253e-18f, 1.3263831846e-02f }, { -3.6723852463e-05f, 1.8462327379e-04f }, - { 7.5031564661e-03f, -1.8114222101e-02f }, { 2.4807723598e-02f, -3.7127382095e-02f }, - { 5.1147919140e-02f, -5.1147919140e-02f }, { 8.2531291606e-02f, -5.5145646011e-02f }, - { 1.1254735140e-01f, -4.6618639361e-02f }, { 1.3419687671e-01f, -2.6693418442e-02f }, - { 1.4208734035e-01f, -6.9602722626e-17f }, { 1.3419687671e-01f, 2.6693418442e-02f }, - { 1.1254735140e-01f, 4.6618639361e-02f }, { 8.2531291606e-02f, 5.5145646011e-02f }, - { 5.1147919140e-02f, 5.1147919140e-02f }, { 2.4807723598e-02f, 3.7127382095e-02f }, - { 7.5031564661e-03f, 1.8114222101e-02f }, { -3.6723852463e-05f, -1.8462327379e-04f }, - { -7.3095791468e-18f, -1.3263831846e-02f }, { 3.7891721988e-03f, -1.9049455038e-02f }, - { 7.5031564661e-03f, -1.8114222101e-02f }, { 8.6449647610e-03f, -1.2938104079e-02f }, - { 6.6319165901e-03f, -6.6319165901e-03f }, { 2.5328987415e-03f, -1.6924288311e-03f }, - { -1.7864658936e-03f, 7.3997840184e-04f }, { -4.6575086796e-03f, 9.2643607755e-04f }, - { -5.3055332974e-03f, 3.2487021852e-18f }, { -4.0136172125e-03f, -7.9835810150e-04f }, - { -1.7864658936e-03f, -7.3997840184e-04f }, { 2.3975916158e-04f, 1.6020195001e-04f }, - { 1.3263832192e-03f, 1.3263832192e-03f }, { 1.3689220250e-03f, 2.0487365913e-03f }, - { 7.8704441197e-04f, 1.9000932936e-03f }, { 1.8643098041e-04f, 9.3725183036e-04f }, - { -9.2843516681e-19f, -3.7896665162e-04f }, { 2.9063040056e-04f, -1.4610976903e-03f }, - { 7.8704441197e-04f, -1.9000932936e-03f }, { 1.0953310298e-03f, -1.6392787312e-03f }, - { 9.4741662045e-04f, -9.4741662045e-04f }, { 3.4870278890e-04f, -2.3299575453e-04f }, - { -4.4136215088e-04f, 1.8281818881e-04f }, { -1.0655584755e-03f, 2.1195275894e-04f }, - { -1.2632220751e-03f, 9.2820052251e-19f }, { -9.9526783374e-04f, -1.9797108099e-04f }, - { -4.4136215088e-04f, -1.8281818881e-04f }, { 1.1524044836e-04f, 7.7001205821e-05f }, - { 4.4212772603e-04f, 4.4212772603e-04f }, { 4.6580996103e-04f, 6.9713387199e-04f }, - { 2.8207356174e-04f, 6.8098581834e-04f }, { 7.5098076010e-05f, 3.7754352331e-04f }, - { 7.8806174309e-20f, -8.0386867921e-05f }, { 9.7165906259e-05f, -4.8848599782e-04f }, - { 2.8207356174e-04f, -6.8098581834e-04f }, { 4.0837232524e-04f, -6.1117237526e-04f }, - { 3.6174088546e-04f, -3.6174088546e-04f }, { 1.2883682237e-04f, -8.6086012482e-05f }, - { -1.9573451137e-04f, 8.1075889233e-05f }, { -4.6404687472e-04f, 9.2304662425e-05f }, - { -5.5652443552e-04f, 4.7708210803e-19f }, { -4.4372297073e-04f, -8.8261986569e-05f }, - { -1.9573451137e-04f, -8.1075889233e-05f }, { 6.2056194319e-05f, 4.1464623394e-05f }, - { 2.1863459522e-04f, 2.1863459522e-04f }, { 2.3252332220e-04f, 3.4799574396e-04f }, - { 1.4373864003e-04f, 3.4701577420e-04f }, { 3.9977422839e-05f, 2.0098007663e-04f }, - { -7.8558088666e-20f, -2.9151278795e-05f }, { 4.7976800158e-05f, -2.4119566214e-04f }, - { 1.4373864003e-04f, -3.4701577420e-04f }, { 2.1174839450e-04f, -3.1690386745e-04f }, - { 1.8948331997e-04f, -1.8948331997e-04f }, { 6.6159029602e-05f, -4.4206050285e-05f }, - { -1.1001696231e-04f, 4.5570517881e-05f }, { -2.5877077742e-04f, 5.1472707944e-05f }, +// Translate+RRC filter +// sample=76.8k, deviation=2400, b=0.5, symbol=9600 +// Length: 32 taps, 4 symbols, 1 cycle of sinusoid +constexpr std::array, 32> rrc_taps_76k8_4t_p { { + { 5.3368736990e-03f, 0.0000000000e+00f }, { 4.6850211151e-03f, 9.3190864122e-04f }, + { 1.7970187432e-03f, 7.4434953528e-04f }, { -2.5478608559e-03f, -1.7024261963e-03f }, + { -6.6710920858e-03f, -6.6710920858e-03f }, { -8.6960320791e-03f, -1.3014531722e-02f }, + { -7.5474785839e-03f, -1.8221225159e-02f }, { -3.8115552023e-03f, -1.9161981995e-02f }, + { -8.1697309033e-19f, -1.3342183083e-02f }, { 3.6940784220e-05f, -1.8571386338e-04f }, + { -7.5474785839e-03f, 1.8221225159e-02f }, { -2.4954265902e-02f, 3.7346698152e-02f }, + { -5.1450054092e-02f, 5.1450054092e-02f }, { -8.3018814119e-02f, 5.5471398140e-02f }, + { -1.1321218147e-01f, 4.6894020990e-02f }, { -1.3498960022e-01f, 2.6851100952e-02f }, + { -1.4292666316e-01f, 1.7503468055e-17f }, { -1.3498960022e-01f, -2.6851100952e-02f }, + { -1.1321218147e-01f, -4.6894020990e-02f }, { -8.3018814119e-02f, -5.5471398140e-02f }, + { -5.1450054092e-02f, -5.1450054092e-02f }, { -2.4954265902e-02f, -3.7346698152e-02f }, + { -7.5474785839e-03f, -1.8221225159e-02f }, { 3.6940784220e-05f, 1.8571386338e-04f }, + { 2.4509192710e-18f, 1.3342183083e-02f }, { -3.8115552023e-03f, 1.9161981995e-02f }, + { -7.5474785839e-03f, 1.8221225159e-02f }, { -8.6960320791e-03f, 1.3014531722e-02f }, + { -6.6710920858e-03f, 6.6710920858e-03f }, { -2.5478608559e-03f, 1.7024261963e-03f }, + { 1.7970187432e-03f, -7.4434953528e-04f }, { 4.6850211151e-03f, -9.3190864122e-04f }, } }; using decoded_packet = std::pair;