1 /** @addtogroup dsp_extra
2  *  @{
3  */
4 /*
5   Copyright (C) 2016 D Levin (https://www.kfrlib.com)
6   This file is part of KFR
7 
8   KFR is free software: you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation, either version 2 of the License, or
11   (at your option) any later version.
12 
13   KFR is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17 
18   You should have received a copy of the GNU General Public License
19   along with KFR.
20 
21   If GPL is not suitable for your project, you must purchase a commercial license to use KFR.
22   Buying a commercial license is mandatory as soon as you develop commercial activities without
23   disclosing the source code of your own applications.
24   See https://www.kfrlib.com for details.
25  */
26 #pragma once
27 
28 #include "../base/basic_expressions.hpp"
29 #include "../simd/operators.hpp"
30 #include "../simd/vec.hpp"
31 
32 namespace kfr
33 {
34 inline namespace CMT_ARCH_NAME
35 {
36 
37 /**
38  * @brief Returns expression template that generates a unit impulse
39  */
40 template <typename T = int>
unitimpulse()41 auto unitimpulse()
42 {
43     return lambda<T>([](cinput_t, size_t index, auto x) {
44         if (index == 0)
45             return onoff(x);
46         else
47             return zerovector(x);
48     });
49 }
50 
51 template <typename T = fbase>
jaehne_arg(size_t size)52 auto jaehne_arg(size_t size)
53 {
54     return truncate(constants<T>::pi_s(1, 2) * sqr(linspace(T(0), T(size), size, false)) / size, size);
55 }
56 
57 /**
58  * @brief Returns expression template that generates a jaehne vector
59  * Generates the sine with linearly increasing frequency from 0hz to nyquist frequency.
60  */
61 template <typename T = fbase>
jaehne(identity<T> magn,size_t size)62 auto jaehne(identity<T> magn, size_t size)
63 {
64     return magn * sin(jaehne_arg<T>(size));
65 }
66 
67 template <typename T = fbase>
swept_arg(size_t size)68 auto swept_arg(size_t size)
69 {
70     return truncate(constants<T>::pi_s(1, 4) * sqr(sqr(linspace(T(0), T(size), size, false)) / sqr(T(size))) *
71                         T(size),
72                     size);
73 }
74 
75 /**
76  * @brief Returns expression template that generates a jaehne vector
77  * Generates the sine with logarithmically increasing frequency from 0hz to nyquist frequency.
78  */
79 template <typename T = fbase>
swept(identity<T> magn,size_t size)80 auto swept(identity<T> magn, size_t size)
81 {
82     return magn * sin(swept_arg<T>(size));
83 }
84 } // namespace CMT_ARCH_NAME
85 } // namespace kfr
86