Пример #1
0
        public static void WhiteNoiseFilter(FFTs stft, double threshold, SelectedWindowIndices indices = null, bool dB = true)
        {
            List <Complex[]> data = stft.GetFFTs();

            (int timeIndex1, int timeIndex2, int freqIndex1, int freqIndex2) =
                indices != null?indices.Indices() : (0, data.Count, 0, stft.fftSize);

            threshold = dB ? Math.Pow(10, threshold / 20) : threshold;
            for (int n = timeIndex1; n < timeIndex2; n++)
            {
                for (int k = freqIndex1; k < freqIndex2; k++)
                {
                    if (data[n][k].Magnitude < threshold)
                    {
                        data[n][k].Real      = 0;
                        data[n][k].Imaginary = 0;
                    }
                }
            }
        }
Пример #2
0
        public static void AddGain(FFTs stft, double gain = 0, SelectedWindowIndices indices = null, bool dB = true)
        {
            (int timeIndex1, int timeIndex2, int freqIndex1, int freqIndex2) =
                indices != null?indices.Indices() : (0, stft.Count, 0, stft.fftSize);

            //Defaults to dB
            //Converts to linear gain for multiplying gain to data
            gain = dB ? Math.Pow(10, gain / 20) : gain;

            List <Complex[]> data = stft.GetFFTs();

            for (int n = timeIndex1; n < timeIndex2; n++)
            {
                for (int k = freqIndex1; k < freqIndex2; k++)
                {
                    data[n][k].Real      *= gain;
                    data[n][k].Imaginary *= gain;
                }
            }
        }
Пример #3
0
        private static void HighPassFilter(FFTs stft, double cutoff, SelectedWindowIndices indices = null)
        {
            (int timeIndex1, int timeIndex2, int freqIndex1, int freqIndex2) =
                indices != null?indices.Indices() : (0, stft.Count, 0, stft.fftSize / 2);

            List <Complex[]> data = stft.GetFFTs();
            int index_cutoff      = (int)(cutoff / stft.FreqResolution);

            for (int n = timeIndex1; n < timeIndex2; n++)
            {
                for (int k = freqIndex1; k < freqIndex2; k++)
                {
                    if (k <= index_cutoff)
                    {
                        data[n][k] = new Complex();
                        data[n][stft.fftSize - 1 - k] = new Complex(); //Mirrored side
                    }
                }
            }
        }
Пример #4
0
        public static void FrequencyShifter(FFTs stft, int freq_shift, SelectedWindowIndices indices = null, int order = 0, double thresh = 0.9)
        {
            int indexShift = freq_shift / stft.FreqResolution;

            if (indexShift == 0)
            {
                return;
            }

            (int timeIndex1, int timeIndex2, int freqIndex1, int freqIndex2) =
                indices != null?indices.Indices() : (0, stft.Count, 0, stft.fftSize);


            //Shift map tells how far each index is going to shift
            //Order of 0 results in a linear shifter
            //shift_mod gives a scaling factor to each shifted index
            int[]    shift_map = createFreqShiftMap(stft, indexShift, indices, order, thresh);
            double[] shift_mod = createFreqShiftModulation(stft, indexShift, indices);


            List <Complex[]> ffts = stft.GetFFTs();

            for (int n = timeIndex1; n < timeIndex2; n++)
            {
                Complex[] fft         = ffts[n];
                Complex[] shifted_fft = new Complex[fft.Length];
                for (int k = 0; k < fft.Length; k++)
                {
                    if (k + shift_map[k] >= 0 && k + shift_map[k] < fft.Length) //Ignore the ones that get shifted too far
                    {
                        shifted_fft[k + shift_map[k]] += fft[k] * shift_mod[k];
                    }
                }
                Array.Copy(shifted_fft, fft, fft.Length);
            }
        }