diff --git a/openrtx/include/protocols/M17/M17Demodulator.h b/openrtx/include/protocols/M17/M17Demodulator.h index cadcbeab..7789a306 100644 --- a/openrtx/include/protocols/M17/M17Demodulator.h +++ b/openrtx/include/protocols/M17/M17Demodulator.h @@ -106,8 +106,8 @@ private: static constexpr size_t M17_SAMPLES_PER_SYMBOL = M17_SPS; static constexpr size_t M17_INPUT_BUF_SIZE = M17_FRAME_SAMPLES_24K / 2; static constexpr size_t M17_FRAME_BYTES = M17_FRAME_SYMBOLS / 4; - static constexpr float conv_stats_alpha = 0.0009765625f; - static constexpr float conv_threshold_factor = 3.65; + static constexpr float conv_stats_alpha = 0.0001f; + static constexpr float conv_threshold_factor = 3.70; static constexpr float qnt_maxmin_alpha = 0.999f; /** diff --git a/openrtx/src/protocols/M17/M17Demodulator.cpp b/openrtx/src/protocols/M17/M17Demodulator.cpp index 942909ef..39e69541 100644 --- a/openrtx/src/protocols/M17/M17Demodulator.cpp +++ b/openrtx/src/protocols/M17/M17Demodulator.cpp @@ -84,7 +84,7 @@ void M17Demodulator::stopBasebandSampling() void M17Demodulator::resetCorrelationStats() { conv_ema = 0.0f; - conv_emvar = 1000000000.0f; + conv_emvar = 20000000000.0f; } /** @@ -204,7 +204,7 @@ void M17Demodulator::update() for(size_t i = 0; i < baseband.len; i++) { float elem = static_cast< float >(baseband.data[i]); - baseband.data[i] = static_cast< int16_t >(M17::rrc(elem) * 0.10); + baseband.data[i] = static_cast< int16_t >(M17::rrc(elem)); } // If we locked a syncword just demodulate samples diff --git a/scripts/plot_m17_demod_csv.py b/scripts/plot_m17_demod_csv.py index 70448200..24b2c726 100755 --- a/scripts/plot_m17_demod_csv.py +++ b/scripts/plot_m17_demod_csv.py @@ -2,9 +2,11 @@ import pandas as pd from matplotlib import pyplot as plt +from sys import argv plt.rcParams["figure.autolayout"] = True -df = pd.read_csv("./build_linux/M17_demodulator_output_1.csv") +df = pd.read_csv(argv[1]) +#df = df.head(n=10000) print("Contents in csv file:\n", df) #plt.plot(df.index, df.Input) #plt.plot(df.index, df.RRCSignal) diff --git a/scripts/plot_m17_demod_csv2.py b/scripts/plot_m17_demod_csv2.py index ff85ec46..f19b98c0 100755 --- a/scripts/plot_m17_demod_csv2.py +++ b/scripts/plot_m17_demod_csv2.py @@ -2,9 +2,11 @@ import pandas as pd from matplotlib import pyplot as plt +from sys import argv plt.rcParams["figure.autolayout"] = True -df = pd.read_csv("./build_linux/M17_clock_recovery_output_2.csv") +df = pd.read_csv(argv[1]) +#df = df.head(n=10000) print("Contents in csv file:\n", df) plt.plot(df.index, df.RRCSignal) plt.plot(df.index, df.SyncDetect) diff --git a/tests/unit/M17_demodulator.cpp b/tests/unit/M17_demodulator.cpp index 6ffacefd..8e4c8ddd 100644 --- a/tests/unit/M17_demodulator.cpp +++ b/tests/unit/M17_demodulator.cpp @@ -83,11 +83,10 @@ int main() M17::M17Demodulator m17Demodulator = M17::M17Demodulator(); m17Demodulator.init(); dataBlock_t baseband = { nullptr, 0 }; - baseband.data = baseband_buffer; + baseband.data = filtered_buffer; baseband.len = baseband_samples; dataBlock_t old_baseband = m17Demodulator.baseband; m17Demodulator.baseband = baseband; - baseband.data = filtered_buffer; FILE *output_csv_1 = fopen("M17_demodulator_output_1.csv", "w"); fprintf(output_csv_1, "Input,RRCSignal,LSFConvolution,FrameConvolution,Stddev\n"); @@ -109,7 +108,8 @@ int main() baseband.data[i], lsf_conv, stream_conv, - 3.65 * m17Demodulator.getCorrelationStddev()); + m17Demodulator.conv_threshold_factor * + m17Demodulator.getCorrelationStddev()); } fclose(output_csv_1); @@ -126,6 +126,7 @@ int main() fscanf(syncword_ref, "%d\n", &expected_syncword); syncword = m17Demodulator.nextFrameSync(offset); offset = syncword.index + m17Demodulator.M17_SYNCWORD_SYMBOLS * M17_SPS; + //printf("%d\n", syncword.index); if (syncword.index != expected_syncword) { fprintf(stderr, "Error in syncwords detection #%d!\n", i); diff --git a/tests/unit/assets/M17_test_baseband.raw b/tests/unit/assets/M17_test_baseband.raw index 4f96e287..f7094971 100644 Binary files a/tests/unit/assets/M17_test_baseband.raw and b/tests/unit/assets/M17_test_baseband.raw differ diff --git a/tests/unit/assets/M17_test_baseband_syncwords.txt b/tests/unit/assets/M17_test_baseband_syncwords.txt index 9a5b14fd..1e2a8a0e 100644 --- a/tests/unit/assets/M17_test_baseband_syncwords.txt +++ b/tests/unit/assets/M17_test_baseband_syncwords.txt @@ -1,2 +1,668 @@ -1957 +1999 +3919 +5839 +7758 +9678 +11598 +13518 +15438 +17359 +19278 +21198 +23118 +25038 +26958 +28879 +30798 +32718 +34638 +36558 +38478 +40398 +42317 +44238 +46157 +48078 +49998 +51918 +53837 +55758 +57678 +59598 +61518 +63438 +65357 +67277 +69197 +71117 +73038 +74958 +76877 +78798 +80717 +82638 +84558 +86479 +88397 +90318 +92237 +94158 +96078 +97999 +99917 +101838 +103757 +105678 +107598 +109519 +111437 +113358 +115278 +117198 +119118 +121038 +122957 +124877 +126797 +128717 +130638 +132558 +134477 +136398 +138318 +140238 +142158 +144079 +145998 +147918 +149838 +151758 +153678 +155599 +157518 +159438 +161358 +163278 +165198 +167119 +169038 +170958 +172878 +174798 +176718 +178639 +180558 +182478 +184398 +186318 +188238 +190159 +192077 +193998 +195918 +197838 +199758 +201679 +203598 +205518 +207438 +209358 +211278 +213199 +215118 +217038 +218958 +220878 +222798 +224719 +226638 +228558 +230478 +232398 +234318 +236239 +238158 +240078 +241998 +243918 +245838 +247759 +249678 +251598 +253517 +255438 +257358 +259278 +261197 +263117 +265037 +266957 +268878 +270798 +272717 +274637 +276557 +278477 +280398 +282318 +284237 +286157 +288077 +289997 +291918 +293838 +295757 +297678 +299597 +301518 +303438 +305359 +307277 +309198 +311117 +313037 +314958 +316878 +318797 +320717 +322637 +324557 +326478 +328398 +330317 +332237 +334157 +336077 +337998 +339918 +341837 +343757 +345677 +347597 +349518 +351438 +353357 +355278 +357197 +359118 +361038 +362959 +364878 +366798 +368718 +370638 +372558 +374478 +376397 +378318 +380237 +382158 +384078 +385998 +387917 +389838 +391758 +393678 +395598 +397519 +399438 +401358 +403277 +405198 +407118 +409039 +410958 +412878 +414798 +416718 +418638 +420559 +422478 +424398 +426318 +428238 +430158 +432079 +433998 +435918 +437837 +439757 +441678 +443598 +445517 +447438 +449357 +451278 +453198 +455119 +457037 +458958 +460877 +462797 +464718 +466638 +468557 +470478 +472397 +474318 +476238 +478159 +480077 +481998 +483918 +485838 +487758 +489679 +491598 +493518 +495438 +497358 +499278 +501199 +503117 +505038 +506957 +508878 +510798 +512718 +514637 +516557 +518477 +520397 +522318 +524238 +526157 +528077 +529997 +531917 +533838 +535758 +537677 +539597 +541517 +543438 +545358 +547278 +549197 +551118 +553037 +554958 +556878 +558798 +560717 +562637 +564557 +566477 +568398 +570318 +572237 +574157 +576077 +577997 +579918 +581838 +583757 +585677 +587597 +589517 +591438 +593358 +595277 +597197 +599117 +601038 +602958 +604879 +606797 +608718 +610638 +612558 +614478 +616398 +618317 +620237 +622157 +624077 +625998 +627918 +629837 +631758 +633677 +635598 +637518 +639439 +641357 +643278 +645197 +647117 +649038 +650958 +652877 +654797 +656717 +658637 +660558 +662478 +664397 +666317 +668237 +670158 +672078 +673999 +675917 +677838 +679758 +681678 +683598 +685518 +687437 +689358 +691277 +693198 +695118 +697038 +698957 +700878 +702798 +704718 +706638 +708558 +710477 +712398 +714317 +716238 +718158 +720079 +721998 +723918 +725838 +727758 +729678 +731599 +733518 +735438 +737358 +739278 +741198 +743119 +745037 +746958 +748877 +750797 +752718 +754638 +756557 +758477 +760397 +762317 +764238 +766158 +768077 +769997 +771917 +773837 +775758 +775840 +777678 +779597 +781517 +783437 +785357 +787278 +789198 +791117 +793037 +794957 +796877 +798798 +798880 +800718 +802637 +804557 +806477 +808397 +810318 +812238 +814157 +816077 +817997 +819917 +821838 +823758 +825677 +827597 +829517 +831437 +833358 +835278 +837197 +839117 +841037 +842957 +844878 +846798 +848717 +850637 +852557 +854477 +856398 +858318 +860237 +862157 +864077 +865997 +867918 +869838 +871757 +873677 +875597 +877517 +879438 +881358 +883277 +885198 +887118 +889038 +890958 +892879 +894797 +896718 +898637 +900557 +902478 +904398 +906317 +908237 +910157 +912077 +913998 +915918 +917837 +919757 +921677 +923597 +925518 +927438 +929357 +931277 +933197 +935117 +937038 +938958 +940877 +942798 +944717 +946638 +948558 +950479 +952397 +954318 +956237 +958157 +960078 +961998 +963917 +965837 +967757 +969677 +971598 +973518 +975437 +977357 +979277 +981197 +983118 +985038 +986957 +988877 +990797 +992717 +994638 +996558 +998477 +1000398 +1002317 +1004238 +1006158 +1008078 +1009997 +1011918 +1013838 +1015758 +1017678 +1019598 +1021517 +1023437 +1025357 +1027277 +1029198 +1031118 +1033037 +1034957 +1036877 +1038798 +1040718 +1042638 +1044557 +1046477 +1048397 +1050317 +1052238 +1054158 +1056077 +1057998 +1059918 +1061838 +1063758 +1065679 +1067598 +1069518 +1071438 +1073358 +1075278 +1077199 +1079118 +1081038 +1082958 +1084878 +1086798 +1088719 +1090638 +1092558 +1094478 +1096398 +1098318 +1100239 +1102158 +1104078 +1105998 +1107918 +1109838 +1111759 +1113678 +1115598 +1117518 +1119438 +1121358 +1123279 +1125198 +1127118 +1129038 +1130958 +1132878 +1134799 +1136718 +1138638 +1140558 +1142478 +1144398 +1146318 +1148237 +1150158 +1152077 +1153998 +1155918 +1157838 +1159757 +1161678 +1163598 +1165518 +1167438 +1169358 +1171277 +1173197 +1175117 +1177037 +1178958 +1180878 +1182797 +1184717 +1186637 +1188558 +1190478 +1192399 +1194318 +1196238 +1198157 +1200078 +1201998 +1203918 +1205837 +1207757 +1209677 +1211598 +1213518 +1215438 +1217357 +1219277 +1221197 +1223117 +1225038 +1226958 +1228877 +1230797 +1232717 +1234637 +1236558 +1238478 +1240397 +1242317 +1244237 +1246157 +1248078 +1249998 +1251917 +1253838 +1255757 +1257678 +1259598 +1261519 +1263437 +1265358 +1267277 +1269198 +1271118 +1273039 +1274958 +1276878 -1