Forums › General Discussions › TG44A Sweep to Path Loss conversion utility
- This topic has 5 replies, 3 voices, and was last updated 9 years, 7 months ago by Bruce.
- AuthorPosts
PhilParticipantThought I would kick off things by providing something that has been handy for me in the past. Unclear if this will still be useful in the upcoming SH software release but it is here for posterity.
One of the things that bothered me in SH 2.18B was I could not do a loss sweep on a cable with the TG and save the result in a format that I could use to apply as a path loss in a later measurement. This can be super handy when you are doing a semi-precise measurement and don’t want the effort of manually entering in a pile of attenuation points in a path loss file. MS Visual Studio Express compliant source code is attached for this command line utility.
Enjoy!
PhilParticipantHmmm. .cpp files blocked. Ugly text follows:
// SHPathLossGen.cpp : Defines the entry point for the console application.
//
// This is more complex than initially thought. Due to limitations in SignalHound 2.18B
// the .CSV data points must be compressed down to 100 data points or less for the Path Loss file
// otherwise bad things happen WRT to signal levels in the SignalHound application.
// As such, the strategy is to divide the number of data points in the CSV file into less than 100 bins (the max allowable
// number of Path Loss Data points) and average the loss/gain of those CSV data points in each bin to come up with a
// single Path Loss datapoint per bin.
// *** Note this 100 point limitation means that Pass loss files will not be exact replicas of Track Gen loss sweeps,
// particularly if there are sharp changes in loss/gain over the span ***#include “stdafx.h”
#include “stdlib.h”
#include “winerror.h”
#include <fstream>
#include <iostream>
#include <string>
#include <vector>using namespace std;
int main(int argc, char* argv[])
{
struct CSVRecord {
double frequency;
double minAmp;
double maxAmp;
};vector<CSVRecord> CSVList;
string line;
unsigned int pos1, pos2;
CSVRecord tempCSV;ifstream fSHExport;
ofstream fSHPathLoss;if((argv[1] == NULL) || (argv[2] == NULL))
{
printf(“\r\nConversion utility from SignalHound .csv output to SH Path Loss file format\r\n”);
printf(“Missing Arguments!\r\n”);
printf(“Usage:\r\n\r\n”);
printf(“%s <Input file> <Output file>\r\n\r\n”, argv[0]);
printf(“Where:\r\n”);
printf(“\r\n Input File – .csv file exported from SignalHound application\r\n”);
printf(“\r\n Output file – file to be written with PathLoss data for import into SignalHound application\r\n”);
printf(“\r\n Note the utility takes the MINIMUM amplitude from the .csv file for the Path Loss.\r\n”);return ERROR_BAD_ARGUMENTS;
}fSHExport.open(argv[1]);
fSHPathLoss.open(argv[2]);//Load the CSV file records into CSVList vector
if(fSHExport.is_open() && fSHPathLoss.is_open())
{
//Toss the first line
getline(fSHExport, line);while (fSHExport.good())
{
getline(fSHExport, line);if(fSHExport.eofbit)
{
pos1 = line.find(“,”);
if(pos1 != -1)
{
pos2 = line.find(“,”, pos1+1);
tempCSV.frequency = atof((line.substr(0, pos1).c_str()));
tempCSV.minAmp = atof((line.substr(pos1+1, pos1-pos2).c_str()));
tempCSV.maxAmp = atof((line.substr(pos2+1).c_str()));CSVList.push_back(tempCSV);
}
}
}//Calculate the number of CSV records/bin we will need from the number of records in the CSVList vector
// Experimental – divide by 100, round up to nearest whole number – this should give us somewhere
// between 50 and 100 bins
double j = (double) CSVList.size()/100;int bin_size = ceil(j);
//Iterate through the records, adding them up in bins and averaging the frequency and amplitude for each bin
vector<CSVRecord>::iterator it = CSVList.begin();while(it != CSVList.end())
{
CSVRecord totCSVRecord;
totCSVRecord.frequency = 0;
totCSVRecord.minAmp = 0;
totCSVRecord.maxAmp = 0;for(int i = 0; i < bin_size; ++i)
{
if(it == CSVList.end())
{
//if we are here we should be in the last bin – set the bin size to the amount of remaining records
//to allow the averaging for the last bin to be correct.
bin_size = i;
break;
}//cout << “bin: ” << i << ” “;
tempCSV = *it;//invert amplitude for Path loss instead of gain
tempCSV.minAmp = -tempCSV.minAmp;
tempCSV.maxAmp = -tempCSV.maxAmp;totCSVRecord.frequency += tempCSV.frequency;
totCSVRecord.minAmp += tempCSV.minAmp;
totCSVRecord.maxAmp += tempCSV.maxAmp;//cout << tempCSV.frequency << “:” << tempCSV.minAmp << “:” << tempCSV.maxAmp << endl;
++it;
}cout << (totCSVRecord.frequency/bin_size) << “,” << ((totCSVRecord.minAmp/bin_size) + (totCSVRecord.maxAmp/bin_size))/2 << endl;
fSHPathLoss << (totCSVRecord.frequency/bin_size) << “,” << ((totCSVRecord.minAmp/bin_size) + (totCSVRecord.maxAmp/bin_size))/2 << endl;
}fSHExport.close();
fSHPathLoss.close();
}else
{
cout << “Unable to open either input or output file!” << endl;
return ERROR_FILE_NOT_FOUND;
}printf(“Finished!”);
return ERROR_SUCCESS;
}
AndrewModeratorHey Phil, thank you for sharing this.
BruceModeratorHi Phil, this is a killer function. Thanks again for bringing it to our attention. I spoke with AJ and Justin about it. They both agree that this is low hanging fruit so we will be implementing it as part of the SA/TG rewrite that is scheduled to hit the street, in less than a month, on 10 Feb 2015.
There will be at least 1000 data points allowed to be saved in a file, from TG sweeps. The user will then be able to load the saved file in the path loss table. This should be a real time saver when making precision measurements over a broad range of frequencies.
PhilParticipantThanks Bruce! Really appreciate the response to my feedback and looking forward to trying the new functionality.
If I may suggest – It would be great if one could import multiple path loss files cumulatively to the path loss table. For example – I am sweeping a cavity using cable A to go from the TG to the cavity and cable B from the cavity to the spectrum analyzer. I could import the path loss file for cable A and then for cable B – the resulting path loss table would be the sum of both cable losses. Can’t remember if SH2.18B works this way already but would be handy if it did!
Cheers,
Phil
BruceModeratorHi Again Phil, Justin told me that the manual has instructions to combine multiple data files in a MS Excel datasheet, save it, and then load it into the path loss table. So it can already be done. You are the only one that has requested this function so it is not a popular enough function for us to write the code. You’re still batting a 500. One out of two is doing great.
- AuthorPosts
You must be logged in to reply to this topic.