Exemplo n.º 1
0
        public Waveform Clone()
        {
            Waveform newWaveform = new Waveform(this.secondsPerSample, this.maximumDataPoints, this.maximumVoltageForPlots);

            for (int i = 0; i < this.maximumDataPoints; i++)
            {
                newWaveform.data[i] = this.data[i];
            }
            return(newWaveform);
        }
Exemplo n.º 2
0
 public Waveform ApplySampling(double newSamplingInMhz)
 {
     checked
     {
         double totalWaveformTime = this.maximumDataPoints * this.secondsPerSample;
         // Calculate parameters for the new waveform and create it
         double   newSecondsPerSample = 1 / (1E6 * newSamplingInMhz);
         double   newNumberSamples    = totalWaveformTime / newSecondsPerSample;
         int      newNumberSamplesInt = (int)newNumberSamples;               // For debugging
         Waveform resultWaveform      = new Waveform(secondsPerSample, newNumberSamplesInt, this.maximumVoltageForPlots);
         for (int newSampleIndex = 0; newSampleIndex < newNumberSamplesInt; newSampleIndex++)
         {
             double sampleTime     = ((double)newSampleIndex) * newSecondsPerSample;
             double oldSampleIndex = sampleTime / this.secondsPerSample;
             resultWaveform.data[newSampleIndex] = this.data[(int)oldSampleIndex];
         }
         return(resultWaveform);
     }
 }
Exemplo n.º 3
0
        public Waveform ApplyCompensation(double resistorValue, double capacitorValue, int timestepsPerSample)
        {
            Waveform resultWaveform = new Waveform(secondsPerSample, maximumDataPoints, this.maximumVoltageForPlots);
            double   capacitorCharge = 0, capacitorVoltage = 0;
            double   secondsPerTimeStep = secondsPerSample / timestepsPerSample;

            for (int sampleNumber = 0; sampleNumber < maximumDataPoints; sampleNumber++)
            {
                double inputVoltage = data[sampleNumber];
                for (int timeStepNumber = 0; timeStepNumber < timestepsPerSample; timeStepNumber++)
                {
                    double currentThroughResistor = (inputVoltage - capacitorVoltage) / resistorValue;
                    capacitorCharge  = capacitorCharge + currentThroughResistor * secondsPerTimeStep;
                    capacitorVoltage = capacitorCharge / capacitorValue;
                }
                resultWaveform.data[sampleNumber] = capacitorVoltage;
            }
            return(resultWaveform);
        }
Exemplo n.º 4
0
        private void RedrawGraphs(bool replaceData)
        {
            if (replaceData || (stage1 == null))
            {
                // Find the time per symbol based on user's selection
                double symbolFrequency = 0;
                if (signalSource1Button.Checked)
                {
                    symbolFrequency = 480E6;
                }
                else if (signalSource2Button.Checked)
                {
                    symbolFrequency = 5E9;
                }
                else if (signalSource3Button.Checked)
                {
                    symbolFrequency = 2.133E9;
                }
                else
                {
                    string c = DateTime.Now.ToString("h:mm:ss tt");
                    statusBox.AppendText($"{c} Invalid symbol frequency \r\n");
                    symbolFrequency = 2E9;
                }

                double timePerSymbol = 1 / symbolFrequency;
                double timePerSample = timePerSymbol / numberSamplesPerSymbol;
                int    numberSamples = (int)(numberSymbols * numberSamplesPerSymbol);

                // CREATE STAGE 1 - Go for 480 Mhz, 2 nanosec/cycle, 10 bits, 20 nsec, 20 samples per bit
                stage1 = new Waveform(timePerSample, numberSamples, 250);
                Random r           = new Random();
                int    sampleIndex = 0;
                for (int symbolNumber = 0; symbolNumber < numberSymbols; symbolNumber++)
                {
                    int symbolValue = r.Next(2);   // Upper bound is exclusive, so this is 0 or 1
                    for (int symbolSample = 0; symbolSample < numberSamplesPerSymbol; symbolSample++)
                    {
                        stage1.data[sampleIndex++] = symbolValue * 200;
                    }
                }
            }
            stage1.PlotWaveform(stage1Chart);

            Waveform stage2 = stage1.Clone();

            stage2.PlotWaveform(stage2Chart);

            // Sample 1k-ohm, 10nF, gives 15.9Khz
            // 1 / (2 * pi * RC) = frequency

            // RC = (1 / (2 * pi * f))  f=1E9
            // RC = 1.59E-10    Assume C = 10 pF
            // R = 1.59E-10 / (10E-12)
            // R=15.9


            // Figure out desired cutoff frequency
            double desiredCutoff = -1;

            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();

            if (probe1SelectedButton.Checked)
            {
                desiredCutoff = 4E9;
                // probeImage.ImageLocation = @"C:\temp\tek\P7240.png";
                System.IO.Stream file =
                    thisExe.GetManifestResourceStream("PickProbe.Resources.P7240.png");
                this.probeImage.Image = Image.FromStream(file);
            }
            else if (probe2SelectedButton.Checked)
            {
                desiredCutoff = 2.5E9;
                System.IO.Stream file =
                    thisExe.GetManifestResourceStream("PickProbe.Resources.P7225.png");
                this.probeImage.Image = Image.FromStream(file);
            }
            else if (probe3SelectedButton.Checked)
            {
                desiredCutoff = 1.5E9;
                System.IO.Stream file =
                    thisExe.GetManifestResourceStream("PickProbe.Resources.P6248.png");
                this.probeImage.Image = Image.FromStream(file);
            }
            else if (probe4SelectedButton.Checked)
            {
                desiredCutoff = 220E6;
                System.IO.Stream file =
                    thisExe.GetManifestResourceStream("PickProbe.Resources.P2220.png");
                this.probeImage.Image = Image.FromStream(file);
            }
            else if (probe5SelectedButton.Checked)
            {
                desiredCutoff = 100E6;
                System.IO.Stream file =
                    thisExe.GetManifestResourceStream("PickProbe.Resources.P3010.png");
                this.probeImage.Image = Image.FromStream(file);
            }

            else if (probe6SelectedButton.Checked)
            {
                double myResult;
                if (double.TryParse(probeMhzAlternate.Text, out myResult) == false)
                {
                    return;
                }
                if (myResult < 1)
                {
                    return;
                }
                desiredCutoff = myResult * 1E6;
            }
            string currentTime = DateTime.Now.ToString("h:mm:ss tt");

            statusBox.AppendText($"{currentTime} cutoff= {desiredCutoff / 1E6} Mhz\r\n");
            statusBox.SelectionStart = statusBox.TextLength;
            statusBox.ScrollToCaret();

            // Puts below at 100 Mhz
            double resistor  = 159;
            double capacitor = 10E-12;

            // Adjust capacitor to desired value
            capacitor = capacitor * (100E6 / desiredCutoff);        // Higher desired cutoff = lower capacitance

            // Create Stage3
            Waveform stage3 = stage2.ApplyRCFilter(resistor, capacitor, 20);

            stage3.PlotWaveform(stage3Chart);

            Waveform stage4 = stage3.Clone();

            if (compensationCorrectCompButton.Checked)
            {
            }

            else if (compensationUnderCompButton.Checked)
            {
                stage4 = stage3.ApplyRCFilter(15.9, 10E-12, 20);
            }

            else if (compenstationOverCompButton.Checked)
            {
                Waveform temp = stage3.ApplyRCFilter(15.9, 10E-12, 20);
                stage4 = stage3.Clone();
                for (int i = 0; i < stage4.maximumDataPoints; i++)
                {
                    stage4.data[i] = stage4.data[i] + (stage3.data[i] - temp.data[i]);
                }
            }

            stage4.PlotWaveform(stage4Chart);

            // DO sampling
            Waveform stage5 = stage4.ApplySampling(500);

            stage5.PlotWaveform(stage5Chart, SeriesChartType.Point);
        }