Beispiel #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Sinc" /> class.
        /// </summary>
        /// <param name="sampleRate">The sample rate.</param>
        /// <param name="frequency">The frequency.</param>
        /// <exception cref="System.Exception"></exception>
        public Sinc(double sampleRate, double frequency) : base(time => Dsp.Sinc(frequency * time / sampleRate), sampleRate)
        {
            this.Frequency = frequency;
            if ((frequency < 0) || (frequency > sampleRate / 2))
            {
                throw new Exception();
            }

            var frequencies = new CustomSeries(new[] { 0, frequency, frequency, sampleRate / 2 });

            this.Spectrum    = new Spectrum.Spectrum(frequencies, new Complex[] { 1 / (2 * frequency), 1 / (2 * frequency), 0, 0 });
            this.DisplayName = "sinc, f = " + frequency;
        }
Beispiel #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="IdealLowpass" /> class.
        /// </summary>
        /// <param name="sampleRate">The sample rate.</param>
        /// <param name="fc">The corner frequency.</param>
        /// <exception cref="System.Exception"></exception>
        public IdealLowpass(double sampleRate, double fc) : base(time => Dsp.Sinc(2 * fc * time / sampleRate) * (2 * fc / sampleRate), sampleRate)
        {
            if ((fc < 0) || (fc > sampleRate / 2))
            {
                throw new Exception();
            }

            this.Fc = fc;
            var frequencies = new CustomSeries(new[] { 0, 20, fc, fc, sampleRate / 2 });

            this.Spectrum    = new Spectrum.Spectrum(frequencies, new Complex[] { 1, 1, 1, 0, 0 });
            this.DisplayName = "ideal lowpass, fc = " + fc;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Sinus"/> class.
        /// </summary>
        /// <param name="sampleRate">The sample rate.</param>
        /// <param name="frequency">The frequency.</param>
        /// <param name="phaseOffset">The phase offset in radians.</param>
        /// <exception cref="System.Exception"></exception>
        public Sinus(double sampleRate, double frequency, double phaseOffset = 0)
            : base(time => Math.Sin(2 * Math.PI * time * frequency / sampleRate + phaseOffset), sampleRate)
        {
            this.Frequency   = frequency;
            this.PhaseOffset = phaseOffset;
            if ((frequency < 0) || (frequency > sampleRate / 2))
            {
                throw new Exception();
            }

            var frequencies = new CustomSeries(new[] { 0, frequency, frequency, frequency, sampleRate / 2 });

            this.Spectrum    = new Spectrum.Spectrum(frequencies, new Complex[] { 0, 0, double.PositiveInfinity, 0, 0 });
            this.DisplayName = "sinus, f = " + frequency;
        }
        private void AddGraph(SelectXYDataWindow sw)
        {
            bool         readstart = false;
            CustomSeries srs       = new CustomSeries();

            srs.ChartArea = "ChartArea1";
            srs.ChartType = SeriesChartType.Line;
            srs.Name      = sw.ParamName;
            srs.XName     = sw.ParamXName;
            chart.Series.Add(srs);

            if (sw.Errorindex >= 0)
            {
                CustomSeries errsrs = new CustomSeries();
                errsrs.ChartArea = "ChartArea1";
                errsrs.ChartType = SeriesChartType.ErrorBar;
                errsrs.Error     = true;
                errsrs.Name      = sw.ParamErrName;
                errsrs.XName     = sw.ParamXName;
                errsrs.Parent    = sw.ParamName;
                chart.Series.Add(errsrs);
            }
            foreach (string line in File.ReadLines("feffdat/BTdat.dat", BTMainForm.CharEncode))
            {
                //選択した行を探す
                if (sw.Line == 0)
                {
                    if (!readstart && line.IndexOf("Eexp_0") >= 0)
                    {
                        readstart = true;
                        continue;
                    }
                }
                if (sw.Line == 1)
                {
                    if (!readstart && line.IndexOf("Eexp_1") >= 0)
                    {
                        readstart = true;
                        continue;
                    }
                }
                if (sw.Line == 2)
                {
                    if (!readstart && line.IndexOf("f(R)_SS") >= 0)
                    {
                        readstart = true;
                        continue;
                    }
                }
                if (sw.Line == 3)
                {
                    if (!readstart && line.IndexOf("kbg") >= 0)
                    {
                        readstart = true;
                        continue;
                    }
                }

                if (readstart)
                {
                    string[] d = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    //読み込み終わり
                    if (d.Count() < 5)
                    {
                        break;
                    }
                    //それぞれ読み込む
                    double x = double.Parse(d[sw.Xindex]);
                    double y = double.Parse(d[sw.Yindex]);
                    if (sw.Errorindex >= 0)
                    {
                        double err = double.Parse(d[sw.Errorindex]);
                        chart.Series[chart.Series.Count - 2].Points.Add(new DataPoint(x, y));                                    //グラフにデータ追加
                        chart.Series[chart.Series.Count - 1].Points.Add(new DataPoint(x, new double[] { y, y - err, y + err })); //グラフにデータ追加
                        chart.Series[chart.Series.Count - 1].Points.Last()["ErrorBarCenterMarkerStyle"] = "Circle";
                        chart.Series[chart.Series.Count - 1].Points.Last()["ErrorBarSeries"]            = "Exp";
                    }
                    else
                    {
                        chart.Series[chart.Series.Count - 1].Points.Add(new DataPoint(x, y));   //グラフにデータ追加
                    }
                }
            }
        }