Making a PN9 Scrambler for CC1110 in GNU Radio - gnuradio

I am trying to implement the data whitening used by the CC1110 radio IC in GNU radio companion, as described in this app note.
It looks like it uses a LFSR with PN9 sequence (with x^9 + x^5 + 1 polynomial) and a seed value of 0x1FF. I think the "Scrambler" block in GNU radio could handle this just fine, but I'm unsure that I'm using the correct parameters (I'm modeling these parameters off of this post).
Mask: 0x11
Seed Value: 0x1FF
Length: 8
Here is my flowgraph:
flowgraph
I have an input binary file with the following contents:
$ xxd bytes.bin
00000000: 0a00 0102 ....
This is the example data in the app note linked above. The output file contents are:
$ xxd bytes_out.bin
00000000: 0101 0101 ....
The example in the app note (page 5) has a different result:
Data: / 0000 1010 / 0000 0000 / 0000 0001 / 0000 0010 / …
PN9: / 1111 1111 / 1110 0001 / 0001 1101 / 1001 1010/ …
Result: / 1111 0101 / 1110 0001 / 0001 1100 / 1001 1000 /…
I am new to GNU radio and DSP so any help on this would be much appreciated. I think I might just be using the wrong Scrambler block parameters, but there might be a fundamental misconception I have with GNU radio. Thanks!

Here is a C++ code snippet to generate that PN9 sequence, that you can run easily with an online compiler:
#include <iostream>
#include <bitset>
using namespace std;
int main() {
bitset<9> lfsr;
lfsr.flip();//Seed: all 1s
const unsigned int period = (1 << 9) - 1;
for(unsigned int i = 0; i < period; ++i)
{
if(i%8 == 0)
{
cout << lfsr[7] << lfsr[6] << lfsr[5] << lfsr[4] << " " << lfsr[3] << lfsr[2] << lfsr[1] << lfsr[0] << " / ";
}
const bool newBit = lfsr[0] ^ lfsr[5];
lfsr >>= 1;
lfsr[8] = newBit;
}
cout << endl;
}
Output is:
1111 1111 / 1110 0001 / 0001 1101 / 1001 1010 / 1110 1101 / 1000 0101 / 0011 0011 / 0010 0100 / 1110 1010 / 0111 1010 / 1101 0010 / 0011 1001 / 0111 0000 / 1001 0111 / 0101 0111 / 0000 1010 / 0101 0100 / 0111 1101 / 0010 1101 / 1101 1000 / 0110 1101 / 0000 1101 / 1011 1010 / 1000 1111 / 0110 0111 / 0101 1001 / 1100 0111 / 1010 0010 / 1011 1111 / 0011 0100 / 1100 1010 / 0001 1000 / 0011 0000 / 0101 0011 / 1001 0011 / 1101 1111 / 1001 0010 / 1110 1100 / 1010 0111 / 0001 0101 / 1000 1010 / 1101 1100 / 1111 0100 / 1000 0110 / 0101 0101 / 0100 1110 / 0001 1000 / 0010 0001 / 0100 0000 / 1100 0100 / 1100 0100 / 1101 0101 / 1100 0110 / 1001 0001 / 1000 1010 / 1100 1101 / 1110 0111 / 1101 0001 / 0100 1110 / 0000 1001 / 0011 0010 / 0001 0111 / 1101 1111 / 1000 0011 /

Related

Trying to understand octal/hexa

deleted due to unclear question
Why do you need octal at all? fec0ded is obviously hexadecimal and 8 is either hex or decimal (actually, doesn't matter - it's still the same 8)
Calculations are done as follows:
FEC0DED xor 8 (hex)
=
1111 1110 1100 0000 1101 1110 1101 xor 1000 (bin)
=
1111 1110 1100 0000 1101 1110 0101 (bin)
=
FEC0DE5 (hex)
I.e. you flip 4th least significant bit.

Getting bits from a packed word

I have a 16 bit word that could be anywhere from 1 to 16 data values. They are decoded by knowing the MSB and lsb of the 16 bit word and grabbing those bits.
I'm using VB and I just don't know how to do this.
Example
I have a word that is
&HA6F2
1010 0100 1111 0010
I know my data is LSB 3 to MSB 9. Bit ordering is left to right
So the data is 010011
How do I get this in VB code? I want to work in bytes because after I get the packed bits then I have to do type casts on it (signed_fixed, integer, 2's complement, etc)
Thanks
You should use mask (bitwise AND, see And keyword). And also probably bitwise-right-shift (see >> operator)
Conceptually:
1010 0100 1111 0010 '= the data
0001 1111 1100 0000 '= 1FC0 the mask
-------------------- And
0000 0100 1100 0000 '= 04C0
-------------------- >> 6
0000 0000 0001 0011 '= 0013 now your value is in the right most
In the code
Dim newData As Integer = (rawData And &H1FC0) >> 6

What does the & symbol mean in this TSQL query?

I have been working on some reports and recently found a small guide for the system I have been querying against. Part of the syntax it offers up is like the following:
... "WHERE [FIELD] & [VALUE] = [VALUE]"
i.e.: ... "WHERE flags & 16 = 16"
I am just curious as to what this syntax is meaning... I get something like WHERE flags = 16, but not the '&16 = 16' part. Any clarification?
The article referenced: http://rightfaxapi.com/advanced-sql-for-manipulating-faxes/
Thank you,
Wes
The & is doing a bit-wise "and". So, it is "1" only when both bits are 1. The logic overall is checking that all the bits in value are set in field.
As an example, consider that value is:
0000 0101
Then if field is
1111 1111
The & is:
0000 0101
(The 1s are only where both are 1.)
And this is the same as value. So, this passes the condition.
Now if field is:
0001 1110
Then the & is:
0000 0100
And this differs from value, so it does not pass the condition.
& is bitwise AND. In your example, your mask is 16(0x0010, binary 0000 0000 0001 0000 ). The reslt of the AND operation will be either 0 (all bits in the mask are not set) or the mask value (all bit in the mask ARE set). So your where A&16 = 16 expression is testing to see if bit 5 of the integer value, counting from the right, is set.
Examples:
48 & 16 = 16 is TRUE:
48 (binary: 0000 0000 0011 0000)
AND 16 (binary: 0000 0000 0001 0000)
-- -----------------------------
16 (binary: 0000 0000 0001 0000)
33 & 16 = 16 is FALSE:
33 (binary: 0000 0000 0010 0001)
AND 16 (binary: 0000 0000 0001 0000)
-- -----------------------------
0 (binary: 0000 0000 0000 0000)
Easy!

Binary Numbers what is the solution V2 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Does anyone know how I can solve this problem ? any help would be great...... i cant seem to get my head around it.
As you know Binary can only be either 1 or 0
Say you had a 8 digit Binary number like a byte >>>>>> 0001 1000
Im trying to figure out an equation or what would be the maximum amount of combinations you could get from an 8 digit number
What i mean is.... say you had a two digit binary number,the maximum Bnary combinations that you could have are either
00
01
10
11
Therefore total maximum combinations from a 2 digit Binary number = 4
Example 2
If you had a 3 digit number , maximum Binary Combinations would be
000
001
010
100
101
111
110
011
Therefore total maximum Binary combinations from a 3 digit number = 8
Example 3
If it were a 4 digit number, maximum binary combinations that you could have are either
0000
0001
0010
0100
1000
0111
0110
1111
1110
1101
1011
1001 Total maximum combination = 12
I Recently Asked this Question and it was answered thank you manu-fatto and zgnilec they were kind enough to let me know it was a simple equation the answer/equation is 2^digit size.
I guess my next problem is how do i write a small program that can show these combinations in Xcode or NSLog. I'm good with objective C an output I can view like NSLog would be great.
All I know is it would look something like:
int DigitSize=8
int CombinationTotal = 2^8
CombinationSize = NSMutableArray ArraywithCapacity 8;
Output
NSString Combination1 =#"0000 0000";
NSString Combination2 =#"0000 0001";
NSString Combination3 =#"0000 0010";
Nslog #"combination 1 = %# ,Combination1";
Nslog #"combination 2 = %# ,Combination2";
Nslog #"combination 3 = %# ,Combination3";
……
Nslog #"combination 256 = ???? ???? ";
Sorry for the vague language I only started learning programming 3 months ago and I still have a lot of tutorials to go through.
**Im trying to build a data compression algorithm...
basically data compression is about reducing the number of bits ... the lesser the bits the smaller a file is
ie
A file with 700bits is smaller than a file with 900bits
8 bits = 1 byte
1024bytes = 1kb
1024kb = 1 mb
i donno if its even possible but i just thought what if you had an algorithm that could read 1024 bits at a time ...with the equation thats = 2^1024 = math error :( == total number of bit combinations possible
Once you have the total number of combinations you set each combination to a symbol like eg 000101010010101011001011011010101010140010101101000000001110100101100001010100000......0011010 = symbol #
So from now on whenever the computer sees the symbol # it recognises it is equal to the binary number 000101010010101011001011011010101010140010101101000000001110100101100001010100000......0011010
to better understand it ...just think of number plates on a car/vehicle, they are only a few characters but wen you punch them into police database or any car data base more information comes out its the same principle....
basically the symbols are a key to more data
i dont know if it make sense but... in theory if you could read 8388608 bits at a time
8388608 bits = 1megabyte ......
ten symbols could mean 10mb...you could create digital media 2d barcodes
its just a thought i had watching starGate lol :)**
2 to the power of 8, where 8 is number of digits.
Edit- only read first question :)
create function that will display an integer as binary
for (i = 0; i < pow(2,n), i++)
{
displayBits(i);
}
A quick implementation
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSUInteger length = 8; // number of digits
NSUInteger n = pow(2, length); // number of possible values
for (int i = 0; i < n; i++) {
NSString *repr = #"" ;
for (int j = 0; j < length; ++j) {
if([repr length] % 5 == 0)
repr = [#" " stringByAppendingString:repr]; // add a blank after evey 4th digit
int x =( i >> j) &1;
repr = [[NSString stringWithFormat:#"%u",x] stringByAppendingString:repr];
}
NSLog(#"%#", repr);
}
}
return 0;
}
Output
0000 0000
0000 0001
0000 0010
0000 0011
0000 0100
0000 0101
0000 0110
0000 0111
0000 1000
0000 1001
0000 1010
0000 1011
0000 1100
0000 1101
0000 1110
0000 1111
0001 0000
…
1110 1100
1110 1101
1110 1110
1110 1111
1111 0000
1111 0001
1111 0010
1111 0011
1111 0100
1111 0101
1111 0110
1111 0111
1111 1000
1111 1001
1111 1010
1111 1011
1111 1100
1111 1101
1111 1110
1111 1111
The core of this program is this:
for (int i = 0; i < n; i++) {
//…
for (int j = 0; j < length; ++j) {
int x =( i >> j) &1;
//…
}
}
this will run for i =0 bis (2^n)-1 and in the inner for-loop for every j of the n bits, to check, if the least bit is 1, and append it to the representation string.
As you are a beginner, you probably dont know, what this means: int x =( i >> j) & 1;
>> shifts the bits of the left side integer by as many decimal places as the right side defines. and & 1 performs a bit wise addition
so for i == 3 and n == 8
3 as binary string representation
j = 0: 00000011 >> 0 -> 0000 0011
&0000 0001
-----------
00000 0001 -> 1 repr = 1
j = 1: 00000011 >> 1 -> 000 0001
&0000 0001
-----------
00000 0001 -> 1 repr = 11
j = 2: 00000011 >> 2 -> 00 0000
&0000 0001
-----------
00000 0000 -> 0 repr = 011
j = 3: 00000011 >> 3 -> 0 0000
&0000 0001
-----------
00000 0000 -> 0 repr = 0011
(the same till j = 7) repr = 0000 0011

Awk - how to print the number?

I have a test file:
0000 850 1300 Pump 4112 893 2400 Installing sleeve 5910 890 2202 Installing tool
Testing crankcase and Protecting oil seal Installing crankshaft
carburetor for leaks (starter side) 5910 890 2208 Installing tool, 8
0000 855 8106 Sealing plate 4112 893 2401 Press sleeve Installing hookless
Sealing exhaust port Installing oil seal snap rings in piston
0000 855 9200 Nipple (clutch side) 5910 890 2301 Screwdriver, T20
Testing carburetor for 4118 890 6400 Setting gauge Separating handle
leaks Setting air gap moldings
0000 890 1701 Testing tool kit between ignition 5910 890 2400 Screwdriver, T27x150
0000 893 2600 Clamping strap module and flywheel For all IS screw
I want to print only:
0000 850 1300
4112 893 2400
5910 890 2202
5910 890 2208
0000 855 8106
.
.
.
Thank you for your help.
EDIT:
The numbers in the file are in different places. The numbers are randomly placed in the input file. Each number is the format:
xxxx xxx xxxx
EDIT-1:
I tried two ways, but it does not work on mawk:
pic#pic:~/Pulpit$ mawk --traditional -f script.awk infile
mawk: not an option: --traditional
pic#pic:~/Pulpit$ mawk -f script.awk infile
pic#pic:~/Pulpit$
One way with grep (if your version supports the -P flag):
grep -oP "[0-9]{4} [0-9]{3} [0-9]{4}" file.txt
Output:
0000 850 1300
4112 893 2400
5910 890 2202
5910 890 2208
0000 855 8106
4112 893 2401
0000 855 9200
5910 890 2301
4118 890 6400
0000 890 1701
5910 890 2400
0000 893 2600
HTH
This is shorter and looks for the specific pattern:
mawk '
BEGIN {
d = "[0-9]"
};
{
offset = 1;
while (RSTART + RLENGTH < length($0)) {
if (! match(substr($0, offset), d d d d " " d d d " " d d d d)) {
next
};
print substr($0, RSTART+offset - 1, RLENGTH);
offset = RSTART + RLENGTH + offset
}
}' inputfile
One way using awk:
Assuming infile has the content provided in your question:
Content of script.awk:
{
## Traverse all words of the line but last two. I assume to print three
## consecutive number fields.
i = 1
while ( i <= NF - 3 ) {
## Set current word position in line.
j = i
## Get next word while current one is a digit, and save it to print later.
while ( $j ~ /^[[:digit:]]+$/ ) {
value[j] = $j
++j
}
## If found three consecutive number fields, print them and update counter of
## words in the line.
if ( i + 3 == j ) {
for ( key in value ) {
printf "%s ", value[key]
}
printf ORS
i += 3
}
else {
## Failed the search, go to next field and try again.
++i
}
## Delete array where I save numbers.
# delete value <--- Commented for compatibility with older versions.
for ( key in value ) {
delete value[key]
}
}
}
Run it like:
awk -f script.awk infile
With following output:
0000 850 1300
4112 893 2400
5910 890 2202
5910 890 2208
0000 855 8106
4112 893 2401
0000 855 9200
5910 890 2301
4118 890 6400
0000 890 1701
5910 890 2400
0000 893 2600