SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
hbfilterchainconverter.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QString>
20 #include "hbfilterchainconverter.h"
21 
22 double HBFilterChainConverter::convertToIndexes(unsigned int log2, unsigned int chainHash, std::vector<unsigned int>& chainIndexes)
23 {
24  chainIndexes.clear();
25 
26  if (log2 == 0) {
27  return 0.0;
28  }
29 
30  unsigned int s = 1;
31  unsigned int u = chainHash;
32 
33  for (unsigned int i = 0; i < log2; i++) {
34  s *= 3;
35  }
36 
37  u %= s; // scale
38  unsigned int ix = log2;
39  double shift = 0.0;
40  double shift_stage = 1.0 / (1<<(log2+1));
41 
42  // base3 conversion
43  do
44  {
45  int r = u % 3;
46  chainIndexes.push_back(r);
47  shift += (r-1)*shift_stage;
48  shift_stage *= 2;
49  u /= 3;
50  ix--;
51  } while (u);
52 
53  // continue shift with leading zeroes. ix has the number of leading zeroes.
54  for (unsigned int i = 0; i < ix; i++)
55  {
56  chainIndexes.push_back(0);
57  shift -= shift_stage;
58  shift_stage *= 2;
59  }
60 
61  return shift;
62 }
63 
64 double HBFilterChainConverter::convertToString(unsigned int log2, unsigned int chainHash, QString& chainString)
65 {
66  if (log2 == 0)
67  {
68  chainString = "C";
69  return 0.0;
70  }
71 
72  unsigned int s = 1;
73  unsigned int u = chainHash;
74  chainString = "";
75 
76  for (unsigned int i = 0; i < log2; i++) {
77  s *= 3;
78  }
79 
80  u %= s; // scale
81  unsigned int ix = log2;
82  double shift = 0.0;
83  double shift_stage = 1.0 / (1<<(log2+1));
84 
85  // base3 conversion
86  do
87  {
88  int r = u % 3;
89 
90  if (r == 0) {
91  chainString = "L" + chainString;
92  } else if (r == 1) {
93  chainString = "C" + chainString;
94  } else if (r == 2) {
95  chainString = "H" + chainString;
96  }
97 
98  shift += (r-1)*shift_stage;
99  shift_stage *= 2;
100  u /= 3;
101  ix--;
102  } while (u);
103 
104  // continue shift with leading zeroes. ix has the number of leading zeroes.
105  for (unsigned int i = 0; i < ix; i++)
106  {
107  chainString = "L" + chainString;
108  shift -= shift_stage;
109  shift_stage *= 2;
110  }
111 
112  return shift;
113 }
114 
115 double HBFilterChainConverter::getShiftFactor(unsigned int log2, unsigned int chainHash)
116 {
117  if (log2 == 0)
118  {
119  return 0.0;
120  }
121 
122  unsigned int s = 1;
123  unsigned int u = chainHash;
124 
125  for (unsigned int i = 0; i < log2; i++) {
126  s *= 3;
127  }
128 
129  u %= s; // scale
130  unsigned int ix = log2;
131  double shift = 0.0;
132  double shift_stage = 1.0 / (1<<(log2+1));
133 
134  // base3 conversion
135  do
136  {
137  int r = u % 3;
138  shift += (r-1)*shift_stage;
139  shift_stage *= 2;
140  u /= 3;
141  ix--;
142  } while (u);
143 
144  // continue shift with leading zeroes. ix has the number of leading zeroes.
145  for (unsigned int i = 0; i < ix; i++)
146  {
147  shift -= shift_stage;
148  shift_stage *= 2;
149  }
150 
151  return shift;
152 }
static double convertToIndexes(unsigned int log2, unsigned int chainHash, std::vector< unsigned int > &chainIndexes)
static double convertToString(unsigned int log2, unsigned int chainHash, QString &chainString)
int32_t i
Definition: decimators.h:244
static double getShiftFactor(unsigned int log2, unsigned int chainHash)