Beispiel #1
0
        public bool Add(RFESweepData SweepData)
        {
            try
            {
                if (IsFull())
                {
                    return(false);
                }

                if (m_MaxHoldData == null)
                {
                    m_MaxHoldData = new RFESweepData(SweepData.StartFrequencyMHZ, SweepData.StepFrequencyMHZ, SweepData.TotalSteps);
                }

                if (m_nUpperBound >= (m_arrData.Length - 1))
                {
                    if (m_bAutogrow)
                    {
                        ResizeCollection(10 * 1000); //add 10K samples more
                    }
                    else
                    {
                        //move all items one position down, lose the older one at position 0
                        m_nUpperBound = m_arrData.Length - 2;
                        m_arrData[0]  = null;
                        for (int nInd = 0; nInd <= m_nUpperBound; nInd++)
                        {
                            m_arrData[nInd] = m_arrData[nInd + 1];
                        }
                    }
                }

                m_nUpperBound++;
                m_arrData[m_nUpperBound] = SweepData;

                for (UInt16 nInd = 0; nInd < SweepData.TotalSteps; nInd++)
                {
                    if (SweepData.GetAmplitudeDBM(nInd, null, false) > m_MaxHoldData.GetAmplitudeDBM(nInd, null, false))
                    {
                        m_MaxHoldData.SetAmplitudeDBM(nInd, SweepData.GetAmplitudeDBM(nInd, null, false));
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public RFESweepData GetMedianAverage(UInt32 nStart, UInt32 nEnd)
        {
            RFESweepData objReturn = null;

            //string sDebugText = "";

            if (nStart > m_nUpperBound || nEnd > m_nUpperBound || nStart > nEnd)
            {
                return(null);
            }

            UInt32 nTotalIterations = nEnd - nStart + 1;

            try
            {
                objReturn = new RFESweepData(m_arrData[nEnd].StartFrequencyMHZ, m_arrData[nEnd].StepFrequencyMHZ, m_arrData[nEnd].TotalSteps);

                for (UInt16 nSweepInd = 0; nSweepInd < objReturn.TotalSteps; nSweepInd++)
                {
                    //sDebugText += "[" + nSweepInd + "]:";
                    float   fSweepValue    = 0f;
                    float[] arrSweepValues = new float[nTotalIterations];

                    for (UInt32 nIterationInd = nStart; nIterationInd <= nEnd; nIterationInd++)
                    {
                        if (nSweepInd == 0)
                        {
                            //check all the sweeps use the same configuration, but only in first loop to reduce overhead
                            if (!m_arrData[nIterationInd].IsSameConfiguration(objReturn))
                            {
                                return(null);
                            }
                        }
                        arrSweepValues[nIterationInd - nStart] = m_arrData[nIterationInd].GetAmplitudeDBM(nSweepInd, null, false);
                        //sDebugText += m_arrData[nIterationInd].GetAmplitudeDBM(nSweepInd).ToString("f2") + ",";
                    }
                    Array.Sort(arrSweepValues);
                    fSweepValue = arrSweepValues[nTotalIterations / 2];
                    //sDebugText += "(" + fSweepValue.ToString("f2") + ")";
                    objReturn.SetAmplitudeDBM(nSweepInd, fSweepValue);
                }
            }
            catch
            {
                objReturn = null;
            }
            return(objReturn);
        }
        public RFESweepData GetAverage(UInt32 nStart, UInt32 nEnd)
        {
            RFESweepData objReturn = null;

            //string sDebugText = "";

            if (nStart > m_nUpperBound || nEnd > m_nUpperBound || nStart > nEnd)
            {
                return(null);
            }

            try
            {
                objReturn = new RFESweepData(m_arrData[nEnd].StartFrequencyMHZ, m_arrData[nEnd].StepFrequencyMHZ, m_arrData[nEnd].TotalDataPoints);

                for (UInt16 nDataPoint = 0; nDataPoint < objReturn.TotalDataPoints; nDataPoint++)
                {
                    //sDebugText += "[" + nSweepInd + "]:";
                    float fSweepValue = 0f;
                    for (UInt32 nIterationInd = nStart; nIterationInd <= nEnd; nIterationInd++)
                    {
                        if (nDataPoint == 0)
                        {
                            //check all the sweeps use the same configuration, but only in first loop to reduce overhead
                            if (!m_arrData[nIterationInd].IsSameConfiguration(objReturn))
                            {
                                return(null);
                            }
                        }

                        fSweepValue += m_arrData[nIterationInd].GetAmplitudeDBM(nDataPoint, null, false);
                        //sDebugText += m_arrData[nIterationInd].GetAmplitudeDBM(nSweepInd).ToString("f2") + ",";
                    }
                    fSweepValue = fSweepValue / (nEnd - nStart + 1);
                    //sDebugText += "(" + fSweepValue.ToString("f2") + ")";
                    objReturn.SetAmplitudeDBM(nDataPoint, fSweepValue);
                }
            }
            catch
            {
                objReturn = null;
            }
            return(objReturn);
        }
        /// <summary>
        /// 
        /// 
        /// 
        /// </summary>
        /// <param name="sFile"></param>
        /// <returns></returns>
        //

        /// <summary>
        /// Will load a RFE standard file from disk. If the file format is incorrect (unknown) will return false but will not invalidate the internal container
        /// If there are file exceptions, will be received by the caller so should react with appropriate error control
        /// If file is successfully loaded, all previous container data is lost and replaced by data from file
        /// </summary>
        /// <param name="sFile">File name to load</param>
        /// <param name="sModelText">model data text. If it is a normal sweep file, then this comes from spectrum analyzer. If it is tracking or normalization 
        /// then this is from both signal generator and spectrum analyzer</param>
        /// <param name="sConfigurationText">configuration text. If it is a normal sweep file, then this comes from spectrum analyzer. If it is tracking or normalization 
        /// then this is from Signal Generator and some required parameters from spectrum analyzer too.</param>
        /// <returns></returns>
        public bool LoadFile(string sFile, out string sModelText, out string sConfigurationText)
        {
            sConfigurationText = "Configuration info Unknown - Old file format";
            sModelText = "Model Unknown - Old file format";

            FileStream myFile = null;

            try
            {
                myFile = new FileStream(sFile, FileMode.Open);

                using (BinaryReader binStream = new BinaryReader(myFile))
                {
                    myFile = null;

                    string sHeader = binStream.ReadString();
                    if ((sHeader != FileHeaderVersioned()) && (sHeader != FileHeaderVersioned_001()))
                    {
                        //unknown format
                        return false;
                    }

                    double fStartFrequencyMHZ = binStream.ReadDouble();
                    double fStepFrequencyMHZ = binStream.ReadDouble();
                    UInt32 nMaxDataIndex = 0;
                    if (sHeader == FileHeaderVersioned_001())
                    {
                        //in version 001 we saved a 16 bits integer
                        nMaxDataIndex = binStream.ReadUInt16();
                    }
                    else
                    {
                        nMaxDataIndex = binStream.ReadUInt32();
                    }
                    UInt16 nTotalSteps = binStream.ReadUInt16();

                    if (sHeader != FileHeaderVersioned_001())
                    {
                        sConfigurationText = "From file: " + binStream.ReadString();
                        sModelText = "From file: " + binStream.ReadString();
                    }

                    //We initialize internal data only if the file was ok and of the right format
                    CleanAll();
                    m_arrData = new RFESweepData[nMaxDataIndex];

                    for (UInt32 nSweepInd = 0; nSweepInd < nMaxDataIndex; nSweepInd++)
                    {
                        RFESweepData objRead = new RFESweepData((float)fStartFrequencyMHZ, (float)fStepFrequencyMHZ, nTotalSteps);

                        if (sHeader == FileHeaderVersioned_001())
                        {
                            objRead.CaptureTime = new DateTime(2000, 1, 1); //year 2000 means no actual valid date-time was captured
                        }
                        else
                        {
                            //Starting in version 002, load sweep capture time too
                            int nLength = (int)binStream.ReadInt32();
                            string sTime = (string)binStream.ReadString();
                            if ((sTime.Length == nLength) && (nLength > 0))
                            {
                                objRead.CaptureTime = DateTime.Parse(sTime);
                            }
                        }

                        for (UInt16 nStep = 0; nStep < nTotalSteps; nStep++)
                        {
                            objRead.SetAmplitudeDBM(nStep, (float)binStream.ReadDouble());
                        }
                        Add(objRead);
                    }
                }
            }
            finally
            {
                if (myFile != null)
                    myFile.Dispose();
            }

            return true;
        }
        public RFESweepData GetAverage(UInt32 nStart, UInt32 nEnd)
        {
            RFESweepData objReturn = null;

            //string sDebugText = "";

            if (nStart > m_nUpperBound || nEnd > m_nUpperBound || nStart > nEnd)
            {
                return null;
            }

            try
            {
                objReturn = new RFESweepData(m_arrData[nEnd].StartFrequencyMHZ, m_arrData[nEnd].StepFrequencyMHZ, m_arrData[nEnd].TotalSteps);

                for (UInt16 nSweepInd = 0; nSweepInd < objReturn.TotalSteps; nSweepInd++)
                {
                    //sDebugText += "[" + nSweepInd + "]:";
                    float fSweepValue = 0f;
                    for (UInt32 nIterationInd = nStart; nIterationInd <= nEnd; nIterationInd++)
                    {
                        if (nSweepInd == 0)
                        {
                            //check all the sweeps use the same configuration, but only in first loop to reduce overhead
                            if (!m_arrData[nIterationInd].IsSameConfiguration(objReturn))
                                return null;
                        }

                        fSweepValue += m_arrData[nIterationInd].GetAmplitudeDBM(nSweepInd,null,false);
                        //sDebugText += m_arrData[nIterationInd].GetAmplitudeDBM(nSweepInd).ToString("f2") + ",";
                    }
                    fSweepValue = fSweepValue / (nEnd - nStart + 1);
                    //sDebugText += "(" + fSweepValue.ToString("f2") + ")";
                    objReturn.SetAmplitudeDBM(nSweepInd, fSweepValue);
                }
            }
            catch
            {
                objReturn = null;
            }
            return objReturn;
        }
Beispiel #6
0
        private void CreateWaterfallTestData()
        {
            m_WaterfallSweepMaxHold.CleanAll();

            m_objRFEAnalyzer.AmplitudeBottomDBM = -100;
            m_objRFEAnalyzer.AmplitudeTopDBM = -10;

            UInt16 nTotalSteps = 100;

            for (UInt16 nMaxHoldInd = 0; nMaxHoldInd < nTotalSteps; nMaxHoldInd++)
            {
                RFESweepData objNewSweep = new RFESweepData(100.0f, 10.0f / 112, 112);
                m_WaterfallSweepMaxHold.Add(objNewSweep);

                for (UInt16 nSweepDataInd = 0; nSweepDataInd < objNewSweep.TotalSteps; nSweepDataInd++)
                {
                    float fAmplitude = -100.0f;
                    //a mark on the 6th position
                    if (nSweepDataInd == 5)
                    {
                        fAmplitude = -30.0f;
                    }
                    //every of the 10 divisions (112/10)
                    if ((nSweepDataInd % 12) == 0)
                    {
                        fAmplitude = -40.0f;
                    }
                    //A 15 steps band for the first half of the sweep time
                    if (nMaxHoldInd < 50)
                    {
                        if (nSweepDataInd > 35 && nSweepDataInd < 50)
                        {
                            fAmplitude = -50.0f;
                        }
                    }
                    //every 5 sweeps interval
                    if ((nMaxHoldInd % 10) < 5)
                    {
                        if (nSweepDataInd == 65)
                        {
                            fAmplitude = -30.0f;
                        }
                    }
                    objNewSweep.SetAmplitudeDBM(nSweepDataInd, fAmplitude);
                }
                Thread.Sleep(10); //to force some time difference between samples
            }
            UpdateWaterfall();
        }
Beispiel #7
0
        /// <summary>
        ///
        ///
        ///
        /// </summary>
        /// <param name="sFile"></param>
        /// <returns></returns>
        //

        /// <summary>
        /// Will load a RFE standard file from disk. If the file format is incorrect (unknown) will return false but will not invalidate the internal container
        /// If there are file exceptions, will be received by the caller so should react with appropriate error control
        /// If file is successfully loaded, all previous container data is lost and replaced by data from file
        /// </summary>
        /// <param name="sFile">File name to load</param>
        /// <param name="sModelText">model data text. If it is a normal sweep file, then this comes from spectrum analyzer. If it is tracking or normalization
        /// then this is from both signal generator and spectrum analyzer</param>
        /// <param name="sConfigurationText">configuration text. If it is a normal sweep file, then this comes from spectrum analyzer. If it is tracking or normalization
        /// then this is from Signal Generator and some required parameters from spectrum analyzer too.</param>
        /// <returns></returns>
        public bool LoadFile(string sFile, out string sModelText, out string sConfigurationText)
        {
            sConfigurationText = "Configuration info Unknown - Old file format";
            sModelText         = "Model Unknown - Old file format";

            FileStream myFile = null;

            try
            {
                myFile = new FileStream(sFile, FileMode.Open);

                using (BinaryReader binStream = new BinaryReader(myFile))
                {
                    myFile = null;

                    string sHeader = binStream.ReadString();
                    if ((sHeader != FileHeaderVersioned()) && (sHeader != FileHeaderVersioned_001()))
                    {
                        //unknown format
                        return(false);
                    }

                    double fStartFrequencyMHZ = binStream.ReadDouble();
                    double fStepFrequencyMHZ  = binStream.ReadDouble();
                    UInt32 nMaxDataIndex      = 0;
                    if (sHeader == FileHeaderVersioned_001())
                    {
                        //in version 001 we saved a 16 bits integer
                        nMaxDataIndex = binStream.ReadUInt16();
                    }
                    else
                    {
                        nMaxDataIndex = binStream.ReadUInt32();
                    }
                    UInt16 nTotalSteps = binStream.ReadUInt16();

                    if (sHeader != FileHeaderVersioned_001())
                    {
                        sConfigurationText = "From file: " + binStream.ReadString();
                        sModelText         = "From file: " + binStream.ReadString();
                    }

                    //We initialize internal data only if the file was ok and of the right format
                    CleanAll();
                    m_arrData = new RFESweepData[nMaxDataIndex];

                    for (UInt32 nSweepInd = 0; nSweepInd < nMaxDataIndex; nSweepInd++)
                    {
                        RFESweepData objRead = new RFESweepData((float)fStartFrequencyMHZ, (float)fStepFrequencyMHZ, nTotalSteps);

                        if (sHeader == FileHeaderVersioned_001())
                        {
                            objRead.CaptureTime = new DateTime(2000, 1, 1); //year 2000 means no actual valid date-time was captured
                        }
                        else
                        {
                            //Starting in version 002, load sweep capture time too
                            int    nLength = (int)binStream.ReadInt32();
                            string sTime   = (string)binStream.ReadString();
                            if ((sTime.Length == nLength) && (nLength > 0))
                            {
                                objRead.CaptureTime = DateTime.Parse(sTime);
                            }
                        }

                        for (UInt16 nStep = 0; nStep < nTotalSteps; nStep++)
                        {
                            objRead.SetAmplitudeDBM(nStep, (float)binStream.ReadDouble());
                        }
                        Add(objRead);
                    }
                }
            }
            finally
            {
                if (myFile != null)
                {
                    myFile.Dispose();
                }
            }

            return(true);
        }
        /// <summary>
        /// Will load a RFE standard file from disk. If the file format is incorrect (unknown) will return false but will not invalidate the internal container
        /// If there are file exceptions, will be received by the caller so should react with appropriate error control
        /// If file is successfully loaded, all previous container data is lost and replaced by data from file
        /// </summary>
        /// <param name="sFile">File name to load</param>
        /// <param name="sModelText">model data text. If it is a normal sweep file, then this comes from spectrum analyzer. If it is tracking or normalization
        /// then this is from both signal generator and spectrum analyzer</param>
        /// <param name="sConfigurationText">configuration text. If it is a normal sweep file, then this comes from spectrum analyzer. If it is tracking or normalization
        /// then this is from Signal Generator and some required parameters from spectrum analyzer too.</param>
        /// <returns></returns>
        public bool LoadFile(string sFile, out string sModelText, out string sConfigurationText)
        {
            sConfigurationText = "Configuration info Unknown - Old file format";
            sModelText         = "Model Unknown - Old file format";
            FileStream myFile = null;

            try
            {
                myFile = new FileStream(sFile, FileMode.Open);

                using (BinaryReader binStream = new BinaryReader(myFile))
                {
                    myFile = null;

                    string sHeader = binStream.ReadString();
                    if ((sHeader != FileHeaderVersioned()) && (sHeader != FileHeaderVersioned_001() && sHeader != FileHeaderVersioned_002() &&
                                                               sHeader != FileHeaderVersioned_003() && sHeader != FileHeaderVersioned_004()))
                    {
                        //unknown format
                        return(false);
                    }

                    double fStartFrequencyMHZ = binStream.ReadDouble();
                    double fStepFrequencyMHZ  = binStream.ReadDouble(); //For normalization file older than v004, we do not use step but start/stop so this variable has not effect
                    UInt32 nMaxDataIndex      = 0;
                    if (sHeader == FileHeaderVersioned_001())
                    {
                        //in version 001 we saved a 16 bits integer
                        nMaxDataIndex = binStream.ReadUInt16();
                    }
                    else
                    {
                        nMaxDataIndex = binStream.ReadUInt32();
                    }

                    UInt16 nTotalDataPoints = binStream.ReadUInt16();

                    if (sHeader != FileHeaderVersioned_001())
                    {
                        sConfigurationText = "From file: " + binStream.ReadString();
                        sModelText         = "From file: " + binStream.ReadString();

                        if (sHeader == FileHeaderVersioned_002() || sHeader == FileHeaderVersioned_003())
                        {
                            //Configuration string previous v004 has [*]RFEGen mark, so it is necessary remove it.
                            int nIndRFEGen = sModelText.IndexOf(_RFEGEN_FILE_MODEL_Mark);
                            sModelText         = sModelText.Substring(nIndRFEGen + 1 + _RFEGEN_FILE_MODEL_Mark.Length);
                            nIndRFEGen         = sConfigurationText.IndexOf(_RFEGEN_FILE_MODEL_Mark);
                            sConfigurationText = sConfigurationText.Substring(nIndRFEGen + 1 + _RFEGEN_FILE_MODEL_Mark.Length);
                        }
                    }

                    if ((sHeader == FileHeaderVersioned_001() || sHeader == FileHeaderVersioned_002() ||
                         sHeader == FileHeaderVersioned_003() || sHeader == FileHeaderVersioned_004()) && (sConfigurationText.Contains(",")))
                    {
                        //From format v005, we always use "en-US" settings. User should create new file.
                        return(false);
                    }

                    //We initialize internal data only if the file was ok and of the right format
                    CleanAll();
                    m_arrData = new RFESweepData[nMaxDataIndex];

                    using (MemoryStream StreamDecompressed = new MemoryStream())
                    {
                        int          nUncompressedSize     = 0;         //total bytes after unzip file, or 0 if was never compressed
                        BinaryReader objBinReader          = binStream; //by default use file stream, but may change to memory if comes compressed
                        byte[]       arrUncompressedBuffer = null;
                        if ((sHeader != FileHeaderVersioned_001()) && (sHeader != FileHeaderVersioned_002()))
                        {
                            nUncompressedSize = (int)binStream.ReadInt32();
                            int nCompressedSize = (int)binStream.ReadInt32();
                            arrUncompressedBuffer = new byte[nUncompressedSize];

                            using (MemoryStream ms = new MemoryStream())
                            {
                                //if we are in version 3 or higher, data comes compressed, so we have to decompress first
                                byte[] gzBuffer = binStream.ReadBytes(nCompressedSize);
                                ms.Write(gzBuffer, 0, nCompressedSize);

                                ms.Position = 0;
                                using (GZipStream zip = new GZipStream(ms, CompressionMode.Decompress))
                                {
                                    zip.Read(arrUncompressedBuffer, 0, nUncompressedSize);
                                }
                                StreamDecompressed.Write(arrUncompressedBuffer, 0, nUncompressedSize);
                                StreamDecompressed.Position = 0;
                                objBinReader = new BinaryReader(StreamDecompressed);
                            }
                        }
                        //recreate all sweep data objects
                        for (UInt32 nSweepInd = 0; nSweepInd < nMaxDataIndex; nSweepInd++)
                        {
                            //Versions older than v004 need to add data point extra
                            UInt16 nTotalDataPointsFile = nTotalDataPoints;
                            if (m_eRFEDataType == RFEFileDataType.Normalization)
                            {
                                if (sHeader == FileHeaderVersioned_001() || sHeader == FileHeaderVersioned_002() || sHeader == FileHeaderVersioned_003())
                                {
                                    nTotalDataPoints++;
                                }
                            }
                            RFESweepData objRead = new RFESweepData((float)fStartFrequencyMHZ, (float)fStepFrequencyMHZ, nTotalDataPoints);

                            if (sHeader == FileHeaderVersioned_001())
                            {
                                objRead.CaptureTime = new DateTime(2000, 1, 1); //year 2000 means no actual valid date-time was captured
                            }
                            else
                            {
                                //Starting in version 002, load sweep capture time too
                                int    nLength = (int)objBinReader.ReadInt32();
                                string sTime   = "";
                                if ((sHeader == FileHeaderVersioned_001()) || (sHeader == FileHeaderVersioned_002()))
                                {
                                    sTime = (string)objBinReader.ReadString();
                                }
                                else
                                {
                                    //From v003 we need to decode byte to string for Date/time data
                                    byte[] arrText = objBinReader.ReadBytes(nLength);
                                    sTime = Encoding.ASCII.GetString(arrText);
                                }
                                if ((sTime.Length == nLength) && (nLength > 0))
                                {
                                    objRead.CaptureTime = DateTime.Parse(sTime);
                                }
                            }
                            float fLastPointValue = 0f;
                            for (UInt16 nDataPoint = 0; nDataPoint < nTotalDataPointsFile; nDataPoint++)
                            {
                                fLastPointValue = (float)objBinReader.ReadDouble();
                                objRead.SetAmplitudeDBM(nDataPoint, fLastPointValue);
                            }
                            if (m_eRFEDataType == RFEFileDataType.Normalization)
                            {
                                //Starting in v004. Fix the last point issue, we will add one point extra with the same amplitude value than previous one.
                                if (sHeader == FileHeaderVersioned_001() || sHeader == FileHeaderVersioned_002() || sHeader == FileHeaderVersioned_003())
                                {
                                    objRead.SetAmplitudeDBM((UInt16)(nTotalDataPoints - 1), fLastPointValue);
                                }
                            }
                            Add(objRead);
                        }
                        if (objBinReader != binStream)
                        {
                            objBinReader.Close();
                        }
                    }
                }
            }
            finally
            {
                if (myFile != null)
                {
                    myFile.Dispose();
                }
            }

            return(true);
        }