Instrument Neutral Distributed Interface INDI 2.2.5
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 if(x >= 0 && x < stream->magnitude->len)
35 stream->magnitude->buf[x] *= sqrt(matrix->magnitude->buf[y]);
36 }
37 free(d_pos);
38 dsp_fourier_idft(stream);
39 dsp_buffer_stretch(stream->buf, stream->len, mn, mx);
40}
41
43 int x, y, d;
44 dsp_t mn = dsp_stats_min(stream->buf, stream->len);
45 dsp_t mx = dsp_stats_max(stream->buf, stream->len);
46 int* d_pos = (int*)malloc(sizeof(int)*stream->dims);
48 for(y = 0; y < matrix->len; y++) {
49 int* pos = dsp_stream_get_position(matrix, y);
50 for(d = 0; d < stream->dims; d++) {
51 d_pos[d] = stream->sizes[d]/2+pos[d]-matrix->sizes[d]/2;
52 }
53 x = dsp_stream_set_position(stream, d_pos);
54 free(pos);
55 stream->magnitude->buf[x] *= sqrt(matrix->magnitude->buf[y]);
56 }
58 free(d_pos);
59 dsp_fourier_idft(stream);
60 dsp_buffer_stretch(stream->buf, stream->len, mn, mx);
61}
double dsp_t
Definition dsp.h:76
int * sizes
Sizes of each dimension.
Definition dsp.h:389
struct dsp_stream_t * magnitude
Fourier transform magnitude.
Definition dsp.h:427
int dims
Number of dimensions of the buffers.
Definition dsp.h:387
dsp_t * buf
buffer
Definition dsp.h:391
int len
The buffers length.
Definition dsp.h:385
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:808
void dsp_convolution_correlation(dsp_stream_p stream, dsp_stream_p matrix)
A cross-correlation processor.
Definition convolution.c:42
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:471
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:451
DLL_EXPORT void dsp_fourier_idft(dsp_stream_p stream)
Perform an inverse discrete Fourier Transform of a dsp_stream.
Definition fft.c:173
#define dsp_stats_min(buf, len)
Gets the minimum value of the input stream.
Definition dsp.h:578
#define dsp_stats_max(buf, len)
Gets the maximum value of the input stream.
Definition dsp.h:596
Contains a set of information and data relative to a buffer and how to use it.
Definition dsp.h:379