-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHannTaper.hpp
More file actions
56 lines (48 loc) · 1.41 KB
/
Copy pathHannTaper.hpp
File metadata and controls
56 lines (48 loc) · 1.41 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
#ifndef ASU_HANNTAPER
#define ASU_HANNTAPER
#include<iostream>
#include<cmath>
#include<vector>
/***********************************************************
* This C++ template taper both ends of the input signal,
* using a Hanning Window.
*
* input(s):
* vector<T> &p ---- Signal that get tapered. length is npts.
* const double &w ---- Taper one-side length compared to npts.
* (width max at 0.5, which means the taper
* covers the whole signal)
*
* e.g.
*
* Signal: ************************* (npts=25)
* Target: tttt*****************tttt (taper one-side length=4)
*
* --> input w should be 4/25.
*
* return(s):
* vector<T> &p (in-place)
* Shule Yu
* Jan 22 2018
*
* Key words: Hanning window taper.
*
* Reference: https://en.wikipedia.org/wiki/Hann_function
***********************************************************/
template<typename T>
void HannTaper(std::vector<T> &p,const double &w){
if (w>0.5) {
std::cerr << "Error in " << __func__ << ": taper window too big ..." << std::endl;
return;
}
int n=p.size(),N=round(n*w);
if (N<=1) return;
double df=M_PI/(N-1);
for (int i=0;i<N;++i){
double weight=0.5-0.5*cos(df*i);
p[i]*=weight;
p[n-1-i]*=weight;
}
return;
}
#endif