private void showImpulceCharacteristicButton_Click(object sender, EventArgs e) { try { int n = (int)impulceCharacteristicNNumericUpDown.Value; double threshold = (double)impulceCharacteristicThresholdNumericUpDown.Value; var windowType = GetFourierTransformType(); var impCharType = (FirFilterType)Enum.Parse(typeof(FirFilterType), (string)impulseCharacteristicTypeComboBox.SelectedItem); double[] h = FiniteImpulseResponse.ImpulseCharacteristic(signal.Hz, n, threshold, impCharType, windowType); var form = new ShowSpectrumForm(h, " Импульсная характеристика", SpectrumType.NotSet, n); form.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// パラメータを指定して新しい OverSampling クラスのインスタンスを初期化します。 /// </summary> /// <param name="samplingRate">サンプリング周波数。これはオーバーサンプリング後の周波数となります。</param> /// <param name="magnification">サンプリング倍率。</param> /// <param name="stereo">ステレオである場合は true、モノラルである場合は false。</param> /// <param name="filterSize">フィルタサイズ。</param> public OverSampling(double samplingRate, int magnification, bool stereo, int filterSize) { if (samplingRate <= 0.0) { throw new ArgumentOutOfRangeException("samplingRate"); } if (magnification <= 0) { throw new ArgumentOutOfRangeException("magnification"); } if (filterSize <= 0) { throw new ArgumentOutOfRangeException("filterSize"); } if (filterSize % 2 != 0) { throw new ArgumentException(); } this.samplingRate = samplingRate; this.magnification = magnification; this.stereo = stereo; this.filterSize = filterSize; this.filter = new SoundFilter(stereo, filterSize); var filterGenerator = new LowPassFilter() { SamplingRate = samplingRate * magnification, CutoffFrequency = samplingRate / 2 - FiniteImpulseResponse.GetDelta(samplingRate * magnification, filterSize) }; double[] impulse = filterGenerator.Generate(filterSize / 2); Window.Blackman(impulse); filter.SetFilter(impulse); }
private void hPFilterButton_Click(object sender, EventArgs e) { try { int n = (int)hPImpulceCharacteristicNNumericUpDown.Value; double threshold = (double)hPImpulceCharacteristicThresholdNumericUpDown.Value; double[] filteredData = FiniteImpulseResponse.FirFilter(signal.Data, signal.Hz, n, threshold, FirFilterType.HighPass); if (saveToFileCheckBox.Checked) { WriteDataToFile(filteredData); } var form = new ShowChartForm(filteredData, filePath + " ВЧ фильтр", signal.Type, signal.Hz); form.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void showPhaseResponseButton_Click(object sender, EventArgs e) { Stopwatch watch = new Stopwatch(); try { var impCharType = (FirFilterType)Enum.Parse(typeof(FirFilterType), (string)impulseCharacteristicTypeComboBox.SelectedItem); int n = (int)impulceCharacteristicNNumericUpDown.Value; double threshold = (double)impulceCharacteristicThresholdNumericUpDown.Value; watch.Start(); double[] h = FiniteImpulseResponse.ImpulseCharacteristic(signal.Hz, n, threshold, impCharType); double[] phaseSpec = FiniteImpulseResponse.PhaseResponse(h, signal.Hz); watch.Stop(); var form = new ShowSpectrumForm(phaseSpec, "ФЧX", SpectrumType.Phase, signal.Hz, watch.ElapsedMilliseconds); form.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void showFrequencyResponseDButton_Click(object sender, EventArgs e) { Stopwatch watch = new Stopwatch(); try { int n = (int)impulceCharacteristicNNumericUpDown.Value; double threshold = (double)impulceCharacteristicThresholdNumericUpDown.Value; var windowType = GetFourierTransformType(); var impCharType = (FirFilterType)Enum.Parse(typeof(FirFilterType), (string)impulseCharacteristicTypeComboBox.SelectedItem); watch.Start(); double[] h = FiniteImpulseResponse.ImpulseCharacteristic(signal.Hz, n, threshold, impCharType, windowType); double[] amplSpec = FiniteImpulseResponse.FrequencyResponse(h, signal.Hz); watch.Stop(); var form = new ShowSpectrumForm(amplSpec, "АЧX", SpectrumType.AmplitudeDecibels, signal.Hz, watch.ElapsedMilliseconds); form.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }