Take the 2-minute tour ×

I tried to get fft and then get dft of a wave using this code:

        string s = textBox1.Text;
        double[] source = SourceToDouble(s);
        listBox2.DataSource = source;
        ToPowerOfTwo(ref source);
        List<Complex> Source = DoubleToComplex(source);
        Complex[] sou = Source.ToArray();
        FourierTransform.FFT(sou, FourierTransform.Direction.Forward);
        listBox1.DataSource = sou;
        FourierTransform.DFT(sou, FourierTransform.Direction.Forward);


private double[] SourceToDouble(string s)
        List<double> Final = new List<double>();

        EricOulashin.WAVFile audioFile = new EricOulashin.WAVFile();
        String warning = audioFile.Open(s, WAVFile.WAVFileMode.READ);
        if (warning == "")
            short audioSample = 0;
                audioSample = audioFile.GetNextSampleAs16Bit();
            throw new Exception(warning);

        return Final.ToArray();

ToPowerOfTwo(ref source):

private void ToPowerOfTwo(ref double[] source)
        List<long> TwoPowers = GetTwoPowers(100);
        long pCount = 0;

            if (source.Count() <= TwoPowers[i])
                pCount = TwoPowers[i];

        List<double> f = new List<double>(source);

        while (f.Count < pCount)
        source = f.ToArray();


private static List<Complex> DoubleToComplex(double[] source)
        List<Complex> Source = new List<Complex>();
        foreach (double dob in source)
            Complex c = new Complex(dob, 0.0);
        return Source;


 private void DoPlaySound(Complex[] c)
            FourierTransform.DFT(c, FourierTransform.Direction.Forward);
            double wav = c[0].Re;
            List<double> Big = ToBigger(100000, new double[] { wav });
            MakeWavFile(Big, "tmp.wav");
            System.Media.SoundPlayer s = new SoundPlayer("tmp.wav");

the problem is this: when I give a wav file to general code, after a long time the method trying to play the final wav (tmp.wav) but it isn't like the general file.

Update 1:

I also tried FourierTransform.DFT(sou, FourierTransform.Direction.Backward); but it didn't work too!

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

An FFT of an entire audio file is not a good way of analyzing voice or other non-stationary information. It would also be very slow. A more common technique would be to analyse short overlapping frames of a few to few dozen milliseconds in length using shorter FFTs, or to process successive frames using overlap-add/save FFT fast convolution.

A single IFFT would be the proper inverse function to an FFT. Otherwise you might end up with a mis-scaled backwards result.

share|improve this answer
I didn't understand correct! I think you mean that I divide my wave array and analyse it part by part. Do I understand correct? –  ahmadali shafiee Apr 3 '12 at 18:37
add comment

It seems you are running a forward DFT three times on your data between reading it and playing it. So of course it's not going to sound like the original.

share|improve this answer
then what am I have to do? –  ahmadali shafiee Apr 1 '12 at 1:55
You only get back to the original data if you run one forward DFT and one backward DFT. –  Oli Charlesworth Apr 1 '12 at 1:56
thanks. trying... –  ahmadali shafiee Apr 1 '12 at 2:03
but it's still too slow. there isn't any solution for it? –  ahmadali shafiee Apr 1 '12 at 2:04
@ahmadalishafiee: Taking the DFT/FFT of an entire wavefile is likely to be slow (well, it depends on the size of the file). Why do you want to do this? –  Oli Charlesworth Apr 1 '12 at 2:05
show 3 more comments

I would rewrite the DoubleToComplex function as:

    private static Complex[] DoubleToComplex(double[] source)
        Complex[] complexSource = new Complex[source.Length];
            complexSource[i] = new Complex(source[i], 0.0);                
        return complexSource;

Why first create a list to create all the Complex object, to bring it later on back to an Array? To use an Array from the beginning is more efficient.

share|improve this answer
that's not the answer of why it doesn't work you just optimize it! –  ahmadali shafiee Apr 17 '12 at 8:20
add comment

Your Answer


