/// <summary> /// Method to handle user's selection in frequency domain /// passes selected samples to concolution filter. /// </summary> /// <param name="method"></param> public void filterSelectedFrequencies(FILTERING method = FILTERING.convolution) { if (freqSelStart == freqSelEnd) { return; } double[] filter = new double[fourierN]; for (int fbin = 0; fbin < filter.Length; fbin++) { if ((fbin >= freqSelStart && fbin <= freqSelEnd) || (fbin >= fourierN - freqSelEnd && fbin <= fourierN - freqSelStart)) { filter[fbin] = 0; } else { filter[fbin] = 1; } } double criticalPoint = 0; if (method == FILTERING.IIRLowpass) { criticalPoint = freqSelStart * SampleRate / fourierN; } else { criticalPoint = freqSelEnd * SampleRate / fourierN; } for (int channel = 0; channel < wave.channels; channel++) { switch (method) { case FILTERING.convolution: wave.samples[channel] = Formulas.convolveFilter(ref wave.samples[channel], filter); break; case FILTERING.DFT: wave.samples[channel] = Formulas.dftFilter(wave.samples[channel], filter); break; case FILTERING.IIRLowpass: //low pass wave.samples[channel] = Formulas.IIRFilter(wave.samples[channel], Math.Min(criticalPoint + 5000, SampleRate / 2), Math.Max(0, criticalPoint - 5000), 0, SampleRate); break; case FILTERING.IIRHighpass: //high pass wave.samples[channel] = Formulas.IIRFilter(wave.samples[channel], Math.Max(0, criticalPoint - 7000), Math.Min(criticalPoint + 3000, SampleRate / 2), 1, SampleRate); break; default: MessageBox.Show("Error occured"); break; } } timeDomain.setSamples(wave.samples); timeDomain.Invalidate(); calculateDFT(); invalidPlayer = true; }