-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathconv.cpp
More file actions
32 lines (30 loc) · 763 Bytes
/
conv.cpp
File metadata and controls
32 lines (30 loc) · 763 Bytes
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
#include "conv.hpp"
/**
* Convolution of u and v vector.
*/
void conv(const vectord &u, const vectord &v, vectord &c)
{
// fill with zeros
c.resize(u.size() + v.size() - 1, 0);
// use convolution machine implements convolution
for (int n = 0; n < c.size(); n++)
{
// iterate input signal u, kernal is v
for (int k = 0; k < v.size(); k++)
{
// just as the Math Equation of Convolution
int iu = n - k;
double uu;
if (iu < 0 || iu >= u.size())
{
uu = 0;
}
else
{
uu = u[iu];
}
// iterate kernel and cumulate it
c[n] = c[n] + v[k] * uu;
}
}
}