Skip to content

Commit 999bee7

Browse files
authored
Merge pull request #4 from atrettin/lowpass_filter
Add low-pass filter
2 parents 5d9596c + 2a46cce commit 999bee7

File tree

8 files changed

+330
-0
lines changed

8 files changed

+330
-0
lines changed

include/SQuIDS/SUNalg.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,33 @@ class SU_vector{
513513
double range = t_end - t_start;
514514
#include "SU_inc/PreEvolutionSelectAvgRange.txt"
515515
}
516+
517+
///\brief Compute low-pass filter for pre-computed sine and cosine evaluations
518+
///
519+
/// This function applies a low-pass filter to the pre-evolution buffer computed by
520+
/// PrepareEvolve to filter out high frequencies. This is distinct from the already
521+
/// existing averaging mechanism because this function filters the frequency, not the
522+
/// number of rotations (i.e. frequency times time). This allows this function to be
523+
/// used both during evaluation of probabilities from the evolved state as well as
524+
/// during the integration of the interaction state equation. A linear ramp can be
525+
/// used to soften the cut-off of the filter.
526+
///\param buffer The buffer with evaluated sine/cosine values from PrepareEvolve.
527+
///\param cutoff Cut-off frequency of the filter. Sine and cosine evaluations
528+
/// with input frequencies higher than this will be set to zero
529+
///\param scale Distance in frequency between cut-off and pass-through. A value of
530+
/// greater than zero allows for a gradual transition to cut-off, rather
531+
/// than applying a hard step function.
532+
void LowPassFilter(double* buffer, double cutoff, double scale) const{
533+
auto& suv1=*this;
534+
size_t offset=GetEvolveBufferSize()/2;
535+
double* CX=buffer;
536+
double* SX=buffer+offset;
537+
double freq;
538+
int i;
539+
#include "SU_inc/LowPassFilterSelect.txt"
540+
}
541+
542+
516543
///\brief Compute the time evolution of the SU_vector
517544
///
518545
///\param buffer A buffer which has been filled by a previous call to
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/******************************************************************************
2+
* This program is free software: you can redistribute it and/or modify *
3+
* it under the terms of the GNU General Public License as published by *
4+
* the Free Software Foundation, either version 3 of the License, or *
5+
* (at your option) any later version. *
6+
* *
7+
* This program is distributed in the hope that it will be useful, *
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10+
* GNU General Public License for more details. *
11+
* *
12+
* You should have received a copy of the GNU General Public License *
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
14+
* *
15+
* Authors: *
16+
* Carlos Arguelles (University of Wisconsin Madison) *
17+
* carguelles@icecube.wisc.edu *
18+
* Jordi Salvado (University of Wisconsin Madison) *
19+
* jsalvado@icecube.wisc.edu *
20+
* Christopher Weaver (University of Wisconsin Madison) *
21+
* cweaver@icecube.wisc.edu *
22+
* Alexander Trettin (DESY) *
23+
* atrettin@icecube.wisc.edu *
24+
******************************************************************************/
25+
// greater than cutoff implies setting to zero
26+
if (fabs(freq) > fabs(cutoff)){
27+
SX[i] = 0;
28+
CX[i] = 0;
29+
// If we are below the cutoff, but above the threshold where we begin to apply the
30+
// filter gradually, we do that.
31+
}else if(fabs(freq) > fabs(cutoff) - fabs(scale)){
32+
SX[i] *= (fabs(cutoff) - fabs(freq))/fabs(scale);
33+
CX[i] *= (fabs(cutoff) - fabs(freq))/fabs(scale);
34+
}
35+
// if neither of the cases above applied, we do nothing
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/******************************************************************************
2+
* This program is free software: you can redistribute it and/or modify *
3+
* it under the terms of the GNU General Public License as published by *
4+
* the Free Software Foundation, either version 3 of the License, or *
5+
* (at your option) any later version. *
6+
* *
7+
* This program is distributed in the hope that it will be useful, *
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10+
* GNU General Public License for more details. *
11+
* *
12+
* You should have received a copy of the GNU General Public License *
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
14+
* *
15+
* Authors: *
16+
* Carlos Arguelles (University of Wisconsin Madison) *
17+
* carguelles@icecube.wisc.edu *
18+
* Jordi Salvado (University of Wisconsin Madison) *
19+
* jsalvado@icecube.wisc.edu *
20+
* Christopher Weaver (University of Wisconsin Madison) *
21+
* cweaver@icecube.wisc.edu *
22+
* Alexander Trettin (DESY) *
23+
* atrettin@icecube.wisc.edu *
24+
******************************************************************************/
25+
freq=2*suv1.components[3];
26+
i = 0;
27+
#include "ApplyLowPassFilter.txt"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/******************************************************************************
2+
* This program is free software: you can redistribute it and/or modify *
3+
* it under the terms of the GNU General Public License as published by *
4+
* the Free Software Foundation, either version 3 of the License, or *
5+
* (at your option) any later version. *
6+
* *
7+
* This program is distributed in the hope that it will be useful, *
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10+
* GNU General Public License for more details. *
11+
* *
12+
* You should have received a copy of the GNU General Public License *
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
14+
* *
15+
* Authors: *
16+
* Carlos Arguelles (University of Wisconsin Madison) *
17+
* carguelles@icecube.wisc.edu *
18+
* Jordi Salvado (University of Wisconsin Madison) *
19+
* jsalvado@icecube.wisc.edu *
20+
* Christopher Weaver (University of Wisconsin Madison) *
21+
* cweaver@icecube.wisc.edu *
22+
* Alexander Trettin (DESY) *
23+
* atrettin@icecube.wisc.edu *
24+
******************************************************************************/
25+
freq=2*suv1.components[4];
26+
i=0;
27+
#include "ApplyLowPassFilter.txt"
28+
freq=(suv1.components[4] + sqrt(3)*suv1.components[8]);
29+
i=1;
30+
#include "ApplyLowPassFilter.txt"
31+
freq=(suv1.components[4] - sqrt(3)*suv1.components[8]);
32+
i=2;
33+
#include "ApplyLowPassFilter.txt"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/******************************************************************************
2+
* This program is free software: you can redistribute it and/or modify *
3+
* it under the terms of the GNU General Public License as published by *
4+
* the Free Software Foundation, either version 3 of the License, or *
5+
* (at your option) any later version. *
6+
* *
7+
* This program is distributed in the hope that it will be useful, *
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10+
* GNU General Public License for more details. *
11+
* *
12+
* You should have received a copy of the GNU General Public License *
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
14+
* *
15+
* Authors: *
16+
* Carlos Arguelles (University of Wisconsin Madison) *
17+
* carguelles@icecube.wisc.edu *
18+
* Jordi Salvado (University of Wisconsin Madison) *
19+
* jsalvado@icecube.wisc.edu *
20+
* Christopher Weaver (University of Wisconsin Madison) *
21+
* cweaver@icecube.wisc.edu *
22+
* Alexander Trettin (DESY) *
23+
* atrettin@icecube.wisc.edu *
24+
******************************************************************************/
25+
freq=2*suv1.components[5];
26+
i=0;
27+
#include "ApplyLowPassFilter.txt"
28+
freq=(suv1.components[5] + sqrt(3)*suv1.components[10]);
29+
i=1;
30+
#include "ApplyLowPassFilter.txt"
31+
freq=suv1.components[5] + ((suv1.components[10] + 2*sqrt(2)*suv1.components[15]))/sqrt(3);
32+
i=2;
33+
#include "ApplyLowPassFilter.txt"
34+
freq=(suv1.components[5] - sqrt(3)*suv1.components[10]);
35+
i=3;
36+
#include "ApplyLowPassFilter.txt"
37+
freq=suv1.components[5] - ((suv1.components[10] + 2*sqrt(2)*suv1.components[15]))/sqrt(3);
38+
i=4;
39+
#include "ApplyLowPassFilter.txt"
40+
freq=(2*(suv1.components[10] - sqrt(2)*suv1.components[15]))/sqrt(3);
41+
i=5;
42+
#include "ApplyLowPassFilter.txt"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/******************************************************************************
2+
* This program is free software: you can redistribute it and/or modify *
3+
* it under the terms of the GNU General Public License as published by *
4+
* the Free Software Foundation, either version 3 of the License, or *
5+
* (at your option) any later version. *
6+
* *
7+
* This program is distributed in the hope that it will be useful, *
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10+
* GNU General Public License for more details. *
11+
* *
12+
* You should have received a copy of the GNU General Public License *
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
14+
* *
15+
* Authors: *
16+
* Carlos Arguelles (University of Wisconsin Madison) *
17+
* carguelles@icecube.wisc.edu *
18+
* Jordi Salvado (University of Wisconsin Madison) *
19+
* jsalvado@icecube.wisc.edu *
20+
* Christopher Weaver (University of Wisconsin Madison) *
21+
* cweaver@icecube.wisc.edu *
22+
* Alexander Trettin (DESY) *
23+
* atrettin@icecube.wisc.edu *
24+
******************************************************************************/
25+
freq=2*suv1.components[6];
26+
i=0;
27+
#include "ApplyLowPassFilter.txt"
28+
freq=(suv1.components[6] + sqrt(3)*suv1.components[12]);
29+
i=1;
30+
#include "ApplyLowPassFilter.txt"
31+
freq=suv1.components[6] + ((suv1.components[12] + 2*sqrt(2)*suv1.components[18]))/sqrt(3);
32+
i=2;
33+
#include "ApplyLowPassFilter.txt"
34+
freq=suv1.components[6] + (suv1.components[12])/sqrt(3) + (suv1.components[18])/sqrt(6) + sqrt(2.5)*suv1.components[24];
35+
i=3;
36+
#include "ApplyLowPassFilter.txt"
37+
freq=(suv1.components[6] - sqrt(3)*suv1.components[12]);
38+
i=4;
39+
#include "ApplyLowPassFilter.txt"
40+
freq=suv1.components[6] - ((suv1.components[12] + 2*sqrt(2)*suv1.components[18]))/sqrt(3);
41+
i=5;
42+
#include "ApplyLowPassFilter.txt"
43+
freq=suv1.components[6] - ((2*sqrt(3)*suv1.components[12] + sqrt(6)*suv1.components[18] + 3*sqrt(10)*suv1.components[24]))/6.;
44+
i=6;
45+
#include "ApplyLowPassFilter.txt"
46+
freq=(2*(suv1.components[12] - sqrt(2)*suv1.components[18]))/sqrt(3);
47+
i=7;
48+
#include "ApplyLowPassFilter.txt"
49+
freq=((4*sqrt(3)*suv1.components[12] - sqrt(6)*suv1.components[18] - 3*sqrt(10)*suv1.components[24]))/6.;
50+
i=8;
51+
#include "ApplyLowPassFilter.txt"
52+
freq=sqrt(1.5)*suv1.components[18] - sqrt(2.5)*suv1.components[24];
53+
i=9;
54+
#include "ApplyLowPassFilter.txt"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/******************************************************************************
2+
* This program is free software: you can redistribute it and/or modify *
3+
* it under the terms of the GNU General Public License as published by *
4+
* the Free Software Foundation, either version 3 of the License, or *
5+
* (at your option) any later version. *
6+
* *
7+
* This program is distributed in the hope that it will be useful, *
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10+
* GNU General Public License for more details. *
11+
* *
12+
* You should have received a copy of the GNU General Public License *
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
14+
* *
15+
* Authors: *
16+
* Carlos Arguelles (University of Wisconsin Madison) *
17+
* carguelles@icecube.wisc.edu *
18+
* Jordi Salvado (University of Wisconsin Madison) *
19+
* jsalvado@icecube.wisc.edu *
20+
* Christopher Weaver (University of Wisconsin Madison) *
21+
* cweaver@icecube.wisc.edu *
22+
* Alexander Trettin (DESY) *
23+
* atrettin@icecube.wisc.edu *
24+
******************************************************************************/
25+
freq=2*suv1.components[7];
26+
i=0;
27+
#include "ApplyLowPassFilter.txt"
28+
freq=(suv1.components[7] + sqrt(3)*suv1.components[14]);
29+
i=1;
30+
#include "ApplyLowPassFilter.txt"
31+
freq=suv1.components[7] + ((suv1.components[14] + 2*sqrt(2)*suv1.components[21]))/sqrt(3);
32+
i=2;
33+
#include "ApplyLowPassFilter.txt"
34+
freq=suv1.components[7] + (suv1.components[14])/sqrt(3) + (suv1.components[21])/sqrt(6) + sqrt(2.5)*suv1.components[28];
35+
i=3;
36+
#include "ApplyLowPassFilter.txt"
37+
freq=suv1.components[7] + (suv1.components[14])/sqrt(3) + (suv1.components[21])/sqrt(6) + (suv1.components[28])/sqrt(10) + 2*sqrt(0.6)*suv1.components[35];
38+
i=4;
39+
#include "ApplyLowPassFilter.txt"
40+
freq=(suv1.components[7] - sqrt(3)*suv1.components[14]);
41+
i=5;
42+
#include "ApplyLowPassFilter.txt"
43+
freq=suv1.components[7] - ((suv1.components[14] + 2*sqrt(2)*suv1.components[21]))/sqrt(3);
44+
i=6;
45+
#include "ApplyLowPassFilter.txt"
46+
freq=suv1.components[7] - ((2*sqrt(3)*suv1.components[14] + sqrt(6)*suv1.components[21] + 3*sqrt(10)*suv1.components[28]))/6.;
47+
i=7;
48+
#include "ApplyLowPassFilter.txt"
49+
freq=suv1.components[7] - ((10*sqrt(3)*suv1.components[14] + 5*sqrt(6)*suv1.components[21] + 3*sqrt(10)*suv1.components[28] + 12*sqrt(15)*suv1.components[35]))/30.;
50+
i=8;
51+
#include "ApplyLowPassFilter.txt"
52+
freq=(2*(suv1.components[14] - sqrt(2)*suv1.components[21]))/sqrt(3);
53+
i=9;
54+
#include "ApplyLowPassFilter.txt"
55+
freq=((4*sqrt(3)*suv1.components[14] - sqrt(6)*suv1.components[21] - 3*sqrt(10)*suv1.components[28]))/6.;
56+
i=10;
57+
#include "ApplyLowPassFilter.txt"
58+
freq=(2*suv1.components[14])/sqrt(3) - (suv1.components[21])/sqrt(6) - (suv1.components[28])/sqrt(10) - 2*sqrt(0.6)*suv1.components[35];
59+
i=11;
60+
#include "ApplyLowPassFilter.txt"
61+
freq=sqrt(1.5)*suv1.components[21] - sqrt(2.5)*suv1.components[28];
62+
i=12;
63+
#include "ApplyLowPassFilter.txt"
64+
freq=sqrt(1.5)*suv1.components[21] - (suv1.components[28])/sqrt(10) - 2*sqrt(0.6)*suv1.components[35];
65+
i=13;
66+
#include "ApplyLowPassFilter.txt"
67+
freq=2*sqrt(0.4)*suv1.components[28] - 2*sqrt(0.6)*suv1.components[35];
68+
i=14;
69+
#include "ApplyLowPassFilter.txt"

0 commit comments

Comments
 (0)