summaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/lib/vita/generate_bits.cpp
blob: f5ea60fc194f02841c0997d652d5f11c981dd5bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//PURPOSE: C test bench for floating point converter IQ_to_FLOAT

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <cmath>
#include "math.h"
#include <iomanip>

using namespace std;
//INITIAL TESTING PURPOSES: Use if you want to print individual bits	
	template <typename T>

	void print_bits(T n) {
		T mask = 1 << (sizeof(T)*8-1);
		while (mask) {
			cout << ((mask & n) ? "1" : "0");
			mask >>= 1;
		}
	cout << endl;
	}

	int main()	{
		

		FILE *convFile;
		FILE *newFile;


		
		


		convFile = fopen("iq_to_float_input.txt", "w");
		newFile =  fopen("iq_to_float_output.txt", "w");
        //iterate through test cases
    
        for (signed int i = -0x8000; i <= 0x7FFF; i++)   {

		float end = float(i*exp2(-15));
        

		unsigned int n = *(reinterpret_cast<unsigned int*>(&end));

        //IN CASE YOU NEED TO LOOK AT SPECIFIC EXPONENT, FRAC, ETC VALUES
        //ACTIVATE BY UNCOMMENTING
        /*

		unsigned int signed_bit = n>>31;
		
		unsigned int exp =  ((n>>23) &0xFF);
		
		unsigned int frac =  (n &0x7FFFFF);

		cout << "end: " << end << endl;
		cout << "n: " << hex << n << endl;



		cout << "signed bit:" << hex << signed_bit << endl;
		cout << "exp: " << hex <<  exp << endl;
		cout << "fract: " << hex << frac << endl;

		float f = *(float*)&n;
		cout << "f" << f << endl;
*/		
		
	//	print_bits<unsigned short>(start);
	//	print_bits<unsigned int>(n);
	    unsigned int something = i;
        something &= 0xFFFF;

		fprintf(convFile, "%x\n",something);
		fprintf(newFile, "%x\n",n);
        }

	fclose(convFile);
	fclose(newFile);


	return 0;
}