-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTriangleSignal.hpp
More file actions
56 lines (47 loc) · 1.3 KB
/
Copy pathTriangleSignal.hpp
File metadata and controls
56 lines (47 loc) · 1.3 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_TRIANGLESIGNAL
#define ASU_TRIANGLESIGNAL
#include<vector>
/***********************************************************
* This C++ template returns a triangle signal.
* The signal has peak at its center, amplitude is 1.
*
* input(s):
* const int &N ---- request signal length.
* const double &frac ---- request fraction of the non-zero part
* (explaned below)
*
* *
* * *
* * *
* * *
* 00000000000 00000000000
*
* frac = 7/N = 7/29 = 0.24137931
*
* return(s):
* vector<double> ans ---- the triangle signal.
*
* Shule Yu
* Dec 31 2017
*
* Key words: triangle signal.
***********************************************************/
std::vector<double> TriangleSignal(const int &N,const double &frac){
// Check requested size.
if (N<=0) return {};
// Check signal width.
double Frac=(frac<0?0:frac);; // gives an impulse if frac<=0.
int L=N*Frac;
double Inc=-2.0/(L+1);
std::vector<double> ans(N,0);
ans[N/2]=1;
for (int i=N/2+1;i<N;i++){
ans[i]=ans[i-1]+Inc;
if (ans[i]<0) ans[i]=0;
ans[N/2-(i-N/2)]=ans[i];
}
ans[0]=ans[1]+Inc;
if (ans[0]<0) ans[0]=0;
return ans;
}
#endif