Represents a set of single phase power time-domain data.
Example #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="Cycle"/> class.
        /// </summary>
        /// <param name="startSample">The index of the start of the cycle.</param>
        /// <param name="frequency">The frequency of the measured system, in Hz.</param>
        /// <param name="waveFormData">The time-domain data to be used to calculate frequency-domain values.</param>
        public Cycle(int startSample, double frequency, MeasurementData waveFormData)
        {
            long timeStart;

            double[] timeInSeconds;
            double[] measurements;
            SineWave sineFit;

            if (startSample < 0)
            {
                throw new ArgumentOutOfRangeException("startSample");
            }

            if (startSample + waveFormData.SampleRate > waveFormData.Times.Length)
            {
                throw new ArgumentOutOfRangeException("startSample");
            }

            if (startSample + waveFormData.SampleRate > waveFormData.Measurements.Length)
            {
                throw new ArgumentOutOfRangeException("startSample");
            }

            timeStart     = waveFormData.Times[startSample];
            timeInSeconds = new double[waveFormData.SampleRate];
            measurements  = new double[waveFormData.SampleRate];

            for (int i = 0; i < waveFormData.SampleRate; i++)
            {
                timeInSeconds[i] = Ticks.ToSeconds(waveFormData.Times[i + startSample] - timeStart);
                measurements[i]  = waveFormData.Measurements[i + startSample];
            }

            sineFit = WaveFit.SineFit(measurements, timeInSeconds, frequency);

            RMS       = Math.Sqrt(measurements.Select(vi => vi * vi).Average());
            Phase     = sineFit.Phase - PiOverTwo;
            Peak      = sineFit.Amplitude;
            Frequency = frequency;

            Error = timeInSeconds
                    .Select(time => sineFit.CalculateY(time))
                    .Zip(measurements, (calc, measurement) => Math.Abs(calc - measurement))
                    .Sum();
        }
        private void CalculateSampleRate(double frequency, MeasurementData measurementData)
        {
            long[] times;
            long   startTicks;
            long   endTicks;
            double cycles;

            // Get the collection of measurement timestamps
            times = measurementData.Times;

            // Determine the start and end time of the data set
            startTicks = times[0];
            endTicks   = times[times.Length - 1];

            // Determine the number of cycles in the file,
            // based on the system frequency
            cycles = frequency * Ticks.ToSeconds(endTicks - startTicks);

            // Calculate the number of samples per cycle
            measurementData.SampleRate = (int)Math.Round(times.Length / cycles);
        }
 /// <summary>
 /// Creates a new <see cref="MeasurementDataSet"/>.
 /// </summary>
 public MeasurementDataSet()
 {
     AN = new MeasurementData();
     BN = new MeasurementData();
     CN = new MeasurementData();
 }
        private void CalculateSampleRate(double frequency, MeasurementData measurementData)
        {
            long[] times;
            long startTicks;
            long endTicks;
            double cycles;

            // Get the collection of measurement timestamps
            times = measurementData.Times;

            // Determine the start and end time of the data set
            startTicks = times[0];
            endTicks = times[times.Length - 1];

            // Determine the number of cycles in the file,
            // based on the system frequency
            cycles = frequency * Ticks.ToSeconds(endTicks - startTicks);

            // Calculate the number of samples per cycle
            measurementData.SampleRate = (int)Math.Round(times.Length / cycles);
        }
 /// <summary>
 /// Creates a new <see cref="MeasurementDataSet"/>.
 /// </summary>
 public MeasurementDataSet()
 {
     AN = new MeasurementData();
     BN = new MeasurementData();
     CN = new MeasurementData();
 }
Example #6
0
        /// <summary>
        /// Creates a new instance of the <see cref="Cycle"/> class.
        /// </summary>
        /// <param name="startSample">The index of the start of the cycle.</param>
        /// <param name="frequency">The frequency of the measured system, in Hz.</param>
        /// <param name="waveFormData">The time-domain data to be used to calculate frequency-domain values.</param>
        public Cycle(int startSample, double frequency, MeasurementData waveFormData)
        {
            long timeStart;
            double[] timeInSeconds;
            double[] measurements;
            SineWave sineFit;

            if (startSample < 0)
                throw new ArgumentOutOfRangeException("startSample");

            if (startSample + waveFormData.SampleRate > waveFormData.Times.Length)
                throw new ArgumentOutOfRangeException("startSample");

            if (startSample + waveFormData.SampleRate > waveFormData.Measurements.Length)
                throw new ArgumentOutOfRangeException("startSample");

            timeStart = waveFormData.Times[startSample];
            timeInSeconds = new double[waveFormData.SampleRate];
            measurements = new double[waveFormData.SampleRate];

            for (int i = 0; i < waveFormData.SampleRate; i++)
            {
                timeInSeconds[i] = Ticks.ToSeconds(waveFormData.Times[i + startSample] - timeStart);
                measurements[i] = waveFormData.Measurements[i + startSample];
            }

            sineFit = WaveFit.SineFit(measurements, timeInSeconds, frequency);

            RMS = Math.Sqrt(measurements.Select(vi => vi * vi).Average());
            Phase = sineFit.Phase - PiOverTwo;
            Peak = sineFit.Amplitude;
            Frequency = frequency;

            Error = timeInSeconds
                .Select(time => sineFit.CalculateY(time))
                .Zip(measurements, (calc, measurement) => Math.Abs(calc - measurement))
                .Sum();
        }