Skip to content

Commit

Permalink
afsk clock skew initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Jerred committed Dec 1, 2023
1 parent 368c8a1 commit 85373ed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
13 changes: 3 additions & 10 deletions src/demodulators/afsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>

#include "bit-stream.h"
#include "demodulators.hpp"
Expand Down Expand Up @@ -74,8 +75,8 @@ void afskSignalToBaseBand(wavgen::Reader &wavgen_reader,

double s1 = mark_i_integ * mark_i_integ + mark_q_integ * mark_q_integ;
double s2 = space_i_integ * space_i_integ + space_q_integ * space_q_integ;
int result = s1 - s2;

double result = s1 - s2;
std::cout << result << " ";
if (result > 0) {
result = 1;
} else {
Expand Down Expand Up @@ -125,13 +126,5 @@ bool demodulators::afskDecodeAscii(wavgen::Reader &wavgen_reader,
afskBaseBandToBitStream(base_band_signal, bit_stream);
message = afskBitStreamToAscii(bit_stream);

// bit_stream.dumpBitStreamAsHex();
// std::ofstream out_file("out.txt");
// for (double d : base_band_signal) {
// std::clamp(d, 0.0, 1.0);
// out_file << d << std::endl;
// }

(void)message;
return false;
}
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ add_executable(mwav_unit_tests
${MWAV_TESTS}/afsk_ascii_test.cpp
)
target_link_libraries(mwav_unit_tests GTest::GTest GTest::Main MWavLib WavGen)
target_include_directories(mwav_unit_tests PRIVATE)
target_include_directories(mwav_unit_tests PRIVATE)

configure_file(${MWAV_TESTS}/afsk_timing_skew.wav ${CMAKE_CURRENT_BINARY_DIR}/afsk_timing_skew.wav COPYONLY)
27 changes: 21 additions & 6 deletions tests/afsk_ascii_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@
#include <data_modes.hpp>
#include <wav_gen.hpp>

const std::string kOutFilePath = "test.wav";
const mwav::data::Mode kMode = mwav::data::Mode::AFSK1200;

/**
* @brief Encodes a string into an AFSK1200 signal/WAV file and then decodes it.
*/
TEST(DataModulation, EncodeAndDecodeAsciiAFSK) {
mwav::data::Mode mode = mwav::data::Mode::AFSK1200;

std::string input = "UUUHello World!UUU\x04";
const std::string kOutFilePath = "test.wav";
std::string input = "Hello World!\x04";
std::string output;

mwav::data::encodeString(mode, input, kOutFilePath);
mwav::data::decodeString(mode, kOutFilePath, output);
mwav::data::encodeString(kMode, input, kOutFilePath);
mwav::data::decodeString(kMode, kOutFilePath, output);
EXPECT_STREQ(input.c_str(), output.c_str());

wavgen::Reader reader(kOutFilePath);
const auto total_samples = reader.getNumSamples();
const auto minimum_samples = input.size() * 8;
EXPECT_GE(total_samples, minimum_samples);
}

/**
* @brief Pre-prepared WAV file with 20 samples added to the start of the file.
* @details 20 samples is enough to throw the signal off by 1/2 of a bit. This
* should test the ability of the demodulator to sync to the signal.
*/
TEST(DataModulation, DecodeWithSignalSkew) {
const std::string kInputFile = "afsk_timing_skew.wav";
std::string output;
mwav::data::decodeString(kMode, kInputFile, output);

std::cout << output << std::endl;
}
Binary file added tests/afsk_timing_skew.wav
Binary file not shown.

0 comments on commit 85373ed

Please sign in to comment.