예제 #1
0
        // public void runSweep(double _fstart, double _fstop, bool _logsweep, int _steps, double delay, int _periods)
        public void runSweep()
        {
            if (running)
            {
                stop();
                dataFifo.flush();
            }

            fstart       = config.sweepFMin;
            fstop        = config.sweepFMax;
            logsweep     = config.sweepLogF;
            steps        = config.sweepPoints;
            periods      = config.sweepMPeriods;
            delaySamples = (int)Math.Floor(config.sweepLoopDelay * owner.sampleRate + 0.5);

            //fstart = _fstart;
            //fstop = _fstop;
            //logsweep = _logsweep;
            //steps = _steps;
            step    = 0;
            substep = 0;
            f       = fstart;

            dataFifo.flush();

            // delaySamples = (int) Math.Floor(delay * owner.sampleRate + 0.5);
            stopnow  = false;
            vnaState = VNAState.WaitDelay;
            running  = true;
        }
예제 #2
0
        private void init()
        {
            InitializeComponent();

            int h = Height;

            if (channels < 8)
            {
                ioB8.Hide(); h = ioB8.Location.Y;
            }
            if (channels < 7)
            {
                ioB7.Hide(); h = ioB7.Location.Y;
            }
            if (channels < 6)
            {
                ioB6.Hide(); h = ioB6.Location.Y;
            }
            if (channels < 5)
            {
                ioB5.Hide(); h = ioB5.Location.Y;
            }
            if (channels < 4)
            {
                ioB4.Hide(); h = ioB4.Location.Y;
            }
            if (channels < 3)
            {
                ioB3.Hide(); h = ioB3.Location.Y;
            }
            if (channels < 2)
            {
                ioB2.Hide(); h = ioB2.Location.Y;
            }
            if (channels == 1)
            {
                ioB1.title = "B";
            }
            Height = h;

            bnDisplayWin.buttonStateChanged += BnDisplayWin_buttonStateChanged;

            ow = null;

            vnaState = VNAState.Idle;
            running  = false;
            step     = 0;
            phi      = 0;

            BSINint = new double[channels];
            BCOSint = new double[channels];

            dataFifo = new DataPointFifo(32);

            processingType = ProcessingType.Sink;
        }
예제 #3
0
        public override void tick()
        {
            if (stopnow)
            {
                vnaState = VNAState.Idle;
                running  = false;
                return;
            }
            if (ow == null)
            {
                return;
            }
            if (!ow.initialized)
            {
                return;
            }

            if (vnaState == VNAState.Idle)
            {
                return;
            }

            SignalBuffer RF = getSignalOutputBuffer(ioRF);
            SignalBuffer A  = getSignalInputBuffer(ioA);

            // DataBuffer B = null;
            SignalBuffer[] B = new SignalBuffer[channels];
            if (channels > 0)
            {
                B[0] = getSignalInputBuffer(ioB1);
            }
            if (channels > 1)
            {
                B[1] = getSignalInputBuffer(ioB2);
            }
            if (channels > 2)
            {
                B[2] = getSignalInputBuffer(ioB3);
            }
            if (channels > 3)
            {
                B[3] = getSignalInputBuffer(ioB4);
            }
            if (channels > 4)
            {
                B[4] = getSignalInputBuffer(ioB5);
            }
            if (channels > 5)
            {
                B[5] = getSignalInputBuffer(ioB6);
            }
            if (channels > 6)
            {
                B[6] = getSignalInputBuffer(ioB7);
            }
            if (channels > 7)
            {
                B[7] = getSignalInputBuffer(ioB8);
            }

            double phisave = phi;
            double dphi    = 2.0 * Math.PI * f / owner.sampleRate;

            phi = phisave;
            int stepsave = substep;

            // Input Processing
            switch (vnaState)
            {
            case VNAState.WaitDelay:
                substep += owner.blockSize;
                if (substep > delaySamples)
                {
                    ASINint = ACOSint = 0;
                    for (int j = 0; j < channels; j++)
                    {
                        BSINint[j] = BCOSint[j] = 0;
                    }
                    vnaState = VNAState.Measuring;
                    substep  = 0;
                    intCount = (int)Math.Floor((double)periods * (double)owner.sampleRate / f + 0.5);
                }
                break;

            case VNAState.Measuring:
                phi     = phisave;
                substep = stepsave;
                if (A != null)
                {
                    for (int i = 0; i < owner.blockSize; i++)
                    {
                        if (substep < intCount)
                        {
                            double win = windowFunc(substep, intCount);
                            ASINint += A.data[i] * Math.Sin(phi) * win;
                            ACOSint += A.data[i] * Math.Cos(phi) * win;
                        }
                        substep++;
                        phi += dphi;
                    }
                }
                for (int j = 0; j < channels; j++)
                {
                    phi     = phisave;
                    substep = stepsave;
                    if (B[j] != null)
                    {
                        for (int i = 0; i < owner.blockSize; i++)
                        {
                            if (substep < intCount)
                            {
                                double win = windowFunc(substep, intCount);
                                BSINint[j] += B[j].data[i] * Math.Sin(phi) * win;
                                BCOSint[j] += B[j].data[i] * Math.Cos(phi) * win;
                            }
                            substep++;
                            phi += dphi;
                        }
                    }
                }

                substep = stepsave + owner.blockSize;
                if (substep >= intCount)
                {
                    // Process
                    DataPoint dp = new DataPoint(channels);

                    dp.f = f;
                    double scalef = 2.0 / ((double)intCount);
                    dp.A = new Complex(ASINint * scalef, ACOSint * scalef);
                    for (int j = 0; j < channels; j++)
                    {
                        dp.B[j] = new Complex(BSINint[j] * scalef, BCOSint[j] * scalef);
                    }
                    // Phase Correction
                    if (config.compPhaseBlocks != 0)
                    {
                        double  delay = (double)config.compPhaseBlocks * owner.blockSize / owner.sampleRate;    // in s
                        double  phase = -2.0 * Math.PI * delay * f;
                        Complex corr  = new Complex(Math.Cos(phase), Math.Sin(phase));
                        dp.A *= corr;
                    }
                    dataFifo.put(dp);

                    substep = 0;
                    step++;
                    if (step < steps)
                    {
                        // Continue
                        if (logsweep)
                        {
                            f = fstart * Math.Pow(fstop / fstart, (double)step / (steps - 1));
                        }
                        else
                        {
                            f = fstart + (double)step / (steps - 1) * (fstop - fstart);
                        }
                        vnaState = VNAState.WaitDelay;
                    }
                    else
                    {
                        // FInish
                        vnaState = VNAState.Idle;
                        running  = false;
                    }
                }
                break;
            }

            // Generator
            phi = phisave;
            if (RF != null)
            {
                if (vnaState != VNAState.Idle)
                {
                    for (int i = 0; i < owner.blockSize; i++)
                    {
                        RF.data[i] = Math.Sin(phi);
                        phi       += dphi;
                        if (phi > 2.0 * Math.PI)
                        {
                            phi -= 2 * Math.PI;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < owner.blockSize; i++)
                    {
                        RF.data[i] = 0;
                        phi       += dphi;
                        if (phi > 2.0 * Math.PI)
                        {
                            phi -= 2 * Math.PI;
                        }
                    }
                }
            }
        }