Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ettore Pane
Skyward Boardcore
Commits
038fe1e4
Commit
038fe1e4
authored
1 year ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
[FFT] fixed implementation bugs
parent
33b2a56e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shared/algorithms/FFT.h
+28
-20
28 additions, 20 deletions
src/shared/algorithms/FFT.h
with
28 additions
and
20 deletions
src/shared/algorithms/FFT.h
+
28
−
20
View file @
038fe1e4
...
...
@@ -23,16 +23,12 @@
#pragma once
#include
<complex.h>
#include
<Eigen/Dense>
#include
<math.h>
#include
<Eigen/Core>
namespace
Boardcore
{
typedef
FFT
<
32
>
FFT32
;
typedef
FFT
<
64
>
FFT64
;
typedef
FFT
<
128
>
FFT128
;
typedef
FFT
<
256
>
FFT256
;
/**
* @brief Implementation of Fast Fourier Trasnform using the iterative version
* with bit-reversal index variant of the famous Cooley-Tukey FFT algorithm.
...
...
@@ -56,9 +52,9 @@ public:
static
const
VectorCF
fft
(
VectorF
input_signal
)
{
size_t
rev_i
;
int
m
,
omega
;
float
omega_m
;
std
::
complex
<
float
>
t
,
u
;
int
m
;
float
phi
;
std
::
complex
<
float
>
t
,
u
,
omega
,
omega_m
;
// Bit-reversal permutation
VectorCF
phasors
=
VectorCF
::
Zero
();
...
...
@@ -69,11 +65,12 @@ public:
}
// Cooley-Tukey FFT algorithm
for
(
int
s
=
0
,
s
<=
n_bits
;
s
++
)
for
(
int
s
=
1
;
s
<=
n_bits
(
N_size
)
;
s
++
)
{
m
=
powl
(
2
,
s
);
omega_m
=
cexpf
(
-
2
*
I
/
m
);
for
(
int
k
=
0
;
k
<
n
;
k
+=
m
)
phi
=
-
2
*
EIGEN_PI
/
m
;
omega_m
=
std
::
complex
<
float
>
(
cos
(
phi
),
sin
(
phi
));
for
(
int
k
=
0
;
k
<
N_size
;
k
+=
m
)
{
omega
=
std
::
complex
<
float
>
(
1
,
0
);
for
(
int
j
=
0
;
j
<
m
/
2
;
j
++
)
...
...
@@ -94,21 +91,24 @@ public:
* @brief Get the frequency used in the FFT
* (only the first half, useful for real input functions)
*
* @param
input_signal
* @param
sample_rate in Hertz
* @return Eigen::Vector<std::complex<float>, N_size>
*/
static
const
VectorHF
fftfreq
(
in
t
sample_rate
)
static
const
VectorHF
fftfreq
(
floa
t
sample_rate
)
{
VectorHF
bins
=
VectorF
::
Zero
();
VectorHF
bins
=
Vector
H
F
::
Zero
();
for
(
int
i
=
0
;
i
<
N_size
/
2
;
i
++
)
{
bins
(
i
)
=
(
float
)
i
*
(
float
)
sample_rate
/
(
float
)
N_size
;
bins
(
i
)
=
(
float
)
i
*
sample_rate
/
(
float
)
N_size
;
}
return
bins
;
}
private
:
static
const
short
n_bits
=
log2f
(
N_size
);
static
short
n_bits
(
size_t
x
)
{
return
(
short
)
log2
(
x
);
}
/**
* @brief Reverse the bits of the inputted unsigned index.
...
...
@@ -117,14 +117,22 @@ private:
*/
static
size_t
reverse_bits
(
size_t
x
)
{
size_t
rev
=
0
for
(
int
i
=
0
;
i
<
n_bits
;
i
++
)
size_t
rev
=
0
;
short
bits
=
n_bits
(
N_size
);
for
(
int
i
=
0
;
i
<
bits
;
i
++
)
{
if
(
x
&
(
1
<<
i
))
rev
|=
1
<<
(
N_size
-
1
-
i
);
{
rev
|=
1
<<
(
bits
-
1
-
i
);
}
}
return
rev
;
}
};
typedef
FFT
<
32
>
FFT32
;
typedef
FFT
<
64
>
FFT64
;
typedef
FFT
<
128
>
FFT128
;
typedef
FFT
<
256
>
FFT256
;
}
// namespace Boardcore
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment