SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
majority_law.h
Go to the documentation of this file.
1#include "logger.h"
2#include <cstdint>
3#include <vector>
4
9
10namespace satdump
11{
12 std::vector<unsigned char> majority_law_vec(std::vector<std::vector<unsigned char>> input);
13
23 template <size_t array_count, size_t byte_count>
24 void majority_law(const uint8_t (&input)[array_count][byte_count], uint8_t *output)
25 {
26 if (array_count < 1)
27 {
28 logger->error("Majority law was attempted with no elements!");
29 return;
30 }
31
32 for (int cur_byte_position = 0; cur_byte_position != byte_count; cur_byte_position++)
33 {
34 unsigned char output_byte = 0;
35
36 for (int bit = 7; bit >= 0; bit--)
37 {
38 int zero_votes = 0;
39 int one_votes = 0;
40
41 // Gets the bit value from each element
42 for (int cur_array = 0; cur_array < array_count; cur_array++)
43 {
44 unsigned char byte = input[cur_array][cur_byte_position];
45
46 if (((byte >> bit) & 1) == 0)
47 {
48 zero_votes++;
49 }
50 else
51 {
52 one_votes++;
53 }
54 }
55
56 // Push new bit
57 output_byte = output_byte << 1;
58
59 // Set the new bit accordingly
60 if (one_votes >= zero_votes)
61 {
62 output_byte |= 1;
63 }
64 }
65
66 // Add to output
67 output[cur_byte_position] = output_byte;
68 }
69 return;
70 }
71} // namespace satdump
void majority_law(const uint8_t(&input)[array_count][byte_count], uint8_t *output)
Applies majority law between N arrays on the bit level Defined here because cpp is stupid and needs t...
Definition majority_law.h:24