Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Bernardo HUMMES FLORES
Embedded Machine Learning
Commits
b8386c99
Commit
b8386c99
authored
Nov 30, 2021
by
Bernardo Hummes
Browse files
added back my code, some problem in boundaries management for the vectors
parent
f5affd57
Changes
1
Show whitespace changes
Inline
Side-by-side
Extraction/features_extraction.cpp
View file @
b8386c99
...
@@ -10,48 +10,48 @@ std::map<FTYPE, DataVector> stft(DataVector &signal) {
...
@@ -10,48 +10,48 @@ std::map<FTYPE, DataVector> stft(DataVector &signal) {
auto
stddev
=
DataVector
(
FFT_SIZE
);
auto
stddev
=
DataVector
(
FFT_SIZE
);
//
for (DataVector::const_iterator it; it != signal.end()-N-1; it+=N) {
for
(
DataVector
::
const_iterator
it
;
it
!=
signal
.
end
()
-
N
-
1
;
it
+=
N
)
{
//
//
// get the two overlapping chuncks from the sliding window
// get the two overlapping chuncks from the sliding window
//
std::vector<Complex> v1(it, it+N);
std
::
vector
<
Complex
>
v1
(
it
,
it
+
N
);
//
std::vector<Complex> v2(it+N/2, it+N+N/2);
std
::
vector
<
Complex
>
v2
(
it
+
N
/
2
,
it
+
N
+
N
/
2
);
//
//
auto w = hamming_window();
auto
w
=
hamming_window
();
//
windowing(w, v1);
windowing
(
w
,
v1
);
//
windowing(w, v2);
windowing
(
w
,
v2
);
//
//
// compute the fft
// compute the fft
//
ite_dit_fft(v1);
ite_dit_fft
(
v1
);
//
ite_dit_fft(v2);
ite_dit_fft
(
v2
);
//
//
// compute the magnitude fft's output (which is a complex, with angle and phase)
// compute the magnitude fft's output (which is a complex, with angle and phase)
//
DataVector v1_abs = DataVector(N);
DataVector
v1_abs
=
DataVector
(
N
);
//
DataVector v2_abs = DataVector(N);
DataVector
v2_abs
=
DataVector
(
N
);
//
//
for (std::size_t i=0; i<v1.size(); i++) {
for
(
std
::
size_t
i
=
0
;
i
<
v1
.
size
();
i
++
)
{
//
v1_abs.push_back(abs(v1[i]));
v1_abs
.
push_back
(
abs
(
v1
[
i
]));
//
v2_abs.push_back(abs(v2[i]));
v2_abs
.
push_back
(
abs
(
v2
[
i
]));
//
}
}
//
//
// compute the average of the magnitudes
// compute the average of the magnitudes
//
auto chunck_1_avg = std::accumulate(v1_abs.begin(), v1_abs.end(), 0)/v1_abs.size();
auto
chunck_1_avg
=
std
::
accumulate
(
v1_abs
.
begin
(),
v1_abs
.
end
(),
0
)
/
v1_abs
.
size
();
//
auto chunck_2_avg = std::accumulate(v1_abs.begin(), v1_abs.end(), 0)/v1_abs.size();
auto
chunck_2_avg
=
std
::
accumulate
(
v1_abs
.
begin
(),
v1_abs
.
end
(),
0
)
/
v1_abs
.
size
();
//
//
avg.push_back(chunck_1_avg);
avg
.
push_back
(
chunck_1_avg
);
//
avg.push_back(chunck_2_avg);
avg
.
push_back
(
chunck_2_avg
);
//
//
// use the average to compute the std deviation
// use the average to compute the std deviation
//
auto chunck_1_stddev = 0;
auto
chunck_1_stddev
=
0
;
//
auto chunck_2_stddev = 0;
auto
chunck_2_stddev
=
0
;
//
//
for (std::size_t i=0; i < v1_abs.size(); i++) {
for
(
std
::
size_t
i
=
0
;
i
<
v1_abs
.
size
();
i
++
)
{
//
chunck_1_stddev += pow(v1_abs.at(i) - chunck_1_avg, 2);
chunck_1_stddev
+=
pow
(
v1_abs
.
at
(
i
)
-
chunck_1_avg
,
2
);
//
chunck_2_stddev += pow(v2_abs.at(i) - chunck_1_avg, 2);
chunck_2_stddev
+=
pow
(
v2_abs
.
at
(
i
)
-
chunck_1_avg
,
2
);
//
}
}
//
//
stddev.push_back(chunck_1_stddev);
stddev
.
push_back
(
chunck_1_stddev
);
//
stddev.push_back(chunck_2_stddev);
stddev
.
push_back
(
chunck_2_stddev
);
//
}
}
std
::
map
<
FTYPE
,
DataVector
>
features
;
std
::
map
<
FTYPE
,
DataVector
>
features
;
//insert bins average and stddev in features
//insert bins average and stddev in features
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment