-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathConstants.h
134 lines (110 loc) · 5.62 KB
/
Constants.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// Copyright 2004-2010, Thomas C. McDermott, N5EG
// This file is part of VNAR - the Vector Network Analyzer program.
//
// VNAR is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// VNAR is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VNAR, if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#pragma once
// Constants.h
//
// 07-25-04 TCM Original
// 05-10-05 TCM Delete VNA_XTAL_CONST and refereces to it. This is now
// handled by an Internal Crystal Calibration function.
// 03-19-06 TCM Add constants for the S21 measurement level offsets for
// Mid and Lo levels.
// 02-27-07 TCM Add constants for ExpectedValue mode, redefine glitch
// constants.
// 05-26-07 TCM Add constants for epsilon (allowed error before applying median
// filter).
// 06-08-2007 TCM Add constants for phase lead caused by 2 highpass poles in the
// modamp AC coupling circuit.
// 09-30-2007 TCM Add TargetPhLoMAG constant - to measure S21 phase with reduced generator
// output level. This avoids rx preamp overload of the phase detector on
// 'hot' rx signals.
//
// Constants for the VNA instrument + others.
//
#include <math.h>
///\def Converts radians to degrees
#define RAD2DEGR 180.0/Math::PI
///\def Converts degrees to radians
#define DEGR2RAD Math::PI/180.0
// Constants related to the actual numeric VNA instrument readings
// These are used until the Detector Calibration is run or loaded from a file.
//#define MAXREFLMAGNITUDE 2100 // temporary until Detector Calibration is run,
// observed on S/N 1
#define MAXTRANMAGNITUDE 3800 // temporary until Detector Calibration is run,
// observed on S/N 1
// Constants related to calibration grid (both instrument calibration and fixture calibration)
///\def Maximum Calibration Frequency
#define MAXCALFREQ 300000000
///\def Minimum Calibration Frequency
#define MINCALFREQ 400000
///\def Number of Calibration Points
#define NUMCALPTS 1024.0
///\def Size of Phase Calibration Grid
#define PHASECALGRIDSIZE 1024
///\def Error size for double-precision rank-order median filter
#define EPSILON 0.005
// def Maximum DDS output level DAC control word
//#define MAX_DDS_LEVEL 0xFFF // Multiplier for DDS Amplitude, unsigned 12-bit int. Maximum = 0xFFF
// Set the 0 db level to 2.5 dB below the maximum possible level
//#define MAX_DDS_LEVEL 0xC00 // Multiplier for DDS Amplitude, unsigned 12-bit int. Maximum = 0xFFF
///\ DDS Maximum Level Control
// Set the ~0 db level to 3 dB below the maximum possible level
#define MAX_DDS_LEVEL 0xB4F // Multiplier for DDS Amplitude, unsigned 12-bit int. Maximum = 0xFFF
// this constant is not dependent on MAX_DDS_LEVEL since it references the Q-DAC
#define QDAC_ZERODBM 0xAAA //0xAAA // 0 dbm for Q-DAC ref level
//0xFFF // about +3.5 dB too hot for Q-DAC
// constants used by Time Domain display
//#define TDRTIMETICK 4.167 // 4.167 nanoseconds per TDR time tick
#define TDRTIMETICK ((1.0/(double)VNA->GetMaxFreq())*1e9)
#define METERSPERNSEC 0.2998 // meters per nanosecond - free space
#define FEETPERNSEC 0.9836 // feet per nanosecond - free space
// constants that set the Mid and Lo levels for the target to measure S21 magnitude
#define TARGETMIDMAG 17
#define TARGETLOMAG 34
// constant - sets Lo output level for the target to measure S21 phase with non-overloading signals
#define TARGETPHLOMAG 20
// constant: sample-to-sample deviation that constitutes a glitch (bad reading)
#define GLITCHSIZE 30
// Calling ExpectedValue with mode==true tests for phase detector saturation
#define PHASEMODE true
#define AMPLMODE false
// Should normally only define one of either FASTGLITCH or SLOWGLITCH as true
//#define FASTGLITCH // use FAST glitch correction algorithm
//#define SLOWGLITCH // use SLOW glitch correction algorithm
/// Array index enumeration for ReflectionMeasurements (in InstrumentCal and DisplayRoutines)
enum ReflMeas { MagQ, PhaseI, PhaseQ }; ///< Array index for storing reflection measurements
#define HIGHPASSPOLE (0) // Phase lead caused by 2 highpass
// poles of AC coupling capacitors in the ModAmp.
// 6.2 degrees at 200 Khz.
// #define SHORT_RANGE 3800
#define SHORT_RANGE 32000
#define MAX_PHASE 181.0
#define MIN_PHASE -181.0
#define NormalizePhase(X) { while ((X) > 180.0) (X) -= 360.; while ((X) < -180.0) (X) += 360.0; }
#define PHASE2SHORT(X) (short)(((X) - MIN_PHASE) * SHORT_RANGE / (MAX_PHASE - MIN_PHASE))
#define SHORT2PHASE(X) (((double)(X) * (MAX_PHASE - MIN_PHASE) / SHORT_RANGE ) + MIN_PHASE )
#define MAX_DB +30.0
#define MIN_DB -180.0
#define DB2SHORT(X) (short)((X)>MIN_DB?((X) - MIN_DB) * SHORT_RANGE / (MAX_DB - MIN_DB):0)
#define SHORT2DB(X) (((double)(X) * (MAX_DB - MIN_DB) / SHORT_RANGE ) + MIN_DB )
//#define MAXSAMPLEVALUE ((int)((((unsigned long)1)<<(VALIDSAMPLEBITS - 1))-8))
#define MAXSAMPLEVALUE 0.9999999
// #define MAXSAMPLEVALUE ((int)((((unsigned long)1)<<(15))-8))
#define todb(X) (20.0f * log10 ((float(X)/(float)MAXSAMPLEVALUE)))
#define toLin(X) ( pow((float)10,(float)(X/20.0)) * (float) MAXSAMPLEVALUE)
#define CALSUM 7 //number of measurements to average for calibration