Skip to content

Commit d08b73f

Browse files
authored
Added: base-band sine signal class.
1 parent 04960e2 commit d08b73f

File tree

2 files changed

+531
-0
lines changed

2 files changed

+531
-0
lines changed
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
#include <fstream>
2+
#include <iomanip>
3+
#include "GMS_am_bb_sine_signal.h"
4+
#include "GMS_sse_memset.h"
5+
#include "GMS_indices.h"
6+
7+
gms::radiolocation
8+
::am_bb_sine_signal_t
9+
::am_bb_sine_signal_t(const std::size_t nsamples,
10+
const std::uint32_t nK,
11+
const float n,
12+
const float A,
13+
const float P)
14+
:
15+
m_nsamples{nsamples},
16+
m_nK{nK},
17+
m_n{n},
18+
m_A{A},
19+
m_P{P},
20+
m_sig_samples{darray_r4_t(m_nsamples)}
21+
{
22+
23+
}
24+
25+
gms::radiolocation
26+
::am_bb_sine_signal_t
27+
::am_bb_sine_signal_t(am_bb_sine_signal_t &&other) noexcept(true)
28+
:
29+
m_nsamples{std::move(other.m_nsamples)},
30+
m_nK{std::move(other.m_nK)},
31+
m_n{std::move(other.m_n)},
32+
m_A{std::move(other.m_A)},
33+
m_P{std::move(other.m_P)},
34+
m_sig_samples{std::move(other.m_sig_samples)}
35+
{
36+
37+
}
38+
39+
gms::radiolocation
40+
::am_bb_sine_signal_t
41+
::~am_bb_sine_signal_t()
42+
{
43+
44+
}
45+
46+
gms::radiolocation
47+
::am_bb_sine_signal_t &
48+
gms::radiolocation
49+
::am_bb_sine_signal_t
50+
::operator=(am_bb_sine_signal_t &&other) noexcept(true)
51+
{
52+
if(__builtin_expect(this==&other,0)) { return (*this);}
53+
this->m_nsamples = std::move(other.m_nsamples);
54+
this->m_nK = std::move(other.m_nK);
55+
this->m_n = std::move(other.m_n);
56+
this->m_A = std::move(other.m_A);
57+
this->m_P = std::move(other.m_P);
58+
this->m_sig_samples.operator=(std::move(other.m_sig_samples));
59+
return (*this);
60+
}
61+
62+
void
63+
gms::radiolocation
64+
::am_bb_sine_signal_t
65+
::init_storage(const float filler)
66+
{
67+
#if (INIT_BY_STD_FILL) == 0
68+
using namespace gms::common;
69+
sse_memset_unroll8x_ps(&this->m_sig_samples.m_data[0],filler,this->m_nsamples);
70+
#else
71+
std::fill(this->m_sig_samples.m_data,this->m_sig_samples.m_data+this->m_nsamples,filler);
72+
#endif
73+
}
74+
75+
void
76+
gms::radiolocation
77+
::am_bb_sine_signal_t
78+
::create_signal_plot(const std::uint32_t n_samp,
79+
const float * __restrict sig_arg,
80+
const float * __restrict sig_val,
81+
const std::string &header,
82+
const std::string &title,
83+
const bool is_sig_arg_present)
84+
{
85+
std::string plot_fname;
86+
std::string sig_fname;
87+
std::ofstream plot_unit;
88+
std::ofstream sig_unit;
89+
sig_fname = header+"_plot.txt";
90+
sig_unit.open(sig_fname.c_str());
91+
if(is_sig_arg_present==true)
92+
{
93+
for(std::size_t __i{0ull}; __i != n_samp; ++__i)
94+
{
95+
sig_unit << " " << sig_arg[__i] << " "
96+
<< sig_val[__i] << "\n";
97+
}
98+
}
99+
else
100+
{
101+
for(std::size_t __i{0ull}; __i != n_samp; ++__i)
102+
{
103+
sig_unit << " " << sig_arg[__i] << "\n";
104+
105+
}
106+
}
107+
sig_unit.close();
108+
std::cout << "Created signal data file \"" << sig_fname << "\".\n";
109+
plot_fname = header+"plot_commands.txt";
110+
plot_unit.open(plot_fname.c_str());
111+
plot_unit << "#" << plot_fname << "\n";
112+
plot_unit << "#\n";
113+
plot_unit << "# Usage:\n";
114+
plot_unit << "# gnuplot < " << plot_fname << "\n";
115+
plot_unit << "#\n";
116+
plot_unit << "set term png\n";
117+
plot_unit << "set output \"" << header << ".png\"\n";
118+
plot_unit << "set xlabel 't'\n";
119+
plot_unit << "set ylabel 'y(t)'\n";
120+
plot_unit << "set title '" << title << "'\n";
121+
plot_unit << "set grid\n";
122+
plot_unit << "set style data lines\n";
123+
if(is_sig_arg_present==true)
124+
{
125+
plot_unit << "plot \"" << sig_fname << "\" using 1:2 lw 1 linecolor rgb \"red\"\n";
126+
}
127+
else
128+
{
129+
plot_unit << "plot \"" << sig_fname << "\" lw 1 linecolor rgb \"red\"\n";
130+
}
131+
plot_unit << "quit\n";
132+
plot_unit.close();
133+
std::cout << " Created signal data file \"" << plot_fname << "\"\n";
134+
}
135+
136+
std::int32_t
137+
gms::radiolocation
138+
::am_bb_sine_signal_t
139+
::create_signal_user_data(const float * __restrict__ sym_in, // size of m_nsamples*m_nK
140+
const std::uint32_t n_T,
141+
const std::uint32_t n_K)
142+
{
143+
if(__builtin_expect(static_cast<std::uint32_t>(this->m_nsamples)!=n_T,0) ||
144+
__builtin_expect(this->m_nK!=n_K,0)) { return (-1);}
145+
const float T{static_cast<float>(this->m_nsamples)};
146+
const float invT{this->m_P/T};
147+
float sum;
148+
for(std::uint32_t __t{0}; __t != n_T; ++__t)
149+
{
150+
const float t{static_cast<float>(__t)};
151+
sum = 0.0f;
152+
for(std::uint32_t __k{0}; __k != n_K; ++__k)
153+
{
154+
const float k{static_cast<float>(__k)};
155+
const float arg{t-k*T};
156+
sum += sin_sample(arg,invT)*sym_in[Ix2D(__t,n_K,__k)];
157+
}
158+
this->m_sig_samples.m_data[__t] = sum;
159+
}
160+
return (0);
161+
}
162+
163+
std::int32_t
164+
gms::radiolocation
165+
::am_bb_sine_signal_t
166+
::create_signal_user_data_u4x(const float * __restrict__ sym_in, // size of m_nsamples*m_nK
167+
const std::uint32_t n_T,
168+
const std::uint32_t n_K)
169+
{
170+
if(__builtin_expect(static_cast<std::uint32_t>(this->m_nsamples)!=n_T,0) ||
171+
__builtin_expect(this->m_nK!=n_K,0)) { return (-1);}
172+
const float T{static_cast<float>(this->m_nsamples)};
173+
const float invT{this->m_P/T};
174+
float sum0;
175+
float sum1;
176+
float sum2;
177+
float sum3;
178+
float t__i_0{-4.0f};
179+
float t__i_1{1.0f};
180+
float t__i_2{2.0f};
181+
float t__i_3{3.0f};
182+
std::uint32_t __i;
183+
std::uint32_t __j;
184+
for(__i = 0; __i != ROUND_TO_FOUR(n_T,4); __i += 4u)
185+
{
186+
t__i_0 += 4.0f;
187+
sum0 = 0.0f;
188+
for(std::uint32_t __k{0}; __k != n_K; ++__k)
189+
{
190+
const float k{static_cast<float>(__k)};
191+
const float arg{t__i_0-k*T};
192+
sum0 += sin_sample(arg,invT)*sym_in[Ix2D(__i+0,n_K,__k)];
193+
}
194+
this->m_sig_samples.m_data[__i+0] = sum0;
195+
t__i_1 += 4.0f;
196+
sum1 = 0.0f;
197+
for(std::uint32_t __k{0}; __k != n_K; ++__k)
198+
{
199+
const float k{static_cast<float>(__k)};
200+
const float arg{t__i_1-k*T};
201+
sum1 += sin_sample(arg,invT)*sym_in[Ix2D(__i+1,n_K,__k)];
202+
}
203+
this->m_sig_samples.m_data[__i+1] = sum1;
204+
t__i_2 += 4.0f;
205+
sum2 = 0.0f;
206+
for(std::uint32_t __k{0}; __k != n_K; ++__k)
207+
{
208+
const float k{static_cast<float>(__k)};
209+
const float arg{t__i_2-k*T};
210+
sum2 += sin_sample(arg,invT)*sym_in[Ix2D(__i+2,n_K,__k)];
211+
}
212+
this->m_sig_samples.m_data[__i+2] = sum2;
213+
t__i_3 += 4.0f;
214+
sum3 = 0.0f;
215+
for(std::uint32_t __k{0}; __k != n_K; ++__k)
216+
{
217+
const float k{static_cast<float>(__k)};
218+
const float arg{t__i_3-k*T};
219+
sum3 += sin_sample(arg,invT)*sym_in[Ix2D(__i+3,n_K,__k)];
220+
}
221+
this->m_sig_samples.m_data[__i+3] = sum3;
222+
}
223+
for(__j = __i; __j != n_T; ++__j)
224+
{
225+
const float t{static_cast<float>(__j)};
226+
sum0 = 0.0f;
227+
for(std::uint32_t __k{0}; __k != n_K; ++__k)
228+
{
229+
const float k{static_cast<float>(__k)};
230+
const float arg{t-k*T};
231+
sum0 += sin_sample(arg,invT)*sym_in[Ix2D(__j,n_K,__k)];
232+
}
233+
this->m_sig_samples.m_data[__j] = sum0;
234+
}
235+
return (0);
236+
}
237+
238+
auto
239+
gms::radiolocation
240+
::operator<<(std::ostream &os,
241+
gms::radiolocation::am_bb_sine_signal_t &rhs)->std::ostream &
242+
{
243+
std::cout << typeid(rhs).name() << "Begin: object state dump." << std::endl;
244+
std::cout << "m_nsamples : " << rhs.m_nsamples << std::endl;
245+
std::cout << "m_nK : " << rhs.m_nK << std::endl;
246+
std::cout << "m_n : " << std::fixed << std::setprecision(7) << rhs.m_n << std::endl;
247+
std::cout << "m_A : " << std::fixed << std::setprecision(7) << rhs.m_A << std::endl;
248+
std::cout << "m_P : " << std::fixed << std::setprecision(7) << rhs.m_P << std::endl;
249+
std::cout << "Signal-samples:" << std::endl;
250+
for(std::size_t __i{0ull}; __i != rhs.m_nsamples; ++__i)
251+
{
252+
os << std::fixed << std::setprecision(7) <<
253+
rhs.m_sig_samples.m_data[__i] << std::endl;
254+
}
255+
std::cout << typeid(rhs).name() << "End: object state dump." << std::endl;
256+
return (os);
257+
}
258+

0 commit comments

Comments
 (0)