vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
impulse_response.cc
Go to the documentation of this file.
1/************************************************************************/
2/* */
3/* vspline - a set of generic tools for creation and evaluation */
4/* of uniform b-splines */
5/* */
6/* Copyright 2015 - 2023 by Kay F. Jahnke */
7/* */
8/* Permission is hereby granted, free of charge, to any person */
9/* obtaining a copy of this software and associated documentation */
10/* files (the "Software"), to deal in the Software without */
11/* restriction, including without limitation the rights to use, */
12/* copy, modify, merge, publish, distribute, sublicense, and/or */
13/* sell copies of the Software, and to permit persons to whom the */
14/* Software is furnished to do so, subject to the following */
15/* conditions: */
16/* */
17/* The above copyright notice and this permission notice shall be */
18/* included in all copies or substantial portions of the */
19/* Software. */
20/* */
21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
23/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
24/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
25/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
26/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
27/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
28/* OTHER DEALINGS IN THE SOFTWARE. */
29/* */
30/************************************************************************/
31
32/// \file impulse_response.cc
33///
34/// \brief get the impulse response of a b-spline prefilter
35///
36/// filter a unit pulse with a b-spline prefilter of a given degree
37/// and display the central section of the result
38///
39/// compile with:
40/// clang++ -std=c++11 -o impulse_response -O3 -pthread impulse_response.cc
41///
42/// to get the central section with values beyond +/- 0.0042 of a degree 5 b-spline:
43///
44/// impulse_response 5 .0042
45///
46/// producing this output:
47///
48/// long double ir_5[] = {
49/// -0.0084918610197410 ,
50/// +0.0197222540252632 ,
51/// -0.0458040841925519 ,
52/// +0.1063780046433000 ,
53/// -0.2470419274022756 ,
54/// +0.5733258709616592 ,
55/// -1.3217294729875093 ,
56/// +2.8421709220216247 ,
57/// -1.3217294729875098 ,
58/// +0.5733258709616593 ,
59/// -0.2470419274022757 ,
60/// +0.1063780046433000 ,
61/// -0.0458040841925519 ,
62/// +0.0197222540252632 ,
63/// -0.0084918610197410 ,
64/// } ;
65///
66/// which, when used as a convolution kernel, will have the same effect on a signal
67/// as applying the recursive filter itself, but with lessened precision due to windowing.
68
69#include <iostream>
70#include <iomanip>
71#include <assert.h>
72#include <vspline/multithread.h>
73#include <vspline/vspline.h>
74
75int main ( int argc , char * argv[] )
76{
77 if ( argc < 3 )
78 {
79 std::cerr << "please pass spline degree and cutoff on the command line"
80 << std::endl ;
81 exit ( -1 ) ;
82 }
83
84 int degree = std::atoi ( argv[1] ) ;
85
86 assert ( degree >= 0 && degree <= vspline_constants::max_degree ) ;
87
88 long double cutoff = std::atof ( argv[2] ) ;
89
90 std::cout << "calculating impulse response with spline degree "
91 << degree << " and cutoff " << cutoff << std::endl ;
92
93 // using the highest-level access to prefiltering, we code:
94
95 vspline::bspline < long double , 1 > bsp ( 1001 , degree ) ;
96
97 auto v1 = bsp.core ;
98 v1 [ 500 ] = 1.0 ;
99
100 bsp.prefilter() ;
101
102 std::cout << "long double ir_" << degree << "[] = {" << std::endl ;
103
104 std::cout << std::fixed << std::showpoint
105 << std::setprecision(std::numeric_limits<long double>::max_digits10) ;
106
107 for ( int k = 0 ; k < 1001 ; k++ )
108 {
109 if ( std::abs ( v1[k] ) > cutoff )
110 {
111 std::cout << v1[k] << "L ," << std::endl ;
112 }
113 }
114 std::cout << "} ;" << std::endl ;
115}
int main(int argc, char *argv[])
code to distribute the processing of bulk data to several threads
class bspline now builds on class bspline_base, adding coefficient storage, while bspline_base provid...
Definition: bspline.h:499
view_type core
Definition: bspline.h:566
void prefilter(vspline::xlf_type boost=vspline::xlf_type(1), int njobs=vspline::default_njobs)
prefilter converts the knot point data in the 'core' area into b-spline coefficients....
Definition: bspline.h:815
includes all headers from vspline (most of them indirectly)