如何对传入信号执行加窗操作?

发布于 2024-11-23 21:07:38 字数 184 浏览 3 评论 0 原文

我正在使用 Aubio 库;我在 aubio.org 的文档或互联网上找不到这个。在进行处理时(特别是在我的例子中使用 aubio_pitch_detect 进行音调检测),Aubio 是否在窗口方面对传入音频数组执行任何操作,还是我必须自己实现?

如果我需要添加它,一个简单的窗口代码示例(或链接)将受到欢迎。

I'm using the Aubio library; I can't find this anywhere in the docs at aubio.org or on the internet. When doing processing (specifically pitch detection with aubio_pitch_detect in my case) does Aubio do anything to the incoming audio arrays in terms of windowing, or do I have to implement that myself?

If I need to add it, a simple windowing code sample (or link) would be welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绾颜 2024-11-30 21:07:41

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));
}

编辑:要解决“天哪,是+或-还是什么”问题,您需要再进一步看看您是乘以 π*i/FFT_N 的 sin 还是 cos。因为 sin(0) = 0 和 cos(0) = 1,所以您正在查看看起来(大约!)如下所示的窗口之间的差异:

在此处输入图像描述

或类似这样:

在此处输入图像描述

请注意,如果您在后面添加一个另一个,他们看起来都像这样:

所以当您在窗口后要对信号进行特定处理时可能会影响您选择的窗口选项,它们实际上并不完全相反,只是排列方式不同。

Found this in 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));
}

Edit: To address the "omg is it + or - or what" question, you need to look a little further to see whether you're multiplying by sin or cos of π*i/FFT_N. Because sin(0) = 0 and cos(0) = 1, you are looking at the difference between a window that looks (approximately!) like this:

enter image description here

or like this:

enter image description here

Note that if you put one after the other, they both look like this:

enter image description here

So while the specific processing you want to do on the signal after you window it might affect which windowing option you choose they are not in fact fundamentally opposed, just aligned differently.

淡写薰衣草的香 2024-11-30 21:07:41

aubio_pitch_do 将音频样本向量作为输入,并将执行所需的窗口操作。

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

如果您需要创建一个窗口,可以使用 <代码>new_aubio_window(大小,类型)

例如:

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;

aubio_pitch_do takes a vector of audio samples as input, and will do the windowing needed.

The documentation can be found in the header files. In this case, check out the pitch.h file.

If you need to create a window, you can do it with new_aubio_window ( size, type ).

For example:

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

Here is the list of window types available so far:

/** 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;
顾北清歌寒 2024-11-30 21:07:41

这是我的几种窗口方法的端口,用于初始化窗口向量。

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(myFloatWindowBuffer, windowLength, WINDOW_NUTALL);

Here is my port of several windowing methods to init a windowing vector.

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;
            }
    }

Example usage:

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

时光沙漏 2024-11-30 21:07:40

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

关于Flavien Volkenbuildsucceeded的答案,他们在汉明系数方面都给出了相同的说法:

0.54或0.53836,以及0.46或0.46164。
两个答案之间都有一个“-”:0.54 - 0.46。

到目前为止,一切顺利。现在看看这个:

(1) 约翰霍普金斯大学说:0.54 + 0.46< br>
(2) 加州大学说: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

This is more of a question than an answer, but I can't comment other answers due to newbie-status.

Regarding the answers of Flavien Volken and buildsucceeded, they both state the same in terms of the Hamming coefficients:

0.54 or 0.53836, and 0.46 or 0.46164.
Both answers have a "-" in between them: 0.54 - 0.46.

So far, so good. Now look at this:

(1) Johns Hopkins University says: 0.54 + 0.46
(2) University of California says: 0.54 - 0.46
(3) A book on DSP says: 0.54 + 0.46
(4) Wikipedia says: 0.54 + 0.46
(5) mathworks says: 0.54 - 0.46
(6) A forum user says: 1.07672 - 0.92328

Totally confused, how do we know what is really correct now?

Here are the links (can't post more than 2 real links because of newbie-status here):

  (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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文