如何对输入信号进行窗口化?

时间:2011-07-15 14:30:18

标签: signal-processing aubio

我正在使用Aubio库;我无法在aubio.org或互联网上的文档中找到它。在进行处理时(特别是在我的情况下使用aubio_pitch_detect进行音高检测)Aubio 在窗口方面对传入的音频阵列做了什么,还是我必须自己实现?

如果我需要添加它,欢迎使用简单的窗口代码示例(或链接)。

4 个答案:

答案 0 :(得分:1)

Performous中找到了这个:

// Hamming window
for (size_t i=0; i < FFT_N; i++) {
    m_window[i] = 0.53836 - 0.46164 * std::cos(2.0 * M_PI * i / (FFT_N - 1));
}

编辑:要解决“omg is it + or - 或what”问题,您需要进一步了解是否要乘以π*i/FFT_N的sin或cos。因为sin(0)= 0而cos(0)= 1,所以你正在看一个看起来像这样的窗口(大约!)之间的区别:

enter image description here

或者像这样:

enter image description here

请注意,如果你一个接一个地放置它们,它们都是这样的:

enter image description here

所以虽然您在窗口后想要对信号进行的特定处理可能会影响您选择的窗口选项但实际上它们并没有从根本上反对,只是以不同的方式对齐。

答案 1 :(得分:1)

这不仅仅是一个问题,而是一个答案,但由于新手身份,我无法评论其他答案。

关于 Flavien Volken buildsucceeded 的答案,他们在汉明系数方面都表示相同:

0.54或0.53836,和0.46或0.46164 这两个答案都有一个&#34; - &#34;在他们之间:0.54 - 0.46。

到目前为止,这么好。现在看看这个:

(1)Johns Hopkins University says:0.54 + 0.46
(2)University of California says:0.54 - 0.46
(3)关于DSP的书说:0.54 + 0.46
(4)维基百科说:0.54 + 0.46
(5)mathworks说:0.54 - 0.46
(6)论坛用户说:1.07672 - 0.92328

完全混淆,我们怎么知道现在真正正确的是什么?


以下是链接(由于此处有新手状态,因此不能发布超过2个真实链接):

  (1): www.jhu.edu/signals/phasors/hpfs7.htm
  (2): www.ece.uci.edu/docs/hspice/hspice_2001_2-220.html
  (3): books.google.de/books?id=ytuUKKVeR88C&pg=PT442&lpg=PT442&dq=hamming%20window%200.54%200.46&source=bl&ots=ecdP7pU8-w&sig=yv9QiCvuWv8vShO-6CjZATx37lA&hl=en&sa=X&ei=M4IJUfvBLsTFtAbQ54GwCw&ved=0CDAQ6AEwATgK
  (4): de.wikipedia.org/wiki/Hamming-Fenster#Hamming-Fenster
  (5): www.mathworks.de/de/help/signal/ref/hamming.html
  (6): forums.oracle.com/forums/message.jspa?messageID=9244422#9244422

答案 2 :(得分:1)

aubio_pitch_do将音频样本矢量作为输入,并将进行所需的窗口化。

可以在头文件中找到该文档。在这种情况下,请查看pitch.h文件。

如果您需要创建一个窗口,可以使用new_aubio_window ( size, type )

例如:

fvec_t * my_new_window = new_aubio_window ( 1024, "hanningz" );

以下是目前可用的窗口类型列表:

/** Window types */
typedef enum
{
  aubio_win_rectangle,
  aubio_win_hamming,
  aubio_win_hanning,
  aubio_win_hanningz,
  aubio_win_blackman,
  aubio_win_blackman_harris,
  aubio_win_gaussian,
  aubio_win_welch,
  aubio_win_parzen,
  aubio_win_default = aubio_win_hanningz,
} aubio_window_type;

答案 3 :(得分:0)

这是我的several windowing methods端口,用于初始化窗口向量。

include <math.h>  

enum {
WINDOW_RECTANGULAR,
WINDOW_HANN,
WINDOW_HAMMING,
WINDOW_COSINE,
WINDOW_LANCZOS,
WINDOW_TRIANGULAR,
WINDOW_BARTLETT,
WINDOW_GAUSSIAN,
WINDOW_BARTLETT_HANN,
WINDOW_BLACKMAN,
WINDOW_NUTALL,
WINDOW_BLACKMAN_HARRIS,
WINDOW_BLACKMAN_NUTALL,
WINDOW_FLATTOP,
WINDOW_NB
};

    template <class T_Real>
    void computeWindow(T_Real*buffer, int length, int type)
    {

            switch (type)
            {
            case WINDOW_RECTANGULAR :
                    for (int n = 0; n < length; n++){ buffer[n] = 1.0; } break;
            case WINDOW_HANN :
                    for (int n = 0; n < length; n++){ buffer[n] = 0.5*(1.0 - cos(M_PI*2.0*n/(length-1))); } break;
            case WINDOW_HAMMING :
                    for (int n = 0; n < length; n++){ buffer[n] = 0.54-0.46*cos(M_PI*2.0*n/(length-1)); } break;
            case WINDOW_COSINE :
                    for (int n = 0; n < length; n++){ buffer[n] = sin(M_PI*n/(length-1)); } break;
            case WINDOW_LANCZOS :
                    for (int n = 0; n < length; n++){ double x = (2.0*n/(length-1)-1.0); buffer[n] = sin(M_PI*x)/(x*M_PI); } break;
            case WINDOW_TRIANGULAR :
                    for (int n = 0; n < length; n++){ buffer[n] = (2.0/(length+1))*((0.5*(length-1.0))-fabs(n-0.5*(length-1.0)))  ; } break;
            case WINDOW_BARTLETT :
                    for (int n = 0; n < length; n++){ buffer[n] = (2.0/(length-1))*((0.5*(length-1.0))-fabs(n-0.5*(length-1.0)))  ; } break;
            case WINDOW_GAUSSIAN :
                {
                    double fi = 0.5;
                    for (int n = 0; n < length; n++)
                    {
                        double inner = (n-0.5*(length-1))/(0.5*fi*(length-1));
                        double indice = -0.5*inner*inner;
                        buffer[n] = exp(indice);
                    }
                    break;
                }
            case WINDOW_BARTLETT_HANN :
                    for (int n = 0; n < length; n++){ buffer[n] = 0.62-0.48*fabs((double)n/(length-1.0)-0.5)-0.48*cos(M_PI*2.0*n/(length-1));} break;
            case WINDOW_BLACKMAN :
                {
                    double alpha = 0.16;
                    double a0 = 0.5*(1.0-alpha);
                    double a1 = 0.5;
                    double a2 = 0.5*alpha;
                    for (int n = 0; n < length; n++){ buffer[n] = a0 - a1*cos(M_PI*2.0*n/(length-1)) + a2*cos(M_PI*4.0*n/(length-1));} break;
                }
            case WINDOW_NUTALL :
                {
                    double a0 = 0.355768;
                    double a1 = 0.487396;
                    double a2 = 0.144232;
                    double a3 = 0.012604;
                    for (int n = 0; n < length; n++){ buffer[n] = a0 - a1*cos(M_PI*2.0*n/(length-1)) + a2*cos(M_PI*4.0*n/(length-1)) - a3*cos(M_PI*6.0*n/(length-1));} break;
                }

            case WINDOW_BLACKMAN_HARRIS :
                {
                    double a0 = 0.35875;
                    double a1 = 0.48829;
                    double a2 = 0.14128;
                    double a3 = 0.01168;
                    for (int n = 0; n < length; n++){ buffer[n] = a0 - a1*cos(M_PI*2.0*n/(length-1)) + a2*cos(M_PI*4.0*n/(length-1)) - a3*cos(M_PI*6.0*n/(length-1));} break;
                }
            case WINDOW_BLACKMAN_NUTALL :
                {
                    double a0 = 0.3635819;
                    double a1 = 0.4891775;
                    double a2 = 0.1365995;
                    double a3 = 0.0106411;
                    for (int n = 0; n < length; n++){ buffer[n] = a0 - a1*cos(M_PI*2.0*n/(length-1)) + a2*cos(M_PI*4.0*n/(length-1)) - a3*cos(M_PI*6.0*n/(length-1));} break;
                }

            case WINDOW_FLATTOP :
                {
                    double a0 = 1.0;
                    double a1 = 1.93;
                    double a2 = 1.29;
                    double a3 = 0.388;
                    double a4 = 0.032;
                    for (int n = 0; n < length; n++)
                    { buffer[n] =
                        a0 - a1*cos(M_PI*2.0*n/(length-1)) +
                        a2*cos(M_PI*4.0*n/(length-1)) -
                        a3*cos(M_PI*6.0*n/(length-1)) +
                        a4*cos(M_PI*8.0*n/(length-1));
                    } break;
                }
                default: break;
            }
    }

使用示例:

computeWindow<float>(myFloatWindowBuffer, windowLength, WINDOW_NUTALL);