Instrument Neutral Distributed Interface INDI  2.0.2
convolution.c
Go to the documentation of this file.
1 /*
2 * DSP API - a digital signal processing library for astronomy usage
3 * Copyright © 2017-2022 Ilia Platone
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "dsp.h"
21 
23  int x, y, d;
24  dsp_t mn = dsp_stats_min(stream->buf, stream->len);
25  dsp_t mx = dsp_stats_max(stream->buf, stream->len);
26  int* d_pos = (int*)malloc(sizeof(int)*stream->dims);
27  for(y = 0; y < matrix->len; y++) {
28  int* pos = dsp_stream_get_position(matrix, y);
29  for(d = 0; d < stream->dims; d++) {
30  d_pos[d] = stream->sizes[d]/2+pos[d]-matrix->sizes[d]/2;
31  }
32  x = dsp_stream_set_position(stream, d_pos);
33  free(pos);
34  stream->magnitude->buf[x] *= sqrt(matrix->magnitude->buf[y]);
35  }
36  free(d_pos);
37  dsp_fourier_idft(stream);
38  dsp_buffer_stretch(stream->buf, stream->len, mn, mx);
39 }
40 
42  int x, y, d;
43  dsp_t mn = dsp_stats_min(stream->buf, stream->len);
44  dsp_t mx = dsp_stats_max(stream->buf, stream->len);
45  int* d_pos = (int*)malloc(sizeof(int)*stream->dims);
46  dsp_buffer_shift(matrix->magnitude);
47  for(y = 0; y < matrix->len; y++) {
48  int* pos = dsp_stream_get_position(matrix, y);
49  for(d = 0; d < stream->dims; d++) {
50  d_pos[d] = stream->sizes[d]/2+pos[d]-matrix->sizes[d]/2;
51  }
52  x = dsp_stream_set_position(stream, d_pos);
53  free(pos);
54  stream->magnitude->buf[x] *= sqrt(matrix->magnitude->buf[y]);
55  }
56  dsp_buffer_shift(matrix->magnitude);
57  free(d_pos);
58  dsp_fourier_idft(stream);
59  dsp_buffer_stretch(stream->buf, stream->len, mn, mx);
60 }
double dsp_t
Definition: dsp.h:69
int * sizes
Sizes of each dimension.
Definition: dsp.h:373
struct dsp_stream_t * magnitude
Fourier transform magnitude.
Definition: dsp.h:411
int dims
Number of dimensions of the buffers.
Definition: dsp.h:371
dsp_t * buf
buffer
Definition: dsp.h:375
int len
The buffers length.
Definition: dsp.h:369
void dsp_buffer_shift(dsp_stream_p stream)
Shift a stream on each dimension.
Definition: buffer.c:24
#define dsp_buffer_stretch(buf, len, _mn, _mx)
Stretch minimum and maximum values of the input stream.
Definition: dsp.h:792
void dsp_convolution_correlation(dsp_stream_p stream, dsp_stream_p matrix)
A cross-correlation processor.
Definition: convolution.c:41
void dsp_convolution_convolution(dsp_stream_p stream, dsp_stream_p matrix)
A cross-convolution processor.
Definition: convolution.c:22
DLL_EXPORT int dsp_stream_set_position(dsp_stream_p stream, int *pos)
Obtain the position the DSP stream by parsing multidimensional indexes.
Definition: stream.c:440
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.
Definition: stream.c:420
DLL_EXPORT void dsp_fourier_idft(dsp_stream_p stream)
Perform an inverse discrete Fourier Transform of a dsp_stream.
Definition: fft.c:172
#define dsp_stats_min(buf, len)
Gets the minimum value of the input stream.
Definition: dsp.h:562
#define dsp_stats_max(buf, len)
Gets the maximum value of the input stream.
Definition: dsp.h:580
Contains a set of informations and data relative to a buffer and how to use it.
Definition: dsp.h:363