Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从Accord.NET中的信号对象创建ComplexSignal对象?_C#_Signal Processing_Fft_Audio Processing_Accord.net - Fatal编程技术网

C# 如何从Accord.NET中的信号对象创建ComplexSignal对象?

C# 如何从Accord.NET中的信号对象创建ComplexSignal对象?,c#,signal-processing,fft,audio-processing,accord.net,C#,Signal Processing,Fft,Audio Processing,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.WaveDecod

我正在尝试对由.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不是Format32Bitieefloat时才应抛出此命令,事实上是这样的


我真的很惊讶,在C#中操纵wav文件的音频功能(特别是频率)并不容易。

您需要创建一个大小为2次方的Hamming(或其他方法)窗口(我在这里选择了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

您需要创建一个大小为2次方的Hamming(或其他方法)窗口(我在这里选择了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

这些结果与udpated Accord.NET库有关,可在此处找到:从昨天起,它现在也可以与最新版本(2.12)一起使用-感谢您报告此问题!这将为我返回所有
NaN
(@Meekohi检查您的源数据,确保您的汉明窗口为2的幂。这可能是Cesar的问题(参见上面的回答,其中说明这应该在他的2.12版中得到修复。也许它作为一个bug重新引入?)这些结果与udpated Accord.NET库有关,可在此处找到:从昨天起,它现在也可以与最新版本(2.12)一起使用-感谢您报告此问题!这将为我返回所有
NaN
:(@Meekohi检查您的源数据,确保您的汉明窗口为2的幂。这可能是Cesar的问题(参见上面他的回答,其中指出这应该在他的2.12版中修复。也许它作为一个bug被重新引入?)