📄 displayroutines.h
字号:
//
// Copyright 2004 - 2006 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
// Utility routines to convert VNA measurements into other
// useful types and coordinates.
//
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::IO;
using namespace System::Windows::Forms;
// Convert Magnitude to rectangular Y display coordinate
int ToDisplayRectMag(double magnitude, int height, int dbScaleFactor, int refLevel);
// Convert Phase to rectangular Y display coordinate
int ToDisplayRectPhs(double phase, int height);
// Convert Group Delay to rectangular Y display coordinate
int ToDisplayRectGD(double groupdelay, int height, int scaleFactor);
// Convert Magnitude and Phase to polar (X,Y) display coordinates
void ToDisplayPolar(double magnitude, double phase, int polarRad, int xoffset, int yoffset, int& X, int& Y);
/// Frequency Grid Class
__gc public class FrequencyGrid
{
private:
int FrequencyIndex __gc[]; ///< Grid of frequencies to measure
int startFreq; ///< Starting (lowest) Frequency of grid
int stopFreq; ///< Stopping (highest) Frequency of grid
int indexer; ///< internal variable to index through grid
int points; ///< Number of points in the frequency grid
double delta; ///< Frequency separation between points in the grid
int ferror; ///< Frequency error of internal crystal at 100 Mhz (from calibration)
public:
FrequencyGrid(int numPoints); // Constructor, allocate array
void SetStartF(int start); // Set start frequency of grid
void SetStopF(int stop); // Set stop frequency of grid
int Frequency(int gridpoint); // convert gridpoint to it's frequency
long long int DDS(int Frequency); // Derive DDS divisor value from Frequency
int GridPoint(int Frequency); // convert Frequency to gridpoint
__property int get_Points(); // get number of points in grid
__property int get_StartF(); // get start frequency of grid
__property int get_StopF(); // get stop frequency of grid
__property int get_Ferror(); // get Frequency error
__property void set_Ferror(int); // set Frequency error
private:
void Build(void);
};
/// Analog Devices AD8302 device-dependent constants
__gc public class Detector
{
public:
int lowerPhase; ///< lower I/Q phase crossover points
int upperPhase; ///< upper I/Q phase crossover points
int centerPhase; ///< phase midpoint
int maxMagnitude; ///< maximum magnitude reading
float unitsPerdB; ///< magnitude ADC counts per dB. (~57.0)
int cxFreqIdx; ///< frequency index of 360 degrees
int centerQindex, centerQ2index;
int centerIindex, centerI2index, centerI3index;
float quadratureError; ///< I-Q phase quadrature error in degrees
float phaseSlope; ///< degrees phase per unit phase count
double pherror __gc[]; ///< phase error for each degree
int MagTable __gc[ , ]; ///< refl magnitude raw data table
double m __gc[]; ///< y = mx + b from linear regression, by frequency
double b __gc[]; ///< y = mx + b from linear regression, by frequency
double r __gc[]; ///< 'r' is the correlation coefficient for the regression, by frequency
double flat __gc[]; ///< ADC count where amp detector bottoms out
static const int t1 = 110; // twiddle factors for detector floor correction
static const int t2 = 110;
double CouplerPhase; // Angle of Coupler V/I ripple - NEW 12-26-2005
double CouplerMagnitude; // Magnitude of Coupler V/I ripple - NEW 12-26-2005
bool calibrated; ///< true if values have been calibrated
int DirMag __gc[]; // New 10-17-2005 Directivity Cal
int DirIphs __gc[]; // Directivity cal raw data
int DirQphs __gc[]; // Directivity cal raw data
bool DirCalibrated; ///< true if Directivity Calibration has been run
Detector(void); // Constructor, allocate default values
bool PhaseCal(int Iphase __gc[], int Qphase __gc[]); // construct phase points from raw data
bool AmpCal(int Mag __gc[ , ]); // construct amplitude calibration table from raw data
void DirectivityCal(int DirectivityMag __gc[,]); // Record directivity data - NEW 10-17-2005
double IQtoDegrees(int I, int Q); // convert I/Q ADC reading to degrees
double MagTodBRefl(int Freq, int Mag); // convert detector magnitude count to dB. via piecewise linear fit
double MagTodBTran(int Freq, int Mag, int LowMag, int MidMag); // convert detector magnitude count to dB. via table lookup
};
/// Object to hold Calibration data
__gc public class CalDataSet
{
public:
/// Holds raw and computed calibration data
Detector* RxDet, * TxDet; /// Holds detector constants
double EdReal __gc[], EdImag __gc[], EsReal __gc[], EsImag __gc[];
double EtReal __gc[], EtImag __gc[], ThReal __gc[], ThImag __gc[];
double S11shortReal __gc[], S11shortImag __gc[];
double S11openReal __gc[], S11openImag __gc[];
double S11termReal __gc[], S11termImag __gc[];
int FreqError; // Internal Crystal Frequency Error
CalDataSet(String *);
// resolve reflected measured data set to Magnitude and Phase
void ResolveReflPolar(int ReflPI, int ReflPQ, int ReflMI, int Freq, double& rmag, double& rphs, bool CouplerComp);
// resolve transmitted measured data set to Magnitude and Phase
void ResolveTranPolar(int TranPI, int TranPQ, int TranMQHi, int TranMQLo, int TranMQMid, int Freq, double& rmag, double& rphs);
};
// Derive error terms from cal measurements
void CalToErrorTerms(CalDataSet* Cal);
// Convert measured S11 into actual S11 via calibration
void CorrectS11(CalDataSet * Cal, int Frequency, double measmag, double measphs, double& rsltmag, double& rsltphs);
// Convert measured S21 into actual S21 via calibration
void CorrectS21(CalDataSet* Cal, int Frequency, double measmag, double measphs, double& rsltmag, double& rsltphs);
// Load calibration data from a previously saved file
bool LoadCalDataSet(OpenFileDialog* infile, CalDataSet* Cal);
// Save newly acquired calibration data to a file
void SaveCalDataSet(SaveFileDialog* outfile, CalDataSet* Cal);
// Convert Log Tx Level to linear value needed by DAC register
unsigned short TxLevLinear(int);
// Convert linear DAC level to dBm. 4095 = 0.0 dBm.
float dBFromLinear(int);
// Convert Return Loss (S11 mag) to SWR, then to vertical display coordinate
int ToDisplayAsSWR(double mag, int height, int scaledB);
// Export S Parameters to a file
void ExportSParams(int format, FrequencyGrid * FG,
double __gc[], double __gc[], double __gc[], double __gc[],
double __gc[], double __gc[], double __gc[], double __gc[]);
// Store S Parameters to temporary storage
void StoreSParams(bool calmode, FrequencyGrid * FG, CalDataSet * CalData,
unsigned short __gc[], unsigned short __gc[], unsigned short __gc[],
unsigned short __gc[], unsigned short __gc[], unsigned short __gc[],
unsigned short __gc[], unsigned short __gc[],
double __gc[], double __gc[], double __gc[], double __gc[]);
// Linear interpolation of Xval between Xlow and Xhigh yielding Y result between Ylow and Yhi
//double public Interpolate(int Xval, int Xlow, int Ylow, int Xhi, int Yhi);
//double public Interpolate(float Xval, float Xlow, float Ylow, float Xhi, float Yhi);
// Median filtering routine. Input is 7 measurements. Returns the median value.
int Median7(unsigned short __gc[], int);
// Median filtering routine. Input is 7 measurements. Returns the median value.
int Median7i(int __gc[]);
// Range routine. Determine range of middle 5 samples in a group of 7 samples.
int Range(unsigned short data __gc[], int index);
// DrawLine routines that checks and bounds points to display rectangle
void DrawLineBound(System::Drawing::Graphics *, System::Drawing::Rectangle, System::Drawing::Pen *, int, int, int, int);
void DrawLineBound(System::Drawing::Graphics *, System::Drawing::Rectangle, System::Drawing::Pen *, System::Drawing::Point, System::Drawing::Point);
// Add 2 polar numbers
void AddPolar(double& mag, double& phase, double magadd, double phaseadd);
// Convert MeasurementDelay string to target's loop count
int MeasureDelayStringToCount(String * value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -