質問

私はリアルタイムで基本周波数を取得するために、高と低域通過フィルタを実装するためのFFTを行ってきています。

今、私は、フィルタを適用した後、.wavファイルに記録することができるようにしたい。

まず私は、FFTを反転する必要がありますし、それは私の質問です。 これを行うための手順を教えてください。

私はこのプロジェクトの中で定義されたFFTを使用しています。

ここではそのためのコードは次のとおりです。

using System;
using System.Collections.Generic;
using System.Text;

namespace SoundLog
{
    public class FourierTransform
    {
        static private int n, nu;

        static private int BitReverse(int j)
        {
            int j2;
            int j1 = j;
            int k = 0;
            for (int i = 1; i <= nu; i++)
            {
                j2 = j1 / 2;
                k = 2 * k + j1 - 2 * j2;
                j1 = j2;
            }
            return k;
        }

        static public double[] FFT(ref double[] x)
        {
            // Assume n is a power of 2
            n = x.Length;
            nu = (int)(Math.Log(n) / Math.Log(2));
            int n2 = n / 2;
            int nu1 = nu - 1;
            double[] xre = new double[n];
            double[] xim = new double[n];
            double[] magnitude = new double[n2];
            double[] decibel = new double[n2];
            double tr, ti, p, arg, c, s;
            for (int i = 0; i < n; i++)
            {
                xre[i] = x[i];
                xim[i] = 0.0f;
            }
            int k = 0;
            for (int l = 1; l <= nu; l++)
            {
                while (k < n)
                {
                    for (int i = 1; i <= n2; i++)
                    {
                        p = BitReverse(k >> nu1);
                        arg = 2 * (double)Math.PI * p / n;
                        c = (double)Math.Cos(arg);
                        s = (double)Math.Sin(arg);
                        tr = xre[k + n2] * c + xim[k + n2] * s;
                        ti = xim[k + n2] * c - xre[k + n2] * s;
                        xre[k + n2] = xre[k] - tr;
                        xim[k + n2] = xim[k] - ti;
                        xre[k] += tr;
                        xim[k] += ti;
                        k++;
                    }
                    k += n2;
                }
                k = 0;
                nu1--;
                n2 = n2 / 2;
            }
            k = 0;
            int r;
            while (k < n)
            {
                r = BitReverse(k);
                if (r > k)
                {
                    tr = xre[k];
                    ti = xim[k];
                    xre[k] = xre[r];
                    xim[k] = xim[r];
                    xre[r] = tr;
                    xim[r] = ti;
                }
                k++;
            }
            for (int i = 0; i < n / 2; i++)
                //magnitude[i] = (float)(Math.Sqrt((xre[i] * xre[i]) + (xim[i] * xim[i])));
                decibel[i] = 10.0 * Math.Log10((float)(Math.Sqrt((xre[i] * xre[i]) + (xim[i] * xim[i]))));
            //return magnitude;
            return decibel;
        }
    }
}
役に立ちましたか?

解決

の周りに非常に多くの本当に良いFFTの実装がありますなど、 FFTW に私は非常に1を使用することをお勧めしています。彼らは同様にIFFTが付属しています。あなたは、実行されるような、耐え難いほど遅くなります。

他のヒント

あなたの正確なFFTとIFFTの定義によっては、違いが唯一の定数です。あなたのケースでその定数を決定する最も簡単な方法は、おそらくトライアル&エラーです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top