-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_win.h
More file actions
78 lines (57 loc) · 1.74 KB
/
tool_win.h
File metadata and controls
78 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*****************************************************/
/* tool_win.h
* Copyright (H) 2021/05/07 by
*
* tool_win 窗函数
*
*/
/*****************************************************/
#ifndef _TOOLWIN_
#define _TOOLWIN_
#include <math.h>
#define WIN_PI (3.141592653589793238462643383279)
class CWindow
{
public:
CWindow();
~CWindow();
public:
// 汉宁窗
template <typename Type> void hanning(Type amp, int size, Type win[]);
// 海明窗
template <typename Type> void hamming(Type amp, int size, Type win[]);
// 模板需要定义和实现在一个文件
};
/********************************************************
* amp增益 size最终生成的窗大小 win输出的窗
* w(k)=0.5*(1-cos(2*pi*k/(N-1))) 0<=k<=N-1
* 此公式与matlab帮助文档中写的不一样,文档中计算如下:
* w = .5*(1 - cos(2*pi*(1:m)'/(n+1))); i从1开始
* 这个计算方法可以不带第一个和最后一个0
* 此处按照matlab来
*********************************************************/
template <typename Type>
void CWindow::hanning(Type amp, int size, Type win[])
{
// 在math.h有一个宏定义WIN_PI
for (int i = 0; i < (size+1)/2; i++)
{
win[i] = amp * Type(0.50 - 0.50*cos((2.0*WIN_PI*(i+1)) / (size+1.0)));
win[size - 1 - i] = win[i];
}
return;
}
/********************************************************
* 汉明窗/海明窗
*********************************************************/
template <typename Type>
void CWindow::hamming(Type amp, int size, Type win[])
{
for(int i = 0; i < (size+1)/2; i++)
{
win[i] = amp * Type(0.54 - 0.46*cos((2*WIN_PI*i) / (size - 1.0)));
win[size - 1 - i] = win[i];
}
return;
}
#endif