23 static void dsp_fourier_dft_magnitude(
dsp_stream_p stream)
41 for(x = 0; x < stream->
len && y < stream->
len; x++) {
43 if(pos[0] <= stream->
sizes[0] / 2) {
52 dsp_fourier_dft_magnitude(stream);
54 dsp_fourier_dft_phase(stream);
69 for(x = 0; x < stream->
len; x++) {
71 if(pos[0] <= stream->
sizes[0] / 2) {
84 double* out = (
double*)malloc(
sizeof(
double) * len);
85 for(i = 0; i < len; i++) {
88 out [i] = sqrt (pow(real, 2)+pow(imaginary, 2));
96 double* out = (
double*)malloc(
sizeof(
double) * len);
97 for(i = 0; i < len; i++) {
102 double mag = sqrt(pow(real, 2)+pow(imaginary, 2));
105 rad = acos (imaginary / (mag > 0.0 ? mag : 1.0));
106 if(real < 0 && rad != 0)
118 for(i = 0; i < len; i++) {
119 double real = sin(phi[i])*mag[i];
120 double imaginary = cos(phi[i])*mag[i];
122 out[i][1] = imaginary;
126 static void* dsp_stream_dft_th(
void* arg)
139 double* buf = (
double*)malloc(
sizeof(
double) * stream->
len);
140 if(stream->
phase == NULL)
146 int *sizes = (
int*)malloc(
sizeof(
int)*stream->
dims);
148 fftw_plan plan = fftw_plan_dft_r2c(stream->
dims, stream->
sizes, buf, stream->
dft.
pairs, FFTW_ESTIMATE_PATIENT);
160 } thread_arguments[2];
161 thread_arguments[0].exp = exp;
162 thread_arguments[0].stream = stream->
phase;
163 pthread_create(&
th[0], NULL, dsp_stream_dft_th, &thread_arguments[0]);
164 thread_arguments[1].exp = exp;
165 thread_arguments[1].stream = stream->
magnitude;
166 pthread_create(&
th[1], NULL, dsp_stream_dft_th, &thread_arguments[1]);
167 pthread_join(
th[0], NULL);
168 pthread_join(
th[1], NULL);
174 double *buf = (
double*)malloc(
sizeof(
double)*stream->
len);
179 int *sizes = (
int*)malloc(
sizeof(
int)*stream->
dims);
181 fftw_plan plan = fftw_plan_dft_c2r(stream->
dims, stream->
sizes, stream->
dft.
pairs, buf, FFTW_ESTIMATE_PATIENT);
struct dsp_stream_t * phase
Fourier transform phase.
double imaginary
Imaginary part of the complex number.
int * sizes
Sizes of each dimension.
dsp_complex dft
Fourier transform.
double * buf
Linear double array containing complex numbers.
struct dsp_stream_t * magnitude
Fourier transform magnitude.
struct dsp_complex::@215 * complex
Complex struct type array.
int dims
Number of dimensions of the buffers.
int len
The buffers length.
double real
Real part of the complex number.
complex_t * pairs
Complex number type array used with libFFTW.
#define dsp_buffer_copy(in, out, len)
Fill the output buffer with the values of the elements of the input stream by casting them to the out...
void dsp_buffer_shift(dsp_stream_p stream)
Shift a stream on each dimension.
#define dsp_buffer_set(buf, len, _val)
Fill the buffer with the passed value.
#define dsp_buffer_reverse(buf, len)
Reverse the order of the buffer elements.
#define dsp_buffer_stretch(buf, len, _mn, _mx)
Stretch minimum and maximum values of the input stream.
DLL_EXPORT int * dsp_stream_get_position(dsp_stream_p stream, int index)
Return the multidimensional positional indexes of a DSP stream by specify a linear index.
DLL_EXPORT dsp_stream_p dsp_stream_copy(dsp_stream_p stream)
Create a copy of the DSP stream passed as argument.
#define dsp_stats_min(buf, len)
Gets the minimum value of the input stream.
#define dsp_stats_max(buf, len)
Gets the maximum value of the input stream.
Contains a set of informations and data relative to a buffer and how to use it.
Complex number array struct, used in Fourier Transform functions.