繁体   English   中英

如何从Accord.NET中的Signal对象创建ComplexSignal对象?

[英]How do I create a ComplexSignal object from a Signal object in Accord.NET?

我正在尝试对由.wav文件产生的信号执行FFT,该文件具有1个通道和64064个样本(16k时约4秒)。 我正在使用Accord.NET和以下代码来尝试创建ComplexSignal对象,这是执行FFT所必需的。

string fileName = "mu1.wav"; //the name of my wave file
WaveDecoder sourceDecoder = new WaveDecoder(fileName); //Accord.Audio.Formats.WaveDecoder
Signal s = sourceDecoder.Decode(); //SampleFormat says Format32bitIeeeFloat
ComplexSignal = s.ToComplex(); //This throws the following exception:

//InvalidSignalPropertiesException 
//Signals length should be a power of 2. 

读取Signal的源代码时,仅当Signal.SampleFormat不是Format32bitIeeeFloat时才抛出该源代码。

我真的很惊讶,用C#操作wav文件的音频功能(尤其是频率)并不容易。

您需要创建一个Hamming(或其他方法)窗口,其大小为2的幂(我在这里选择1024)。 然后,在执行前向傅立叶变换之前,将该窗口应用于复数信号。

        string fileName = "mu1.wav";
        WaveDecoder sourceDecoder = new WaveDecoder(fileName);
        Signal sourceSignal = sourceDecoder.Decode();

        //Create Hamming window so that signal will fit into power of 2:           
        RaisedCosineWindow window = RaisedCosineWindow.Hamming(1024);

        // Splits the source signal by walking each 512 samples, then creating 
        // a 1024 sample window. Note that this will result in overlapped windows.
        Signal[] windows = sourceSignal.Split(window, 512);

        // You might need to import Accord.Math in order to call this:
        ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal);

        // Forward to the Fourier domain
        complex.ForwardFourierTransform(); //Complete!

        //Recommend building a histogram to see the results

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM