Exemplo n.º 1
0
        public static float[] ValuesByWindow(int frameSIZE, bool causal, WindowType windowType)
        {
            switch (windowType)
            {
            case WindowType.Rectangle:
                return(SignalWindow.Rectangle(frameSIZE, causal));


            case WindowType.VonnHann:
                return(SignalWindow.VonHann(frameSIZE, causal));

            case WindowType.Hamming:
                return(SignalWindow.Hamming(frameSIZE, causal));

            default:

                return(SignalWindow.Rectangle(frameSIZE, causal));
            }
        }
Exemplo n.º 2
0
        public static float[] MultiplyByWindow(float[] data, bool causal, WindowType windowType)
        {
            switch (windowType)
            {
            case WindowType.Rectangle:
                return(SignalWindow.RectangleMultiply(data, causal));


            case WindowType.VonnHann:
                return(SignalWindow.VonHannMultiply(data, causal));

            case WindowType.Hamming:
                return(SignalWindow.HammingMultiply(data, causal));

            default:

                return(SignalWindow.RectangleMultiply(data, causal));
            }
        }
Exemplo n.º 3
0
 public static float[] CreateImpulseSignal(int size, float cutOffFrequency, int sampleRate, WindowType windowType, bool causal)
 {
     return(SignalWindow.MultiplyByWindow(CreateImpulseSignal(size, cutOffFrequency, sampleRate), causal, windowType));
 }
Exemplo n.º 4
0
        public static float[] SignalFilterFreq(float[] signal, int frameSize, int frameOffset,
                                               int filterSize, float filterCutoff, WindowType windowType, bool causal)
        {
            float[] impulse = Helper.CreateImpulseSignal(filterSize, filterCutoff, 44100);

            int powerTwo = 0;

            for (int p = 2; p <= 120000; p *= 2)
            {
                if (p >= frameSize + impulse.Length - 1)
                {
                    powerTwo = p;
                    break;
                }
            }
            float[] filter = new float[powerTwo];
            if (causal)
            {
                filter = Helper.AddZerosAfter(impulse, powerTwo - impulse.Length);
            }
            else
            {
                filter = Helper.AddZerosInMiddle(impulse, powerTwo - impulse.Length);
            }



            float[][] frames    = CreateFrames(signal, frameSize, frameOffset);
            float[]   result    = new float[signal.Length + filter.Length - frameSize];
            Complex[] fftFilter = filter.Select(v => new Complex(v, 0)).ToArray();


            fftFilter = Audio.Classes.AudioHelper.FFT(fftFilter, true);


            float[] windowValues = SignalWindow.ValuesByWindow(frameSize, true, windowType);


            for (int i = 0; i < frames.Length; i++)
            {
                float[] frame = new float[frameSize];

                for (int j = 0; j < frame.Length; j++)
                {
                    frame[j] = frames[i][j] * windowValues[j];    // każda ramka wymnożona przez wartości okna
                }

                float[] frameWithZeros = AddZerosAfter(frame, filter.Length - frames[i].Length); // uzupełniamy zerami na końcu ramki

                float[] appliedFilter = FilterPerFrameFreq(frameWithZeros, fftFilter);

                for (int j = 0; j < appliedFilter.Length; j++)
                {
                    result[i * frameOffset + j] += appliedFilter[j];
                }
            }

            float multi = 1 / result.Max();

            for (int i = 0; i < result.Length; i++)
            {
                result[i] *= multi;
            }

            return(result);
        }