Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66365926
fft.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 10, 02:24
Size
1 KB
Mime Type
text/x-c
Expires
Wed, Jun 12, 02:24 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18211387
Attached To
R7554 sp4e_exercices
fft.hh
View Options
#ifndef FFT_HH
#define FFT_HH
/* ------------------------------------------------------ */
#include "matrix.hh"
#include "my_types.hh"
#include <fftw3.h>
/* ------------------------------------------------------ */
struct
FFT
{
static
Matrix
<
complex
>
transform
(
Matrix
<
complex
>
&
m
);
static
Matrix
<
complex
>
itransform
(
Matrix
<
complex
>
&
m
);
static
Matrix
<
std
::
complex
<
int
>>
computeFrequencies
(
int
size
);
};
/* ------------------------------------------------------ */
inline
Matrix
<
complex
>
FFT
::
transform
(
Matrix
<
complex
>
&
m_in
)
{
fftw_plan
p
;
int
N
=
m_in
.
rows
();
// same as int n1 = m_in.cols();
Matrix
<
complex
>
m_out
(
N
);
// reinterpret cast
complex
*
c
=
m_in
.
data
();
auto
*
c_in
=
reinterpret_cast
<
fftw_complex
*>
(
c
);
c
=
m_out
.
data
();
auto
*
c_out
=
reinterpret_cast
<
fftw_complex
*>
(
c
);
p
=
fftw_plan_dft_2d
(
N
,
N
,
c_in
,
c_out
,
FFTW_FORWARD
,
FFTW_ESTIMATE
);
fftw_execute
(
p
);
fftw_destroy_plan
(
p
);
return
m_out
;
}
/* ------------------------------------------------------ */
inline
Matrix
<
complex
>
FFT
::
itransform
(
Matrix
<
complex
>
&
m_in
)
{
fftw_plan
p
;
int
N
=
m_in
.
rows
();
// same as int n1 = m_in.cols();
Matrix
<
complex
>
m_out
(
N
);
// reinterpret cast
complex
*
c
=
m_in
.
data
();
auto
*
c_in
=
reinterpret_cast
<
fftw_complex
*>
(
c
);
c
=
m_out
.
data
();
auto
*
c_out
=
reinterpret_cast
<
fftw_complex
*>
(
c
);
p
=
fftw_plan_dft_2d
(
N
,
N
,
c_in
,
c_out
,
FFTW_BACKWARD
,
FFTW_ESTIMATE
);
fftw_execute
(
p
);
fftw_destroy_plan
(
p
);
double
rescale
=
1.
/
(
N
*
N
);
for
(
auto
&&
entry
:
index
(
m_out
))
{
auto
&
val
=
std
::
get
<
2
>
(
entry
);
val
*=
rescale
;
}
return
m_out
;
}
/* ------------------------------------------------------ */
/* ------------------------------------------------------ */
inline
Matrix
<
std
::
complex
<
int
>>
FFT
::
computeFrequencies
(
int
size
)
{}
#endif
// FFT_HH
Event Timeline
Log In to Comment