Пример #1
0
    private void Start()
    {
        //jeden kanal
        wahwah                  = musicCube.GetComponent <WahWahFilter>();
        wahwah.QValue           = 1.5f;
        wahwah.CutOffFrequency  = 300.0f;
        wahwah.FrequencyRange   = 800.0f;
        lowpass                 = musicCube.GetComponent <LowPassFilter>();
        lowpass.CutOffFrequency = 400.0f;
        lowpass.QValue          = 0.5f;


        //drugi kanal
        envelope                 = musicCube.GetComponent <EnvelopGenerator>();
        envelope.AttackRate      = 0.15f * 44100.0f;
        envelope.DecayRate       = 0.15f * 44100.0f;
        envelope.SustainLevel    = 0.6f;
        envelope.ReleaseRate     = 0.1f * 44100.0f;
        highpass                 = musicCube.GetComponent <HighPassFilter>();
        highpass.QValue          = 0.5f;
        highpass.CutOffFrequency = 300.0f;
        bandpass                 = musicCube.GetComponent <BandPassFilter>();
        bandpass.centreFrequency = 350.0f;
        bandpass.q               = 0.4f;
        bandpass.BandPassFilterConstantPeakGain();
        vibrato           = musicCube.GetComponent <VibratoFilter>();
        vibrato.delay     = 0.2f;
        vibrato.depth     = 0.03f;
        vibrato.frequency = 0.8f;
    }
        private void btnAddFilter_Click(object sender, RoutedEventArgs e)
        {
            Filter filter = null;

            switch ((sender as FrameworkElement).Name)
            {
            case "btnAddLPF": filter = new LowPassFilter(Filter.DefaultN, (double)globalSampleRate / 4); break;

            case "btnAddHPF": filter = new HighPassFilter(Filter.DefaultN, (double)globalSampleRate / 4); break;

            case "btnAddBPF": filter = new BandPassFilter(Filter.DefaultN, (double)globalSampleRate / 8, (double)globalSampleRate * 3 / 8); break;

            case "btnAddBSF": filter = new BandStopFilter(Filter.DefaultN, (double)globalSampleRate / 8, (double)globalSampleRate * 3 / 8); break;

            case "btnAddMF": filter = new AverageFilter(Filter.DefaultN); break;

            case "btnAddZPass": filter = new ZFilterPass(ZFilterPass.DefaultR, (double)globalSampleRate / 4); break;

            case "btnAddZPass1": filter = new ZFilterPass1(ZFilterPass1.DefaultR, (double)globalSampleRate / 4); break;

            case "btnAddNotch": filter = new NotchFilter(NotchFilter.DefaultR1, NotchFilter.DefaultR2, (double)globalSampleRate / 4); break;

            default: return;
            }

            filter.PropertyChanged += new PropertyChangedEventHandler(Filter_PropertyChanged);

            filters.Add(filter);
            filtersList.SelectedIndex = filters.IndexOf(filter);

            updateResult();
        }
Пример #3
0
        public void ApplyTest()
        {
            int n          = 16384;
            int sampleRate = 1000;

            double f1 = 22;
            double f2 = 300;

            Signal cosine = new CosineGenerator(f1, 1, sampleRate).Generate(n);
            Signal sine   = new SineGenerator(f2, 1, sampleRate).Generate(n);

            var merge = new AddFilter(cosine);

            merge.Normalize = true;
            Signal original = merge.Apply(sine);

            var of1 = FindFrequencyCount(sampleRate, original, f1);
            var of2 = FindFrequencyCount(sampleRate, original, f2);

            Assert.AreEqual(0.359128660199268, of1, 1e-8);
            Assert.AreEqual(0.47955332752802149, of2, 1e-8);

            Signal lowFiltered1 = new LowPassFilter(f1, sampleRate).Apply(original);
            Signal lowFiltered2 = new LowPassFilter(f2, sampleRate).Apply(original);

            Signal highFiltered1 = new HighPassFilter(f1, sampleRate).Apply(original);
            Signal highFiltered2 = new HighPassFilter(f2, sampleRate).Apply(original);

            var lf11 = FindFrequencyCount(sampleRate, lowFiltered1, f1);
            var lf12 = FindFrequencyCount(sampleRate, lowFiltered1, f2);

            Assert.AreEqual(0.24589601823749971, lf11, 1e-8); // should be higher
            Assert.AreEqual(0.038266797164259778, lf12, 1e-8);
            Assert.IsTrue(lf11 > lf12);

            var lf21 = FindFrequencyCount(sampleRate, lowFiltered2, f1);
            var lf22 = FindFrequencyCount(sampleRate, lowFiltered2, f2);

            Assert.AreEqual(0.35642263929018364, lf21, 1e-8); // should not have much difference
            Assert.AreEqual(0.271181864130875, lf22, 1e-8);

            var hf11 = FindFrequencyCount(sampleRate, highFiltered1, f1);
            var hf12 = FindFrequencyCount(sampleRate, highFiltered1, f2);

            Assert.AreEqual(0.24542517074628975, hf11, 1e-8);  // should not have much difference
            Assert.AreEqual(0.44797847700473359, hf12, 1e-8);

            var hf21 = FindFrequencyCount(sampleRate, highFiltered2, f1);
            var hf22 = FindFrequencyCount(sampleRate, highFiltered2, f2);

            Assert.AreEqual(0.026113299330488803, hf21, 1e-8);
            Assert.AreEqual(0.23279968506488344, hf22, 1e-8); // should be higher
            Assert.IsTrue(hf22 > hf21);

            Assert.AreEqual(16384, cosine.Duration.TotalMilliseconds);
            Assert.AreEqual(16384, sine.Duration.TotalMilliseconds);
            Assert.AreEqual(16384, original.Duration.TotalMilliseconds);
        }
        public void ApplyTest()
        {
            int n          = 16384;
            int sampleRate = 1000;

            double f1 = 22;
            double f2 = 300;

            Signal cosine = new CosineGenerator(f1, 1, sampleRate).Generate(n);
            Signal sine   = new SineGenerator(f2, 1, sampleRate).Generate(n);

            var merge = new AddFilter(cosine);

            merge.Normalize = true;
            Signal original = merge.Apply(sine);

            var of1 = FindFrequencyCount(sampleRate, original, f1);
            var of2 = FindFrequencyCount(sampleRate, original, f2);

            Assert.AreEqual(2.1919473889115457E-05, of1, 1e-8);
            Assert.AreEqual(2.9269612275882952E-05, of2, 1e-8);

            Signal lowFiltered1 = new LowPassFilter(f1, sampleRate).Apply(original);
            Signal lowFiltered2 = new LowPassFilter(f2, sampleRate).Apply(original);

            Signal highFiltered1 = new HighPassFilter(f1, sampleRate).Apply(original);
            Signal highFiltered2 = new HighPassFilter(f2, sampleRate).Apply(original);

            var lf11 = FindFrequencyCount(sampleRate, lowFiltered1, f1);
            var lf12 = FindFrequencyCount(sampleRate, lowFiltered1, f2);

            Assert.AreEqual(1.5008301894378632E-05, lf11, 1e-8); // should be higher
            Assert.AreEqual(2.33561994410787E-06, lf12, 1e-8);
            Assert.IsTrue(lf11 > lf12);

            var lf21 = FindFrequencyCount(sampleRate, lowFiltered2, f1);
            var lf22 = FindFrequencyCount(sampleRate, lowFiltered2, f2);

            Assert.AreEqual(2.1754311480113727E-05, lf21, 1e-8); // should not have much difference
            Assert.AreEqual(1.6551627449395776E-05, lf22, 1e-8);

            var hf11 = FindFrequencyCount(sampleRate, highFiltered1, f1);
            var hf12 = FindFrequencyCount(sampleRate, highFiltered1, f2);

            Assert.AreEqual(1.4979563644182712E-05, hf11, 1e-8);  // should not have much difference
            Assert.AreEqual(2.7342436340623498E-05, hf12, 1e-8);

            var hf21 = FindFrequencyCount(sampleRate, highFiltered2, f1);
            var hf22 = FindFrequencyCount(sampleRate, highFiltered2, f2);

            Assert.AreEqual(1.5938293048394034E-06, hf21, 1e-8);
            Assert.AreEqual(1.420896515288728E-05, hf22, 1e-8); // should be higher
            Assert.IsTrue(hf22 > hf21);

            Assert.AreEqual(16384, cosine.Duration.TotalMilliseconds);
            Assert.AreEqual(16384, sine.Duration.TotalMilliseconds);
            Assert.AreEqual(16384, original.Duration.TotalMilliseconds);
        }
Пример #5
0
 private void highPassFilterButton_Click(object sender, EventArgs e)
 {
     if (otherFiltersInputImgBox.Image != null)
     {
         var inputBitmap = new Bitmap(otherFiltersInputImgBox.Image);
         var highPassFilterMaskClient = new HighPassFilter(inputBitmap,
                                                           Settings.Default.StoreAsColorWherePossible);
         otherFiltersOutputImgBox.Image = highPassFilterMaskClient.Filter();
     }
 }
Пример #6
0
        public void HighPassFilterComputesCorrectly()
        {
            int      _period = 5;
            DateTime time    = DateTime.Now;

            decimal[] actualValues = new decimal[20];

            HighPassFilter hpf = new HighPassFilter(_period);

            # region Arrays inputs
Пример #7
0
        public static BitArray Decompose(IDemodulator demodulator, WavFile wavFile)
        {
            var samples = wavFile.Data.ToShortArray();

            samples = new Trimmer().Trim(samples);

            var hpFilter = new HighPassFilter(
                cutoffFrequency: demodulator.CarrierFrequency / 2.0,
                sampleRate: demodulator.SampleRate
                );

            //   samples = hpFilter.FilterSamples(samples);

            samples = new Normalizer().PeakNormalize(samples);

            //   samples = new PhaseFixer().FixPhase(samples, (int)demodulator.SampleRate, 2);

            //

            var soundBytes     = samples.ToByteArray();
            var processedSound = new WavFile(wavFile.SampleRate, soundBytes);

            using (FileStream fs = new FileStream($"PROCESSED.wav", FileMode.Create)) {
                BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(processedSound.ToBytes());
            }

            //

            var waveDecomposer = new WaveDecomposer(demodulator);

            var      dataSegments = waveDecomposer.FindDataSegments(samples);
            BitArray data         = null;

            foreach (var segment in dataSegments)
            {
                var bits = demodulator.ReadBits(segment.DataSamples, segment.ZerosValue, segment.OnesValue, segment.BytesToRead);

                if (data == null)
                {
                    data = new BitArray(bits);
                }
                else
                {
                    data = data.MergeWith(bits);
                }
            }

            return(data);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AutocorrelogramPeriodogram"/> class.
        /// </summary>
        /// <param name="name">The name of this indicator</param>
        /// <param name="shortPeriod">The period of the low pass filter cut off frequency.</param>
        /// <param name="longPeriod">The period of the high pass filter cut off frequency.</param>
        /// <param name="correlationWidth">Number of pair observations used to estimate the autocorrelation coefficients.</param>
        public AutocorrelogramPeriodogram(string name, int shortPeriod, int longPeriod, int correlationWidth)
            : base(name, correlationWidth)
        {
            _shortPeriod      = shortPeriod;
            _longPeriod       = longPeriod;
            _bandwidth        = longPeriod - shortPeriod;
            _correlationWidth = correlationWidth;
            _decayFactor      = EstimateDecayFactor(_shortPeriod, _longPeriod);

            hpf             = new HighPassFilter(longPeriod);
            sSmoother       = new SuperSmoother(shortPeriod);
            sSmootherWindow = new RollingWindow <double>(longPeriod + _correlationWidth);

            R = Vector <double> .Build.Dense(_bandwidth + 1, 1d);
        }
Пример #9
0
        public void ResetsProperly()
        {
            int _period = 5;
            DateTime time = DateTime.Now;

            HighPassFilter hpf = new HighPassFilter(_period);

            for (int i = 0; i < 6; i++)
            {
                hpf.Update(new IndicatorDataPoint(time, 1m));
                time.AddMinutes(1);
            }
            Assert.IsTrue(hpf.IsReady, "SuperSmoother ready");
            hpf.Reset();
            TestHelper.AssertIndicatorIsInDefaultState(hpf);
        }
Пример #10
0
        public void sample_test()
        {
            string basePath = NUnit.Framework.TestContext.CurrentContext.TestDirectory;
            string pathWhereTheDatasetShouldBeStored = Path.Combine(basePath, "mfcc");

            #region doc_example1
            // Let's say we would like to analyse an audio sample. To give an example that
            // could be reproduced by anyone without having to give a specific sound file
            // that would need to have been downloaded by every user trying to run this example,
            // we will use obtain an example from the Free Spoken Digits Dataset instead:
            var fsdd = new FreeSpokenDigitsDataset(path: pathWhereTheDatasetShouldBeStored);

            // Let's obtain one of the audio signals:
            Signal a          = fsdd.GetSignal(0, "jackson", 10);
            int    sampleRate = a.SampleRate; // 8000

            // Note: if you would like to load a signal from the
            // disk, you could use the following method directly:
            // Signal a = Signal.FromFile(fileName);

            // Create a high-pass filter to keep only frequencies above 2000 Hz
            var filter = new HighPassFilter(frequency: 2000, sampleRate: sampleRate);

            // Apply the filter to the signal
            Signal result = filter.Apply(a);

            // Create a spectrogram for the original
            var sourceSpectrum = new Spectrogram(a);

            // Create a spectrogram for the filtered signal:
            var resultSpectrum = new Spectrogram(result);

            // Get the count for a high frequency before and after the high-pass filter:
            double before = sourceSpectrum.GetFrequencyCount(windowIndex: 0, frequency: 100); // 0.0015747246599406217
            double after  = resultSpectrum.GetFrequencyCount(windowIndex: 0, frequency: 100); // 7.7444174980265885E-05
            #endregion

            Assert.AreEqual(0.0015747246599406217, before, 1e-8);
            Assert.AreEqual(7.7444174980265885E-05, after, 1e-8);
        }
Пример #11
0
        public void HighPassFilterComputesCorrectly()
        {
            int _period = 5;
            DateTime time = DateTime.Now;
            decimal[] actualValues = new decimal[20];

            HighPassFilter hpf = new HighPassFilter(_period);

            # region Arrays inputs
            decimal[] prices = new decimal[20]
            {
                /*
                 * Formula:
                 * prices[i] = 10 * sin(2 * pi / 20 * i) + 15
                 * i = [0, 1, 2,..., 19]
                 */
                15m, 18.09m, 20.88m, 23.09m, 24.51m, 25m, 24.51m, 23.09m, 20.88m, 18.09m,
                15m, 11.91m, 9.12m, 6.91m, 5.49m, 5m, 5.49m, 6.91m, 9.12m, 11.91m
            };

            decimal[] expectedValues = new decimal[20]
            {
                // Estimated with Python:
                0m, 0m, 0m, -0.1946m, -0.3266m, -0.4106m, -0.4506m, -0.4444m, -0.3945m, -0.3084m,
                -0.1884m, -0.052m, 0.0889m, 0.224m, 0.3338m, 0.4121m, 0.4509m, 0.4445m, 0.3945m, 0.3084m
            };
            # endregion

            for (int i = 0; i < prices.Length; i++)
            {
                hpf.Update(new IndicatorDataPoint(time, prices[i]));
                actualValues[i] = Math.Round(hpf.Current.Value, 4);
                Console.WriteLine(actualValues[i]);
                time.AddMinutes(1);
            }
            Assert.AreEqual(expectedValues, actualValues, "Estimation HighPassFilter(5)");
        }
Пример #12
0
        private void HandleFilterTypeChange(FilterChange message)
        {
            bpFilter = message.BPFilter;
            hpFilter = message.HPFilter;
            lpFilter = message.LPFilter;
            switch (message.FilterType)
            {
            case FilterType.None:
                Become(ProcessNone);
                break;

            case FilterType.HighPass:
                Become(ProcessHighPass);
                break;

            case FilterType.LowPass:
                Become(ProcessLowPass);
                break;

            case FilterType.BandPass:
                Become(ProcessBandPass);
                break;
            }
        }
Пример #13
0
        public static Signal AplicarFiltroPassaAlta(Signal sinal)
        {
            var highPassFilter = new HighPassFilter(0.9f);

            return(highPassFilter.Apply(sinal));
        }
Пример #14
0
 /// <summary>
 /// Constructs a new instance of <see cref="BandPassFilter"/>.
 /// </summary>
 public BandPassFilter(float low, float high)
 {
     _hi = new HighPassFilter(low);
     _lo = new LowPassFilter(high);
 }
        /// <summary>
        /// Process a buffer of sample data
        /// </summary>
        /// <param name="buffer">The samples need to be process</param>
        /// <returns>A array of result with the interval of 100ms</returns>
        public void ProcessBuffer(double[][] buffer, Action <double, double> progressUpdated)
        {
            // Clone the buffer
            double[][] clone = new double[buffer.Length][];
            for (int i = 0; i < buffer.Length; i++)
            {
                clone[i] = (double[])buffer[i].Clone();
            }
            buffer = clone;

            // “K” frequency weighting
            PreFilter.ProcessBuffer(buffer);
            HighPassFilter.ProcessBuffer(buffer);

            // Init the process
            int bufferPosition    = 0;
            int bufferSampleCount = buffer[0].Length;

            while (bufferPosition + (StepSampleCount - StepBufferPosition) < bufferSampleCount)
            {
                progressUpdated?.Invoke(bufferPosition, bufferSampleCount);
                // Enough to fill a step
                for (int channel = 0; channel < NumChannel; channel++)
                {
                    Array.Copy(buffer[channel], bufferPosition, StepBuffer[channel], StepBufferPosition, StepSampleCount - StepBufferPosition);
                }
                bufferPosition += StepSampleCount - StepBufferPosition;

                // Swap buffer
                double[][] temp = BlockBuffer[0];
                for (int i = 1; i < BlockBuffer.Length; i++)
                {
                    BlockBuffer[i - 1] = BlockBuffer[i];
                }
                BlockBuffer[BlockBuffer.Length - 1] = StepBuffer;
                StepBuffer         = temp;
                StepBufferPosition = 0;

                // Calc momentory loudness
                double momentaryMeanSquare = 0;
                if (BlockBuffer[0] != null)
                {
                    for (int channel = 0; channel < NumChannel; channel++)
                    {
                        double channelSquardSum = 0;
                        for (int step = 0; step < BlockStepCount; step++)
                        {
                            double[][] stepBuffer = BlockBuffer[step];
                            for (int sample = 0; sample < StepSampleCount; sample++)
                            {
                                double squared = Math.Pow(stepBuffer[channel][sample], 2);
                                channelSquardSum += squared;
                            }
                        }
                        double channelMeanSquare = channelSquardSum / (BlockStepCount * StepSampleCount);
                        double channelWeight     = GetChannelWeight(channel);
                        momentaryMeanSquare += channelWeight * channelMeanSquare;
                    }
                }
                else
                {
                    momentaryMeanSquare = 0;
                }
                double momentaryLoudness = -0.691 + 10 * Math.Log10(momentaryMeanSquare);
                MomentaryLoudnessUpdated?.Invoke(momentaryLoudness);

                if (ShortTermLoudnessUpdated != null)
                {
                    // Calc short-term loudness
                    ShiftBuffer(ShortTermMeanSquares);
                    ShortTermMeanSquares[ShortTermMeanSquares.Length - 1] = momentaryMeanSquare;

                    double shortTermMeanSquaresSum = 0;
                    for (int i = 0; i < ShortTermMeanSquares.Length; i++)
                    {
                        shortTermMeanSquaresSum += ShortTermMeanSquares[i];
                    }
                    double shortTermMeanSquareMean = shortTermMeanSquaresSum / ShortTermMeanSquares.Length;
                    double shortTermLoudness       = -0.691 + 10 * Math.Log10(shortTermMeanSquareMean);
                    ShortTermLoudnessUpdated?.Invoke(shortTermLoudness);
                }

                // Calc integrated loudness
                if (IsIntegrating)
                {
                    MeanSquareLoudness meanSquareLoudness = new MeanSquareLoudness
                    {
                        MeanSquare = momentaryMeanSquare,
                        Loudness   = momentaryLoudness
                    };
                    PrecedingMeanSquareLoudness.Add(meanSquareLoudness);
                }
            }

            // Process remaining samples
            int remainingLength = buffer[0].Length - bufferPosition;

            for (int channel = 0; channel < NumChannel; channel++)
            {
                Array.Copy(buffer[channel], bufferPosition, StepBuffer[channel], StepBufferPosition, remainingLength);
            }
            StepBufferPosition = remainingLength;
        }
Пример #16
0
        private static async Task TestBrainDeviceManager()
        {
            var cfg       = ClientConfig.GetConfig();
            var lowFilter = new LowPassFilter()
            {
                LowPassRate = 10
            };
            var highFilter = new HighPassFilter()
            {
                HighPassRate = 10000
            };
            var bPassFilter = new BandPassFilter()
            {
                LowCutoffRate = 20, HighCutoffRate = 30
            };
            var bStopFilter = new BandStopFilter()
            {
                LowPassRate = 35, HighPassRate = 38
            };
            var mFilter = new MedianFilter()
            {
                HalfMedianWindowSize = 7
            };
            var bandFilter = new BandPassStopFilter
            {
                BandFilterList = new List <BandFilter> {
                    lowFilter, highFilter, bPassFilter, bStopFilter
                }
            };

            bandFilter.Disable = true;
            var allFilter = new FilterTypeList()
            {
                Filters = new List <FilterType> {
                    bandFilter, mFilter
                }
            };
            var filterParameters = new Dictionary <string, string>
            {
                { FilterTypeList.FIRhalfOrderOptionName, 10.ToString() }
            };

            cfg.FilterLst = allFilter;
            IOnlineFilter         filter     = null;
            WaveletReconstruction waveletRec = null;

            cfg.WaveletRecCfg = new WaveletReconstructionConfig
            {
                AvgLevel          = 8,
                ConvolutionMode   = ConvolutionModeEnum.Normal,
                ExtensionMode     = SignalExtension.ExtensionMode.SymmetricHalfPoint,
                Level             = 8,
                MotherWaveletName = "db5",
                WindowSize        = 15
            };
            cfg.WriteToFile(ClientConfig.DefaultConfigFileName);


            BrainDeviceManager.Init();
            var sender = await BrainDeviceManager.Connnect("127.0.0.1", 9211);

            BrainDevState currentState = default(BrainDevState);

            //保证设备参数正常才继续跑逻辑
            BrainDeviceManager.BrainDeviceState.Subscribe(ss =>
            {
                currentState = ss;
                filterParameters.Update(
                    FilterTypeList.SampleRateOptionName,
                    BrainDevState.SampleCountPer1Sec(ss.SampleRate).ToString()
                    );
                //AppLogger.Debug($"Brain Device State Changed Detected: {ss}");
            }, () =>
            {
                AppLogger.Debug("device stop detected");
            });
            int totalReceived    = 0;
            var medianFilter     = OnlineFirFilter.CreateDenoise(7);
            var fastMedianFilter = new OnlineFastMedianFilter(3);

            BrainDeviceManager.SampleDataStream.Subscribe(tuple =>
            {
                var(order, datas, arr) = tuple;
                //Console.Write($" {order} ");
                var passTimes = BrainDevState.PassTimeMs(currentState.SampleRate, totalReceived) / 1000;
                var intArr    = datas.CopyToArray();
                var val       = intArr[0];
                var voltage   = BitDataConverter.Calculatevoltage(val, 4.5f, currentState.Gain);
                totalReceived++;
                var m1 = medianFilter.ProcessSample(voltage);
                var m2 = fastMedianFilter.ProcessSample(voltage);
                AppLogger.Debug($"passTimes:{passTimes},val:{val},voltage:{voltage},median filter:{m1},fast:{m2},{m1==m2}");
                if (filter == null)
                {
                    filter     = allFilter.CreateFilter(filterParameters);
                    waveletRec = cfg.WaveletRecCfg.Create(
                        BrainDevState.SampleCountPer1Sec(currentState.SampleRate));
                    waveletRec.ReconstructionStream.Subscribe(reconstruct =>
                    {
                        var(vol, tim) = reconstruct;
                        AppLogger.Debug($"wavelet reconstruction:{vol} at {tim}");
                    });
                }
                waveletRec?.BufferData((voltage, passTimes));
                AppLogger.Debug($"filter processed:{filter.ProcessSample(voltage)}");
                //AppLogger.Debug($"order:{order}");
                //AppLogger.Debug($"converted values:{datas.Show()}");
                //AppLogger.Debug($"original datas:{arr.Show()}");
            }, () =>
            {
                AppLogger.Debug("device sampling stream closed detected");
            });

            var cmdResult = await sender.QueryParam();

            AppLogger.Debug("QueryParam result:" + cmdResult);
            if (cmdResult != CommandError.Success)
            {
                AppLogger.Error("Failed to QueryParam, stop");
                BrainDeviceManager.DisConnect();
                return;
            }


            cmdResult = await sender.SetFilter(true);

            AppLogger.Debug("SetFilter result:" + cmdResult);

            cmdResult = await sender.SetTrap(TrapSettingEnum.Trap_50);

            AppLogger.Debug("SetTrap result:" + cmdResult);

            cmdResult = await sender.SetSampleRate(SampleRateEnum.SPS_2k);

            AppLogger.Debug("SetSampleRate result:" + cmdResult);

            cmdResult = await sender.QueryParam();

            AppLogger.Debug("QueryParam result:" + cmdResult);

            cmdResult = await sender.QueryFaultState();

            AppLogger.Debug("QueryFaultState result:" + cmdResult);

            cmdResult = await sender.TestSingleImpedance(1);

            AppLogger.Debug("TestSingleImpedance result:" + cmdResult);

            cmdResult = await sender.TestMultiImpedance(30);

            AppLogger.Debug("TestMultiImpedance result:" + cmdResult);

            Console.ReadLine();
            var fs = new FileResource(currentState, 19801983, 1, BrainDeviceManager.BufMgr);

            fs.StartRecord(BrainDeviceManager.SampleDataStream);
            cmdResult = await sender.Start();

            if (cmdResult != CommandError.Success)
            {
                AppLogger.Error("Failed to start sampler");
            }
            else
            {
                AppLogger.Debug($"start receive sample data");
                await Task.Delay(1000 *10);

                AppLogger.Debug($"stoping");
                await sender.Stop();

                AppLogger.Debug($"stop receive sample data");
                await Task.Delay(1000);
            }

            BrainDeviceManager.DisConnect();
            fs.Dispose();

            var readf = new FileSampleData(fs.ResourceId, BrainDeviceManager.BufMgr);

            Console.WriteLine($"expecte to read {totalReceived} blocks");
            Console.WriteLine($"start reading saved sampling data");
            int readCount = 0;

            readf.DataStream.Subscribe(tuple =>
            {
                var(order, datas, arr) = tuple;
                Console.Write($" {order} ");
                readCount++;
                //AppLogger.Debug($"order:{order}");
                //AppLogger.Debug($"converted values:{datas.Show()}");
                //AppLogger.Debug($"original datas:{arr.Show()}");
            }, () =>
            {
                AppLogger.Debug($"read sampling data file end,count :{readCount},expected count:{totalReceived}");
            });
            readf.Start();
            await Task.Delay(1000 *10);

            Console.Write($"wait complete");
        }
Пример #17
0
 public ConfigHighPassFilter(DSP dsp)
     : base(dsp)
 {
     myDSP = (HighPassFilter)dsp;
     Initialize();
 }
Пример #18
0
 public ConfigHighPassFilter(DSP dsp)
     : base(dsp)
 {
     myDSP = (HighPassFilter)dsp;
     Initialize();
 }