Ejemplo n.º 1
0
        public override ISignal CreateSignal()
        {
            var fi = new FileInfo(this.FileName);

            if (!fi.Exists)
            {
                return(null);
            }

            var file = File.ReadLines(this.FileName);

            var frequencies = new List <double>();
            var values      = new List <Complex>();

            double frequency;
            double mag;
            double phase;

            foreach (var line in file)
            {
                var fields = line.Split(',');

                if (fields.Length < 2)
                {
                    continue;
                }

                if (!double.TryParse(fields[0], NumberStyles.Any, CultureInfo.InvariantCulture, out frequency))
                {
                    continue;
                }

                if (!double.TryParse(fields[1], NumberStyles.Any, CultureInfo.InvariantCulture, out mag))
                {
                    continue;
                }

                if (fields.Length == 2)
                {
                    frequencies.Add(frequency);
                    values.Add(mag);
                }
                else if (fields.Length == 3)
                {
                    if (!double.TryParse(fields[1], NumberStyles.Any, CultureInfo.InvariantCulture, out phase))
                    {
                        continue;
                    }

                    frequencies.Add(frequency);
                    values.Add(Complex.FromPolarCoordinates(mag, phase));
                }
            }

            var series = new FftSeries(this.SampleRate, this.SignalLength);
            var ret    = Dsp.AdaptiveInterpolation(frequencies, values, series.Values.ToReadOnlyList(), false).ToReadOnlyList();

            return(new FiniteSignal(new FftSpectrum(series, ret), this.TimeOffset));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="FftSpectrum" /> class.
 /// </summary>
 /// <param name="frequencies">The frequencies.</param>
 /// <param name="values">The values.</param>
 public FftSpectrum(FftSeries frequencies, IReadOnlyList <Complex> values) : base(frequencies, values)
 {
     this.Frequencies = frequencies;
 }