예제 #1
0
파일: MainForm.cs 프로젝트: AKorney/astu
        private void button1_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter           = "txt files (*.txt)|*.txt";
                ofd.InitialDirectory = @"D:\stud_repo\astu\DS\FourierTransform\FourierTransform\test";
                ofd.RestoreDirectory = true;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var profileKey = Regex.Replace(Path.GetFileNameWithoutExtension(ofd.FileName), "[0-9]", "");
                    if (!_profiles.ContainsKey(profileKey))
                    {
                        profileKey = "default";
                    }

                    var rawContent   = File.ReadAllText(ofd.FileName);
                    var splittedText = rawContent.Split(new Char[] { '\n', '\r', ' ' }, StringSplitOptions.RemoveEmptyEntries);


                    _rawSource = splittedText.Select((item, index) => new SignalPoint {
                        X = index, Y = Convert.ToDouble(item.Replace(".", ","))
                    }).ToList();

                    _transformedSource = SignalConverter.ConvertWithProfile(_rawSource, _profiles[profileKey]);

                    sourceChart.DataSource = _transformedSource;
                    sourceChart.Series["SourceSignal"].XValueMember  = "X";
                    sourceChart.Series["SourceSignal"].YValueMembers = "Y";

                    sourceChart.ChartAreas["ChartArea1"].AxisX.Title = _profiles[profileKey].XLabel;
                    sourceChart.ChartAreas["ChartArea1"].AxisY.Title = _profiles[profileKey].YLabel;
                    sourceChart.DataBind();
                }
            }
        }
예제 #2
0
파일: FiltersForm.cs 프로젝트: AKorney/astu
        public List <SignalPoint> ReadWav(string path)
        {
            try
            {
                using (FileStream wavStream = new FileStream(path,
                                                             FileMode.Open, FileAccess.Read))
                {
                    int readHeader = wavStream.Read(head, 0, H);
                    int length     =
                        (((int)head[43]) << 24) +
                        (((int)head[42]) << 16) +
                        (((int)head[41]) << 8) +
                        (int)head[40];

                    var content = new byte[length];
                    wavStream.Read(content, 0, length);
                    List <SignalRepresentation.SignalPoint> rawwav = new List <SignalRepresentation.SignalPoint>();

                    for (int i = 0; i < length / 2; i++)
                    {
                        byte byteOne = content[i * 2];
                        byte byteTwo = content[i * 2 + 1];
                        rawwav.Add(new SignalPoint {
                            X = i, Y = (int)(short)(byteOne | byteTwo << 8)
                        });
                    }
                    return(SignalConverter.ConvertWithProfile(rawwav, wav));
                }
            }
            catch (FileNotFoundException ex)
            {
                return(null);
            }
        }
예제 #3
0
        private List <SignalPoint> ReadData(string path, string profile)
        {
            List <SignalPoint> sourceSignal;
            var rawContent   = File.ReadAllText(path);
            var splittedText = rawContent.Split(new Char[] { '\n', '\r', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            //List<SignalPoint> rawSignal = new List<SignalPoint>();
            //for (int i = 0; i < splittedText.Length; i++)
            //{
            //    rawSignal.Add(new SignalPoint { X = i, Y = Convert.ToDouble(splittedText[i].Replace(".", ",")) });
            //}
            List <SignalPoint> rawSignal = splittedText.Select((item, index) => new SignalPoint {
                X = index, Y = Convert.ToDouble(item)
            }).ToList();

            sourceSignal = SignalConverter.ConvertWithProfile(rawSignal, _profiles[profile]);
            return(sourceSignal);
        }