fix: remove zeromean

chg: cleanup
This commit is contained in:
Chris 2018-09-09 19:54:22 +02:00
commit bc0ffa9e51
2 changed files with 45 additions and 45 deletions

View file

@ -123,7 +123,6 @@ void zeromean(uint8_t* data, size_t size) {
bool isNoise_int(int *bits, uint32_t size) { bool isNoise_int(int *bits, uint32_t size) {
resetSignal(); resetSignal();
if ( bits == NULL || size < 100 ) return true; if ( bits == NULL || size < 100 ) return true;
//zeromean(bits, size);
int32_t sum = 0; int32_t sum = 0;
for ( size_t i = 0; i < size; i++) { for ( size_t i = 0; i < size; i++) {
@ -148,7 +147,6 @@ bool isNoise_int(int *bits, uint32_t size) {
bool isNoise(uint8_t *bits, uint32_t size) { bool isNoise(uint8_t *bits, uint32_t size) {
resetSignal(); resetSignal();
if ( bits == NULL || size < 100 ) return true; if ( bits == NULL || size < 100 ) return true;
zeromean(bits, size);
uint32_t sum = 0; uint32_t sum = 0;
for ( uint32_t i = 0; i < size; i++) { for ( uint32_t i = 0; i < size; i++) {
@ -835,7 +833,7 @@ int DetectNRZClock(uint8_t *dest, size_t size, int clock, size_t *clockStartIdx)
//countFC is to detect the field clock lengths. //countFC is to detect the field clock lengths.
//counts and returns the 2 most common wave lengths //counts and returns the 2 most common wave lengths
//mainly used for FSK field clock detection //mainly used for FSK field clock detection
uint16_t countFC(uint8_t *bits, size_t size, uint8_t fskAdj) { uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj) {
uint8_t fcLens[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; uint8_t fcLens[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint16_t fcCnts[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; uint16_t fcCnts[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint8_t fcLensFnd = 0; uint8_t fcLensFnd = 0;
@ -856,15 +854,16 @@ uint16_t countFC(uint8_t *bits, size_t size, uint8_t fskAdj) {
if (fskAdj){ if (fskAdj){
//if we had 5 and now have 9 then go back to 8 (for when we get a fc 9 instead of an 8) //if we had 5 and now have 9 then go back to 8 (for when we get a fc 9 instead of an 8)
if (lastFCcnt == 5 && fcCounter == 9) fcCounter--; if (lastFCcnt == 5 && fcCounter == 9) fcCounter--;
//if fc=9 or 4 add one (for when we get a fc 9 instead of 10 or a 4 instead of a 5) //if fc=9 or 4 add one (for when we get a fc 9 instead of 10 or a 4 instead of a 5)
if ((fcCounter == 9) || fcCounter == 4) fcCounter++; if ((fcCounter == 9) || fcCounter == 4) fcCounter++;
// save last field clock count (fc/xx) // save last field clock count (fc/xx)
lastFCcnt = fcCounter; lastFCcnt = fcCounter;
} }
// find which fcLens to save it to: // find which fcLens to save it to:
for (int ii=0; ii<15; ii++){ for (int m=0; m<15; m++){
if (fcLens[ii]==fcCounter){ if (fcLens[m] == fcCounter){
fcCnts[ii]++; fcCnts[m]++;
fcCounter = 0; fcCounter = 0;
break; break;
} }
@ -900,6 +899,7 @@ uint16_t countFC(uint8_t *bits, size_t size, uint8_t fskAdj) {
if (g_debugMode == 2) prnt("DEBUG countfc: FC %u, Cnt %u, best fc: %u, best2 fc: %u", fcLens[i], fcCnts[i], fcLens[best1], fcLens[best2]); if (g_debugMode == 2) prnt("DEBUG countfc: FC %u, Cnt %u, best fc: %u, best2 fc: %u", fcLens[i], fcCnts[i], fcLens[best1], fcLens[best2]);
if (fcLens[i] == 0) break; if (fcLens[i] == 0) break;
} }
if (fcLens[best1] == 0) return 0; if (fcLens[best1] == 0) return 0;
uint8_t fcH = 0, fcL = 0; uint8_t fcH = 0, fcL = 0;
if (fcLens[best1] > fcLens[best2]){ if (fcLens[best1] > fcLens[best2]){
@ -1111,22 +1111,22 @@ uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow,
// loop to find the highest clock that has a remainder less than the tolerance // loop to find the highest clock that has a remainder less than the tolerance
// compare samples counted divided by // compare samples counted divided by
// test 128 down to 32 (shouldn't be possible to have fc/10 & fc/8 and rf/16 or less) // test 128 down to 32 (shouldn't be possible to have fc/10 & fc/8 and rf/16 or less)
int ii=7; int m = 7;
for (; ii>=2; ii--){ for (; m >= 2; m--){
if (rfLens[rfHighest] % clk[ii] < tol1 || rfLens[rfHighest] % clk[ii] > clk[ii]-tol1){ if (rfLens[rfHighest] % clk[m] < tol1 || rfLens[rfHighest] % clk[m] > clk[m]-tol1){
if (rfLens[rfHighest2] % clk[ii] < tol1 || rfLens[rfHighest2] % clk[ii] > clk[ii]-tol1){ if (rfLens[rfHighest2] % clk[m] < tol1 || rfLens[rfHighest2] % clk[m] > clk[m]-tol1){
if (rfLens[rfHighest3] % clk[ii] < tol1 || rfLens[rfHighest3] % clk[ii] > clk[ii]-tol1){ if (rfLens[rfHighest3] % clk[m] < tol1 || rfLens[rfHighest3] % clk[m] > clk[m]-tol1){
if (g_debugMode == 2) if (g_debugMode == 2)
prnt("DEBUG FSK: clk %d divides into the 3 most rf values within tolerance",clk[ii]); prnt("DEBUG FSK: clk %d divides into the 3 most rf values within tolerance", clk[m]);
break; break;
} }
} }
} }
} }
if (ii < 2) return 0; // oops we went too far if (m < 2) return 0; // oops we went too far
return clk[ii]; return clk[m];
} }

View file

@ -49,7 +49,7 @@ extern int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int i
extern uint8_t bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest); extern uint8_t bits_to_array(const uint8_t *bits, size_t size, uint8_t *dest);
extern uint32_t bytebits_to_byte(uint8_t *src, size_t numbits); extern uint32_t bytebits_to_byte(uint8_t *src, size_t numbits);
extern uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits); extern uint32_t bytebits_to_byteLSBF(uint8_t *src, size_t numbits);
extern uint16_t countFC(uint8_t *bits, size_t size, uint8_t fskAdj); extern uint16_t countFC(uint8_t *bits, size_t size, bool fskAdj);
extern int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr); extern int DetectASKClock(uint8_t *dest, size_t size, int *clock, int maxErr);
extern bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low); extern bool DetectCleanAskWave(uint8_t *dest, size_t size, uint8_t high, uint8_t low);
extern uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge); extern uint8_t detectFSKClk(uint8_t *bits, size_t size, uint8_t fcHigh, uint8_t fcLow, int *firstClockEdge);