Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdavidberger/e3f93f485739f4d35dda57b08439bdd7 to your computer and use it in GitHub Desktop.
Save jdavidberger/e3f93f485739f4d35dda57b08439bdd7 to your computer and use it in GitHub Desktop.
Lighthouse v2 polynomials and freq per mode
Mode 1:
CARRIER_POLYNOMIALS[0]: 0x0001D258
CARRIER_POLYNOMIALS[1]: 0x00017E04
Rotor Frequency: 50.0521 Hz
Mode 2:
CARRIER_POLYNOMIALS[0]: 0x0001FF6B
CARRIER_POLYNOMIALS[1]: 0x00013F67
Rotor Frequency: 50.1567 Hz
Mode 3:
CARRIER_POLYNOMIALS[0]: 0x0001B9EE
CARRIER_POLYNOMIALS[1]: 0x000198D1
Rotor Frequency: 50.3673 Hz
Mode 4:
CARRIER_POLYNOMIALS[0]: 0x000178C7
CARRIER_POLYNOMIALS[1]: 0x00018A55
Rotor Frequency: 50.5796 Hz
Mode 5:
CARRIER_POLYNOMIALS[0]: 0x00015777
CARRIER_POLYNOMIALS[1]: 0x0001D911
Rotor Frequency: 50.6864 Hz
Mode 6:
CARRIER_POLYNOMIALS[0]: 0x00015769
CARRIER_POLYNOMIALS[1]: 0x0001991F
Rotor Frequency: 50.9014 Hz
Mode 7:
CARRIER_POLYNOMIALS[0]: 0x00012BD0
CARRIER_POLYNOMIALS[1]: 0x0001CF73
Rotor Frequency: 51.0096 Hz
Mode 8:
CARRIER_POLYNOMIALS[0]: 0x0001365D
CARRIER_POLYNOMIALS[1]: 0x000197F5
Rotor Frequency: 51.1182 Hz
Mode 9:
CARRIER_POLYNOMIALS[0]: 0x000194A0
CARRIER_POLYNOMIALS[1]: 0x0001B279
Rotor Frequency: 51.2273 Hz
Mode 10:
CARRIER_POLYNOMIALS[0]: 0x00013A34
CARRIER_POLYNOMIALS[1]: 0x0001AE41
Rotor Frequency: 51.6685 Hz
Mode 11:
CARRIER_POLYNOMIALS[0]: 0x000180D4
CARRIER_POLYNOMIALS[1]: 0x00017891
Rotor Frequency: 52.2307 Hz
Mode 12:
CARRIER_POLYNOMIALS[0]: 0x00012E64
CARRIER_POLYNOMIALS[1]: 0x00017C72
Rotor Frequency: 52.6894 Hz
Mode 13:
CARRIER_POLYNOMIALS[0]: 0x00019C6D
CARRIER_POLYNOMIALS[1]: 0x00013F32
Rotor Frequency: 52.9217 Hz
Mode 14:
CARRIER_POLYNOMIALS[0]: 0x0001AE14
CARRIER_POLYNOMIALS[1]: 0x00014E76
Rotor Frequency: 53.2741 Hz
Mode 15:
CARRIER_POLYNOMIALS[0]: 0x00013C97
CARRIER_POLYNOMIALS[1]: 0x000130CB
Rotor Frequency: 53.7514 Hz
Mode 16:
CARRIER_POLYNOMIALS[0]: 0x00013750
CARRIER_POLYNOMIALS[1]: 0x0001CB8D
Rotor Frequency: 54.1150 Hz
@jdavidberger
Copy link
Author

https://onlinegdb.com/BJgoLYAxB

#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;



uint16_t reverse(uint16_t v) {
    uint16_t rtn = 0;
    for(int i = 0;i < 16;i++) {
        rtn = rtn << 1;
        rtn |= v & 1;
        v = v >> 1;
    }
    return rtn;
}
uint32_t reverse32(uint32_t v) {
    uint32_t rtn = 0;
    for(int i = 0;i < 32;i++) {
        rtn = rtn << 1;
        rtn |= v & 1;
        v = v >> 1;
    }
    return rtn;
}

uint32_t polys[] = {
    // x^17 + x^13 + x^12 + x^10 + x^7 + x^4 + x^2 + x^1 + 1
    0x0001D258, 
    // x^17 + x^14 +  x^7 +  x^6 + x^5 + x^4 + x^3 + x^2 + 1
    0x00017E04,
    0x0001FF6B, 0x00013F67,
    0x0001B9EE, 0x000198D1,
    0x000178C7, 0x00018A55,
    0x00015777, 0x0001D911,
    0x00015769, 0x0001991F,
    0x00012BD0, 0x0001CF73,
    0x0001365D, 0x000197F5,
    0x000194A0, 0x0001B279,
    0x00013A34, 0x0001AE41,
    0x000180D4, 0x00017891,
    0x00012E64, 0x00017C72,
    0x00019C6D, 0x00013F32,
    0x0001AE14, 0x00014E76,
    0x00013C97, 0x000130CB,
    0x00013750, 0x0001CB8D,
    //x19+x18+x16+x13+x12+x10+x9+x6+x5+x4+x2+1
    // 0b1010111001101100101
    (reverse32(0xD3675) >> 13),
    //x19+x16+x11+x10+x5+x3+x2+1
    reverse32(0x90C2D) >> 13,
    reverse32(0xC058B) >> 13, reverse32(0xB85F3) >> 13,
    reverse32(0x937B3) >> 13, reverse32(0xF4607) >> 13
};


void print_binary(uint16_t v) {
    for(int k = 0;k < 16;k++) {
        bool b = (v >> (16-k-1)) & 1;
        printf("%d", b );    
    }
    printf("\n");
}

int popcnt(unsigned x)
{
    int c;
    for (c = 0; x != 0; x >>= 1)
        if (x & 1)
            c++;
    return c;
}

bool lsfr_iterate(uint32_t& state, uint32_t poly) {
    int deg = (int)floor(log((double)poly)/log(2.));
    uint16_t b = popcnt(state & poly) & 1;
    state = (state << 1) | b;
    return b;
}

int main()
{
    for(int i = 0;i < sizeof(polys)/sizeof(polys[0])/2;i++) {
        for(int j = 0;j < 2;j++) {
            auto v = polys[i * 2 + j];
            int tap_count = 0;
            printf("%8d 0x%08x (%d) 0b", v, v, (int)floor(log((double)v)/log(2.)));
            
            for(int k = 0;k < 20;k++) {
                bool b = (v >> (20-k-1)) & 1;
                printf("%d", b );    
                tap_count += b;
            }
            
            printf(" (%2d) ", tap_count);
            
            
            if(j == 0)
                printf(", "); 
        }
        printf("\n");
    }
    
    
    for(int j = 0;j < sizeof(polys)/sizeof(polys[0]);j++) {
        // 0110 0111 1000 1111 1101 1000 0010 11__
        // 0000 0011 1100 1010 1000 0000 0100 10__
        //uint32_t state = (0b0000001111001010);
        uint32_t state = (0b0110011110001111);
        printf("%x ", polys[j]);
        for(int i = 0;i < 60;i++) {
            if(i % 4 == 0) printf("");
         bool b = lsfr_iterate(state, polys[j]);
         printf("%d,", b); 
         
        }
        printf("%08x", state);
        printf("\n");
    }
    
    return 0;
}

@jdavidberger
Copy link
Author

0110 0111 1000 1111 1101 1000 0010 11__
0000 0011 1100 1010 1000 0000 0100 10__

Were observed from lighthouse_console with dump/sample turned on when LH was in mode 1. The polynomial of:
x^17 + x^13 + x^12 + x^10 + x^7 + x^4 + x^2 + x^1 + 1 matches 0x0001D258 and predicts the remainder of the sequence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment