Example #1
0
        private void Measure()
        {
            // allocate space for the results
            int tracePointsPerStep = (int)(frequencyStep / 100E3); // truncates towards 0

            results.numberOfTracePoints = rxFrequencyRamp.Length * tracePointsPerStep + 1;
            results.noiseFloorTraces    = new double[bandwidths.Length][][];
            results.maxHoldTraces       = new double[bandwidths.Length][];
            for (int i = 0; i < bandwidths.Length; i++)
            {
                results.noiseFloorTraces[i] = new double[numberOfRuns][];
                for (int j = 0; j < numberOfRuns; j++)
                {
                    results.noiseFloorTraces[i][j] = Enumerable.Repeat(double.NegativeInfinity, results.numberOfTracePoints).ToArray();
                }
                results.maxHoldTraces[i] = Enumerable.Repeat(double.NegativeInfinity, results.numberOfTracePoints).ToArray();
            }
            // process data from producer
            for (int i = 0; i < numberOfRuns; i++)
            {
                for (int j = 0; j < rxFrequencyRamp.Length; j++)
                {
                    ComplexWaveform <ComplexDouble> iqData; // for compatibility with pre c# 7 code
                    if (queue.TryTake(out iqData, timeout.ToTimeSpan()))
                    {
                        double iqRate = 1 / iqData.PrecisionTiming.SampleInterval.TotalSeconds;
                        /// Call LabVIEW built DLL for filtering the data.
                        /// The VI is set to shared clone re-entrant, therefore we can manage execution thread from C#.
                        Parallel.For(0, bandwidths.Length, bandwidthIndex =>
                        {
                            double[] powerTrace = LVFilters.ComplexFilter(iqRate, vbw, 1000, bandwidths[bandwidthIndex], 70, iqData.GetScaledData());
                            // sort the trace from high to low
                            int[] indexes = Enumerable.Range(0, powerTrace.Length).ToArray();
                            Array.Sort(powerTrace, indexes, Comparer <double> .Create(new Comparison <double>((i1, i2) => i2.CompareTo(i1)))); // sort decending
                            // take the first (max) values of the sorted power trace and sort again according to index
                            int recordTracePoints = tracePointsPerStep;
                            if (j == rxFrequencyRamp.Length - 1)
                            {
                                recordTracePoints++;
                            }
                            Array.Sort(indexes, powerTrace, 0, recordTracePoints); // sorts just the points we are interested in
                            // evaluate the max hold of the result
                            for (int k = 0; k < recordTracePoints; k++)
                            {
                                int traceIndex = j * tracePointsPerStep + k;
                                results.noiseFloorTraces[bandwidthIndex][i][traceIndex] = powerTrace[k];
                                results.maxHoldTraces[bandwidthIndex][traceIndex]       = Math.Max(results.maxHoldTraces[bandwidthIndex][traceIndex], powerTrace[k]);
                            }
                        });
                    }
                }
            }
            measurementCompleteEvent.Set();
        }
Example #2
0
 private void Measure()
 {
     results.frequencyRamp = new double[frequencyRamp.Length];
     results.measuredPower = new double[frequencyRamp.Length];
     results.measuredGain  = new double[frequencyRamp.Length];
     for (int i = 0; i < frequencyRamp.Length; i++)
     {
         results.frequencyRamp[i] = frequencyRamp[i]; // copying the frequency ramp array prevents modification by the user
         ComplexDouble[] rawIQ;
         if (queue.TryTake(out rawIQ, timeout.ToTimeSpan()))
         {
             results.measuredPower[i] = SignalAnalysis.CalculatePower(rawIQ).Average();
             results.measuredGain[i]  = results.measuredPower[i] - sgPowerLevel;
         }
     }
     measurementCompleteEvent.Set();
 }