#include "matrixData.h" /* Function: MatrixData * Params In * N/A * Return * N/A * Purpose * Default constructor. Initialize both columnLen and columnNum to 0. */ MatrixData::MatrixData( int rNum, int cNum, QWidget* parent ) { // Set the radar and channel numbers. radarNumber = rNum; channelNumber = cNum; // Initialize variables. tOffset = 0.0; // Connect to parent for writing messages to the log. connect( this, SIGNAL( writeMsg( QString, int ) ), parent, SLOT( writeToLog( QString, int ) ) ); // Initialize the column lengths for each data type to 0. for( int i = 0; i < dataTypes; ++i ) { columnLen[0] = 0; } columnNum = 0; colsPastTraceLen = 0; aColSum = NULL; aCol = new float*[ channelNumber ]; refPulse = new float*[ channelNumber ]; rawMatrix.resize( channelNumber ); pulseMatrix.resize( channelNumber ); freqMatrix.resize( channelNumber ); std::vector< fftwf_complex > temp; temp.resize( MAXPOINTS ); for( int m = 0; m < MAXPOINTS; ++m ) { temp[m] = 0.0; } for( int j = 0; j < channelNumber; ++j ) { refPulse[j] = NULL; rawMatrix[j].resize( TRACELENGTH ); pulseMatrix[j].resize( TRACELENGTH ); freqMatrix[j].resize( TRACELENGTH ); for( int k = 0; k < TRACELENGTH; ++k ) { rawMatrix[j][k] = temp; pulseMatrix[j][k] = temp; freqMatrix[j][k] = temp; } } initializeColumns(); } MatrixData::~MatrixData() { delete [] aColSum; for( int i = 0; i < channelNumber; ++i ) { delete [] aCol[i]; delete [] refPulse[i]; } rawMatrix.clear(); pulseMatrix.clear(); freqMatrix.clear(); } void MatrixData::setColumnLen( int len, int dataType ) { if( ( dataType >= 0 ) && ( dataType < 4 ) ) { columnLen[dataType] = len; if( dataType == 3 ) { for( int i = 0; i < channelNumber; ++i ) { if( refPulse[i] ) { delete refPulse[i]; refPulse[i] = NULL; } refPulse[i] = new float[ len ]; } } } else { std::cout << "Error: DataType is not a valid type." << std::endl; } } int MatrixData::getColumnLen( int dataType ) { if( ( dataType >= 0 ) && ( dataType < 4 ) ) { return columnLen[dataType]; } else { return MAXPOINTS; } } int MatrixData::getColumnNum() { return columnNum; } int MatrixData::getRadarNum() { return radarNumber; } int MatrixData::getChanNum() { return channelNumber; } void MatrixData::setDepthScaleVal( double timePre, double timePost, double* hz ) { timeDepthPre = timePre; timeDepthPost = timePost; hzDepthStart = hz[0]; hzDepth = hz[1]; } double MatrixData::getDepthScaleVal( int data, int depth, int val ) { double timeVal = 0.0; double microseconds = 1000000.0; if( data == 1 ) { return ( ( hzDepthStart + ( val * hzDepth ) ) / 1000000.0 ); } else if ( data == 0 ) { timeVal = ( timeDepthPre * val ) + tOffset; } else // data == 2 { timeVal = ( timeDepthPost * val ) + tOffset - pLength; } if( depth == 0 ) { return ( ( ( ( 300000000.0 ) * timeVal ) / ( 2.0 ) ) / microseconds ) / 1000.0; } else if( depth == 1 ) { return ( ( ( ( 300000000.0 ) * timeVal ) / ( sqrt( 3.15 ) * 2.0 ) ) / microseconds ) / 1000.0; } else // depth == 2 { return timeVal; } } bool MatrixData::matrixEqualLength() { if( pulseMatrix[0].size() == pulseMatrix[1].size() == pulseMatrix[2].size() == pulseMatrix[3].size() == pulseMatrix[4].size() == pulseMatrix[5].size() == pulseMatrix[6].size() == pulseMatrix[7].size() ) { return true; } return false; } int MatrixData::getLastCol() { return rawMatrix[0].size(); } float MatrixData::getColData( int i, int x, int y, PlotOptions* p ) { int xCoord = ( ( columnNum - 1 ) % TRACELENGTH ); // Return a value that is the sum of the user-selected channels. if( i == 0 ) { fftwf_complex sum = 0.0; float dSum = 0.0; for( int j = 0; j < channelNumber; ++j ) { if( p->channels[j] ) { if( p->dataType == 0 ) { sum = rawMatrix[j][xCoord][y]; } else if( p->dataType == 1 ) { sum = freqMatrix[j][xCoord][y]; } else { sum = pulseMatrix[j][xCoord][y]; } } } if( p->dataScale == 0 ) { dSum = creal( sum ); } else { dSum = ( 20 * log10( cabs( sum ) ) ); } return dSum; } else // Return the value from the specified channel. { fftwf_complex sum = 0.0; float dSum = 0.0; if( p->dataType == 0 ) { sum = rawMatrix[i-1][xCoord][y]; } else if( p->dataType == 1 ) { sum = freqMatrix[i-1][xCoord][y]; } else { sum = pulseMatrix[i-1][xCoord][y]; } if( p->dataScale == 0 ) { dSum = creal( sum ); } else { dSum = ( 20 * log10( cabs( sum ) ) ); } return dSum; } } void MatrixData::setRefPulse( float** reference ) { //refPulse = reference; for( int i = 0; i < channelNumber; ++i ) { for( int j = 0; j < getColumnLen( 3 ); ++j ) { refPulse[i][j] = reference[i][j]; } } } float MatrixData::getRefPulse( int chan, int xCoord ) { return refPulse[ chan ][ xCoord ]; } /* Function: getMatrixData * Params In * int x: The x-coordinate of the point in the matrix. * int y: The y-coordinate of the point in the matrix. * Return * double: Returns the value from the matrix at (x,y). * Purpose * Gets the value from every selected channel's matrix at point (x,y), returns the sum of the values converted to a float. */ float MatrixData::getMatrixData( int x, int y, int scale, int type, PlotOptions* params ) { int xCoord = ( ( columnNum + x ) % TRACELENGTH ); //Sum the values every channel and send back. if( scale == 0 ) { if( type == 0 ) { fftwf_complex res = 0.0; for( int c = 0; c < channelNumber; ++c ) { if( params->channels[c] ) { res += rawMatrix[c][xCoord][y]; } } return creal( res ); } else if( type == 1 ) { fftwf_complex res = 0.0; for( int c = 0; c < channelNumber; ++c ) { if( params->channels[c] ) { res += freqMatrix[c][xCoord][y]; } } return creal( res ); } else { fftwf_complex res = 0.0; for( int c = 0; c < channelNumber; ++c ) { if( params->channels[c] ) { res += pulseMatrix[c][xCoord][y]; } } return creal( res ); } } else { if( type == 0 ) { fftwf_complex res = 0.0; for( int c = 0; c < channelNumber; ++c ) { if( params->channels[c] ) { res += rawMatrix[c][xCoord][y]; } } return 20 * log10( cabs( res ) ); } else if( type == 1 ) { fftwf_complex res = 0.0; for( int c = 0; c < channelNumber; ++c ) { if( params->channels[c] ) { res += freqMatrix[c][xCoord][y]; } } return 20 * log10( cabs( res ) ); } else { fftwf_complex res = 0.0; for( int c = 0; c < channelNumber; ++c ) { if( params->channels[c] ) { res += pulseMatrix[c][xCoord][y]; } } return 20 * log10( cabs( res ) ); } } } /* Function: setFreqMatrixData * Params In * int i: The channel that is getting data set. * vector< fftwf_complex > data: The column of complex data getting added to the matrix. * Return * N/A * Purpose * Sets the next column in the specific matrix to contain the new vector of data. */ void MatrixData::setFreqMatrixData( int i, std::vector< fftwf_complex > data ) { // i is the channel. Since C++ starts from 0, subtract 1 from i. freqMatrix[i-1][columnNum % TRACELENGTH] = data; } /* Function: setPulseMatrixData * Params In * int i: The channel that is getting data set. * vector< fftwf_complex > data: The column of complex data getting added to the matrix. * Return * N/A * Purpose * Sets the next column in the specific matrix to contain the new vector of data. * Increments the column counter by one when the channel being stored is the max channels. */ void MatrixData::setPulseMatrixData( int i, std::vector< fftwf_complex > data ) { // i is the channel. Since C++ starts from 0, subtract 1 from i. pulseMatrix[i-1][columnNum % TRACELENGTH] = data; if( i == channelNumber ) { columnNum++; } } /* Function: setRawMatrixData * Params In * int i: The channel that is getting data set. * vector< fftwf_complex > data: The column of complex data getting added to the matrix. * Return * N/A * Purpose * Sets the next column in the specific matrix to contain the new vector of data. * Increments the column counter by one. */ void MatrixData::setRawMatrixData( int i, std::vector< fftwf_complex > data ) { // i is the channel. Since C++ starts from 0, subtract 1 from i. rawMatrix[i-1][columnNum % TRACELENGTH] = data; } float* MatrixData::getColDataDouble( int i, PlotOptions* p ) { if( i == 0 ) { for( int j = 0; j < columnLen[p->dataType]; ++j ) { fftw_complex resSum; resSum = 0.0; for( int k = 0; k < channelNumber; ++k ) { if( p->channels[k] ) { if( p->dataType == 0 ) { resSum += rawMatrix[k][columnNum-1][j]; } else if( p->dataType == 1 ) { resSum += freqMatrix[k][columnNum-1][j]; } else { resSum += pulseMatrix[k][columnNum-1][j]; } } } if( p->dataScale == 0 ) { aColSum[j] = creal( resSum ); } else if( p->dataScale == 1 ) { aColSum[j] = 20* log10( cabs( resSum ) ); } } for( int k = columnLen[p->dataType]; k < MAXPOINTS; ++k ) { aColSum[k] = 50.0; } return aColSum; } else if( ( i > 0 ) && ( i <= channelNumber ) ) { fftw_complex res = 0.0; for( int j = 0; j < columnLen[p->dataType]; ++j ) { if( p->dataType == 0 ) { res = rawMatrix[i-1][columnNum-1][j]; } else if( p->dataType == 1 ) { res = freqMatrix[i-1][columnNum-1][j]; } else { res = pulseMatrix[i-1][columnNum-1][j]; } if( p->dataScale == 0 ) { aCol[i-1][j] = creal( res ); } else if( p->dataScale == 1 ) { aCol[i-1][j] = 20 * log10( cabs( res ) ); } } for( int k = columnLen[p->dataType]; k < MAXPOINTS; ++k ) { aCol[i-1][k] = 0.0; } return aCol[i-1]; } else { exit(1); } } void MatrixData::initializeColumns() { aColSum = new float[ MAXPOINTS ]; for( int i = 0; i < channelNumber; ++i ) { aCol[i] = new float[ MAXPOINTS ]; for( int j = 0; j < MAXPOINTS; ++j ) { aColSum[j] = 0.0; aCol[i][j] = 0.0; } } } void MatrixData::setRadarOffsetValues( double air, double ice, double time ) { tOffset = time; } void MatrixData::setTau( double t ) { pLength = t; QString tmp; tmp.setNum( pLength ); //writeMsg( "Pulse Length is: " + tmp, DEBUG ); }