Open source Very Long Baseline Interferometry
OpenVLBI
dsp.h
1 /* libDSP - a digital signal processing library
2  * Copyright © 2017-2022 Ilia Platone
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef _DSP_H
20 #define _DSP_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #ifndef DLL_EXPORT
27 #define DLL_EXPORT extern
28 #endif
29 
30 #ifdef __linux__
31 #include <endian.h>
32 #else
33 #define __bswap_16(a) __builtin_bswap16(a)
34 #define __bswap_32(a) __builtin_bswap32(a)
35 #define __bswap_64(a) __builtin_bswap64(a)
36 #endif
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <math.h>
41 #include <float.h>
42 #include <sys/types.h>
43 #include <time.h>
44 #include <assert.h>
45 #include <pthread.h>
46 #include <fftw3.h>
47 
68 #define DSP_MAX_STARS 200
69 #define dsp_t double
70 #define dsp_t_max 255
71 #define dsp_t_min -dsp_t_max
72 
78 DLL_EXPORT unsigned long int dsp_max_threads(unsigned long value);
79 
80 #ifndef DSP_DEBUG
81 #define DSP_DEBUG
86 DLL_EXPORT void dsp_set_debug_level(int value);
91 DLL_EXPORT int dsp_get_debug_level();
96 DLL_EXPORT void dsp_set_app_name(char* name);
101 DLL_EXPORT char* dsp_get_app_name();
106 DLL_EXPORT void dsp_set_stdout(FILE *f);
111 DLL_EXPORT void dsp_set_stderr(FILE *f);
112 
118 DLL_EXPORT void dsp_print(int x, char* str);
119 
120 #define DSP_DEBUG_INFO 0
121 #define DSP_DEBUG_ERROR 1
122 #define DSP_DEBUG_WARNING 2
123 #define DSP_DEBUG_DEBUG 3
124 #define pdbg(x, ...) ({ \
125 char str[500]; \
126 struct timespec ts; \
127 time_t t = time(NULL); \
128 struct tm tm = *localtime(&t); \
129 clock_gettime(CLOCK_REALTIME, &ts); \
130 sprintf(str, "[%04d-%02d-%02dT%02d:%02d:%02d.%03ld ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec/1000000); \
131 switch(x) { \
132  case DSP_DEBUG_ERROR: \
133  sprintf(&str[strlen(str)], "ERRO]"); \
134  break; \
135  case DSP_DEBUG_WARNING: \
136  sprintf(&str[strlen(str)], "WARN]"); \
137  break; \
138  case DSP_DEBUG_DEBUG: \
139  sprintf(&str[strlen(str)], "DEBG]"); \
140  break; \
141  default: \
142  sprintf(&str[strlen(str)], "INFO]"); \
143  break; \
144 } \
145 if(dsp_get_app_name() != NULL) \
146  sprintf(&str[strlen(str)], "[%s]", dsp_get_app_name()); \
147 sprintf(&str[strlen(str)], " "); \
148 sprintf(&str[strlen(str)], __VA_ARGS__); \
149 dsp_print(x, str); \
150 })
151 #define pinfo(...) pdbg(DSP_DEBUG_INFO, __VA_ARGS__)
152 #define perr(...) pdbg(DSP_DEBUG_ERROR, __VA_ARGS__)
153 #define pwarn(...) pdbg(DSP_DEBUG_WARNING, __VA_ARGS__)
154 #define pgarb(...) pdbg(DSP_DEBUG_DEBUG, __VA_ARGS__)
155 #define pfunc pgarb("%s\n", __func__)
156 #define start_gettime
157 #define end_gettime
158 #else
159 #define pinfo(...)
160 #define perr(...)
161 #define pwarn(...)
162 #define pgarb(...)
163 #define pfunc(...)
164 #define start_gettime(...)
165 #define end_gettime(...)
166 #endif
167 
168 
170 #ifndef Min
171 #define Min(a,b) \
172  ({ __typeof (a) _a = (a); \
173  __typeof (a) _b = (b); \
174  _a < _b ? _a : _b; })
175 #endif
177 #ifndef Max
178 #define Max(a,b) \
179  ({ __typeof (a) _a = (a); \
180  __typeof (a) _b = (b); \
181  _a > _b ? _a : _b; })
182 #endif
184 #ifndef Log
185 #define Log(a,b) \
186 ( log(a) / log(b) )
187 #endif
188 #ifndef DSP_ALIGN_TRANSLATED
190 #define DSP_ALIGN_TRANSLATED 1
191 #endif
192 #ifndef DSP_ALIGN_SCALED
194 #define DSP_ALIGN_SCALED 2
195 #endif
196 #ifndef DSP_ALIGN_ROTATED
198 #define DSP_ALIGN_ROTATED 4
199 #endif
200 #ifndef DSP_ALIGN_NO_MATCH
202 #define DSP_ALIGN_NO_MATCH 8
203 #endif
214 typedef struct dsp_point_t
215 {
217  double* location;
219  int dims;
221 
225 typedef struct dsp_offset_t
226 {
228  double* offset;
230  int dims;
232 
236 typedef struct dsp_star_t
237 {
241  double diameter;
243  char name[150];
245 
249 typedef struct dsp_triangle_t
250 {
252  double index;
254  int dims;
256  double theta;
258  double *sizes;
260  double *ratios;
264 
268 typedef struct dsp_align_info_t
269 {
271  double* offset;
273  double* center;
275  double* radians;
277  double* factor;
279  int dims;
285  double score;
287  double decimals;
289  int err;
291 
296 typedef union
297 {
299  struct
300  {
302  double real;
304  double imaginary;
305  } *complex;
307  fftw_complex *fftw;
309  double *buf;
310 } dsp_complex;
311 
315 typedef struct dsp_region_t
316 {
318  int start;
320  int len;
322 
326 typedef union dsp_location_t
327 {
329  struct
330  {
331  double x;
332  double y;
333  double z;
334  } xyz;
336  struct
337  {
338  double lon;
339  double lat;
340  double el;
343  double coordinates[3];
345 
349 typedef void *(*dsp_func_t) (void *, ...);
350 
361 typedef struct dsp_stream_t
362 {
364  char name[128];
366  int is_copy;
368  int len;
370  int dims;
372  int* sizes;
374  dsp_t* buf;
378  void *arg;
388  double* target;
390  struct timespec starttimeutc;
392  double wavelength;
394  double focal_ratio;
396  double diameter;
398  double SNR;
400  int red;
402  double *pixel_sizes;
404  double samplerate;
406  pthread_t thread;
428 
440 DLL_EXPORT void dsp_fourier_dft(dsp_stream_p stream, int exp);
441 
446 DLL_EXPORT void dsp_fourier_idft(dsp_stream_p stream);
447 
452 DLL_EXPORT void dsp_fourier_2dsp(dsp_stream_p stream);
453 
458 DLL_EXPORT void dsp_fourier_2fftw(dsp_stream_p stream);
459 
467 DLL_EXPORT dsp_complex dsp_fourier_phase_mag_array_get_complex(double* mag, double* phi, int len);
468 
476 
484 
494 DLL_EXPORT void dsp_filter_squarelaw(dsp_stream_p stream);
495 
501 DLL_EXPORT void dsp_filter_lowpass(dsp_stream_p stream, double frequency);
502 
508 DLL_EXPORT void dsp_filter_highpass(dsp_stream_p stream, double frequency);
509 
516 DLL_EXPORT void dsp_filter_bandpass(dsp_stream_p stream, double LowFrequency,
517  double HighFrequency);
518 
525 DLL_EXPORT void dsp_filter_bandreject(dsp_stream_p stream, double LowFrequency,
526  double HighFrequency);
527 
538 DLL_EXPORT void dsp_convolution_convolution(dsp_stream_p stream, dsp_stream_p matrix);
539 
545 DLL_EXPORT void dsp_convolution_correlation(dsp_stream_p stream, dsp_stream_p matrix);
546 
553 #ifndef dsp_stats_min
560 #define dsp_stats_min(buf, len)\
561 ({\
562  int i;\
563  __typeof(buf[0]) min = (__typeof(buf[0]))buf[0];\
564  for(i = 0; i < len; i++) {\
565  min = Min(buf[i], min);\
566  }\
567  min;\
568  })
569 #endif
570 
571 #ifndef dsp_stats_max
578 #define dsp_stats_max(buf, len)\
579 ({\
580  int i;\
581  __typeof(buf[0]) max = (__typeof(buf[0]))buf[0];\
582  for(i = 0; i < len; i++) {\
583  max = Max(buf[i], max);\
584  }\
585  max;\
586  })
587 #endif
588 
589 #ifndef dsp_stats_mid
596 #define dsp_stats_mid(buf, len)\
597 ({\
598  int i;\
599  __typeof(buf[0]) min = dsp_stats_min(buf, len);\
600  (__typeof(buf[0]))(min - dsp_stats_max(buf, len)) / 2.0 + min;\
601 })
602 #endif
603 
604 #ifndef dsp_stats_maximum_index
611 #define dsp_stats_minimum_index(buf, len)\
612 ({\
613  int i;\
614  __typeof(buf[0]) min = dsp_stats_min(buf, len);\
615  for(i = 0; i < len; i++) {\
616  if(buf[i] == min) break;\
617  }\
618  i;\
619  })
620 #endif
621 
622 #ifndef dsp_stats_maximum_index
629 #define dsp_stats_maximum_index(buf, len)\
630 ({\
631  int i;\
632  __typeof(buf[0]) max = dsp_stats_max(buf, len);\
633  for(i = 0; i < len; i++) {\
634  if(buf[i] == max) break;\
635  }\
636  i;\
637  })
638 #endif
639 
640 #ifndef dsp_stats_stddev
647 #define dsp_stats_mean(buf, len)\
648 ({\
649  int __dsp__i;\
650  double __dsp__mean = 0;\
651  for(__dsp__i = 0; __dsp__i < len; __dsp__i++) {\
652  __dsp__mean += buf[__dsp__i];\
653  }\
654  __dsp__mean /= len;\
655  __dsp__mean;\
656  })
657 #endif
658 
659 #ifndef dsp_stats_stddev
665 #define dsp_stats_stddev(buf, len)\
666 ({\
667  double __dsp__mean = dsp_stats_mean(buf, len);\
668  int __dsp__x;\
669  double __dsp__stddev = 0;\
670  for(__dsp__x = 0; __dsp__x < len; __dsp__x++) {\
671  __dsp__stddev += fabs(buf[__dsp__x] - __dsp__mean);\
672  }\
673  __dsp__stddev /= len;\
674  __dsp__stddev;\
675  })
676 #endif
677 
678 #ifndef dsp_stats_val_count
686 #define dsp_stats_val_count(buf, len, val) \
687 ({\
688  int x;\
689  int count = 0;\
690  for(x = 0; x < len; x++) {\
691  if(buf[x] == val)\
692  count ++;\
693  }\
694  count;\
695  })
696 #endif
697 
698 #ifndef dsp_stats_val_sum
705 #define dsp_stats_val_sum(buf, len) \
706 ({\
707  int x;\
708  double sum = 0;\
709  for(x = 0; x < len; x++) {\
710  sum += buf[x];\
711  }\
712  sum;\
713  })
714 #endif
715 
716 #ifndef dsp_stats_range_count
725 #define dsp_stats_range_count(buf, len, lo, hi) \
726 ({\
727  int x;\
728  int count = 0;\
729  for(x = 0; x < len; x++) {\
730  if(buf[x] < hi && buf[x] >= lo)\
731  count ++;\
732  }\
733  count;\
734  })
735 #endif
736 
737 #ifndef dsp_stats_compare
745 #define dsp_stats_compare(in1, in2, len)\
746 ({\
747  __typeof(in1[0]) out = 0;\
748  for(int i = 0; i < len; i++) {\
749  out += in1[i] - (__typeof(in1[0]))in2[i];\
750  }\
751  out;\
752  })
753 #endif
754 
762 DLL_EXPORT double* dsp_stats_histogram(dsp_stream_p stream, int size);
763 
774 DLL_EXPORT void dsp_buffer_shift(dsp_stream_p stream);
775 
780 DLL_EXPORT void dsp_buffer_removemean(dsp_stream_p stream);
781 
782 #ifndef dsp_buffer_stretch
790 #define dsp_buffer_stretch(buf, len, _mn, _mx)\
791 ({\
792  int k;\
793  __typeof(buf[0]) __mn = dsp_stats_min(buf, len);\
794  __typeof(buf[0]) __mx = dsp_stats_max(buf, len);\
795  double oratio = (_mx - _mn);\
796  double iratio = (__mx - __mn);\
797  if(iratio == 0) iratio = 1;\
798  for(k = 0; k < len; k++) {\
799  buf[k] -= __mn;\
800  buf[k] = (__typeof(buf[0]))((double)buf[k] * oratio / iratio);\
801  buf[k] += _mn;\
802  }\
803 })
804 #endif
805 
806 #ifndef dsp_buffer_set
813 #define dsp_buffer_set(buf, len, _val)\
814 ({\
815  int k;\
816  for(k = 0; k < len; k++) {\
817  buf[k] = (__typeof(buf[0]))(_val);\
818  }\
819 })
820 #endif
821 
822 #ifndef dsp_buffer_normalize
830 #define dsp_buffer_normalize(buf, len, mn, mx)\
831 ({\
832  int k;\
833  for(k = 0; k < len; k++) {\
834  buf[k] = Max(mn, Min(mx, buf[k]));\
835  }\
836 })
837 #endif
838 
845 DLL_EXPORT void dsp_buffer_max(dsp_stream_p stream, dsp_t* in, int len);
846 
853 DLL_EXPORT void dsp_buffer_min(dsp_stream_p stream, dsp_t* in, int len);
854 
861 DLL_EXPORT void dsp_buffer_sub(dsp_stream_p stream, dsp_t* in, int len);
862 
869 DLL_EXPORT void dsp_buffer_sum(dsp_stream_p stream, dsp_t* in, int len);
870 
877 DLL_EXPORT void dsp_buffer_div(dsp_stream_p stream, dsp_t* in, int len);
878 
885 DLL_EXPORT void dsp_buffer_mul(dsp_stream_p stream, dsp_t* in, int len);
886 
893 DLL_EXPORT void dsp_buffer_pow(dsp_stream_p stream, dsp_t* in, int len);
894 
901 DLL_EXPORT void dsp_buffer_log(dsp_stream_p stream, dsp_t* in, int len);
902 
908 DLL_EXPORT void dsp_buffer_sub1(dsp_stream_p stream, dsp_t val);
909 
915 DLL_EXPORT void dsp_buffer_1sub(dsp_stream_p stream, dsp_t val);
916 
922 DLL_EXPORT void dsp_buffer_sum1(dsp_stream_p stream, dsp_t val);
923 
929 DLL_EXPORT void dsp_buffer_div1(dsp_stream_p stream, double val);
930 
936 DLL_EXPORT void dsp_buffer_1div(dsp_stream_p stream, double val);
937 
943 DLL_EXPORT void dsp_buffer_mul1(dsp_stream_p stream, double val);
944 
950 DLL_EXPORT void dsp_buffer_pow1(dsp_stream_p stream, double val);
951 
957 DLL_EXPORT void dsp_buffer_log1(dsp_stream_p stream, double val);
958 
965 DLL_EXPORT void dsp_buffer_median(dsp_stream_p stream, int size, int median);
966 
972 DLL_EXPORT void dsp_buffer_sigma(dsp_stream_p stream, int size);
973 
981 DLL_EXPORT void dsp_buffer_deviate(dsp_stream_p stream, dsp_t* deviation, dsp_t mindeviation, dsp_t maxdeviation);
982 
983 #ifndef dsp_buffer_reverse
989 #define dsp_buffer_reverse(buf, len) \
990  ({ \
991  int i = (len - 1) / 2; \
992  int j = i + 1; \
993  __typeof(buf[0]) _x; \
994  while(i >= 0) \
995  { \
996  _x = buf[j]; \
997  buf[j] = buf[i]; \
998  buf[i] = _x; \
999  i--; \
1000  j++; \
1001  } \
1002  })
1003 #endif
1004 
1005 #ifndef dsp_buffer_swap
1011 #define dsp_buffer_swap(in, len) \
1012  ({ \
1013  int k; \
1014  switch(sizeof(((__typeof (in[0])*)in)[0])) { \
1015  case 2: \
1016  for(k = 0; k < len; k++) \
1017  ((__typeof (in[0])*)in)[k] = __bswap_16(((__typeof (in[0])*)in)[k]); \
1018  break; \
1019  case 3: \
1020  for(k = 0; k < len; k++) \
1021  ((__typeof (in[0])*)in)[k] = __bswap_32(((__typeof (in[0])*)in)[k]); \
1022  break; \
1023  } \
1024  })
1025 #endif
1026 
1027 #ifndef dsp_buffer_copy
1036 #define dsp_buffer_copy(in, out, len) \
1037  ({ \
1038  int k; \
1039  for(k = 0; k < len; k++) { \
1040  ((__typeof (out[0])*)out)[k] = (__typeof (out[0]))((__typeof (in[0])*)in)[k]; \
1041  } \
1042  })
1043 #endif
1044 
1045 #ifndef dsp_buffer_copy_stepping
1057 #define dsp_buffer_copy_stepping(in, out, inlen, outlen, instep, outstep) \
1058  ({ \
1059  int k; \
1060  int t; \
1061  for(k = 0, t = 0; k < inlen && t < outlen; k+=instep, t+=outstep) { \
1062  ((__typeof (out[0])*)out)[t] = (__typeof (out[0]))((__typeof (in[0])*)in)[k]; \
1063  } \
1064  })
1065 #endif
1066 
1078 DLL_EXPORT void dsp_stream_alloc_buffer(dsp_stream_p stream, int len);
1079 
1086 DLL_EXPORT void dsp_stream_set_buffer(dsp_stream_p stream, void *buffer, int len);
1087 
1093 DLL_EXPORT dsp_t* dsp_stream_get_buffer(dsp_stream_p stream);
1094 
1099 DLL_EXPORT void dsp_stream_free_buffer(dsp_stream_p stream);
1100 
1106 DLL_EXPORT dsp_stream_p dsp_stream_new(void);
1107 
1113 DLL_EXPORT void dsp_stream_free(dsp_stream_p stream);
1114 
1122 
1130 DLL_EXPORT void dsp_stream_add_child(dsp_stream_p stream, dsp_stream_p child);
1131 
1139 DLL_EXPORT void dsp_stream_add_star(dsp_stream_p stream, dsp_star star);
1140 
1148 DLL_EXPORT void dsp_stream_del_star(dsp_stream_p stream, int n);
1149 
1157 DLL_EXPORT void dsp_stream_add_triangle(dsp_stream_p stream, dsp_triangle triangle);
1158 
1166 DLL_EXPORT void dsp_stream_del_triangle(dsp_stream_p stream, int index);
1167 
1174 DLL_EXPORT void dsp_stream_calc_triangles(dsp_stream_p stream);
1175 
1183 DLL_EXPORT void dsp_stream_del_child(dsp_stream_p stream, int n);
1184 
1192 DLL_EXPORT void dsp_stream_add_dim(dsp_stream_p stream, int len);
1193 
1202 DLL_EXPORT void dsp_stream_set_dim(dsp_stream_p stream, int dim, int size);
1203 
1211 DLL_EXPORT void dsp_stream_del_dim(dsp_stream_p stream, int n);
1212 
1223 DLL_EXPORT int dsp_stream_set_position(dsp_stream_p stream, int *pos);
1224 
1235 DLL_EXPORT int* dsp_stream_get_position(dsp_stream_p stream, int index);
1236 
1246 DLL_EXPORT void *dsp_stream_exec(dsp_stream_p stream, void *args, ...);
1247 
1252 DLL_EXPORT void dsp_stream_crop(dsp_stream_p stream);
1253 
1258 DLL_EXPORT void dsp_stream_rotate(dsp_stream_p stream);
1259 
1264 DLL_EXPORT void dsp_stream_translate(dsp_stream_p stream);
1265 
1270 DLL_EXPORT void dsp_stream_scale(dsp_stream_p stream);
1271 
1282 DLL_EXPORT void dsp_signals_whitenoise(dsp_stream_p stream);
1283 
1290 DLL_EXPORT void dsp_signals_sinewave(dsp_stream_p stream, double samplefreq, double freq);
1291 
1298 DLL_EXPORT void dsp_signals_sawtoothwave(dsp_stream_p stream, double samplefreq, double freq);
1299 
1306 DLL_EXPORT void dsp_signals_triwave(dsp_stream_p stream, double samplefreq, double freq);
1307 
1315 DLL_EXPORT void dsp_modulation_frequency(dsp_stream_p stream, double samplefreq, double freq, double bandwidth);
1316 
1323 DLL_EXPORT void dsp_modulation_amplitude(dsp_stream_p stream, double samplefreq, double freq);
1324 
1338 DLL_EXPORT dsp_stream_p* dsp_file_read_fits(const char* filename, int *channels, int stretch);
1339 
1346 DLL_EXPORT void dsp_file_write_fits(const char* filename, int bpp, dsp_stream_p stream);
1347 
1355 DLL_EXPORT void dsp_file_write_fits_composite(const char* filename, int components, int bpp, dsp_stream_p* stream);
1356 
1365 DLL_EXPORT dsp_stream_p* dsp_file_read_jpeg(const char* filename, int *channels, int stretch);
1366 
1373 DLL_EXPORT void dsp_file_write_jpeg(const char* filename, int quality, dsp_stream_p stream);
1374 
1382 DLL_EXPORT void dsp_file_write_jpeg_composite(const char* filename, int components, int quality, dsp_stream_p* stream);
1383 
1392 DLL_EXPORT dsp_stream_p* dsp_file_read_png(const char* filename, int *channels, int stretch);
1393 
1401 DLL_EXPORT void dsp_file_write_png_composite(const char* filename, int components, int compression, dsp_stream_p* stream);
1402 
1410 DLL_EXPORT dsp_t* dsp_file_bayer_2_gray(dsp_t* src, int width, int height);
1411 
1420 DLL_EXPORT dsp_t* dsp_file_bayer_2_rgb(dsp_t *src, int red, int width, int height);
1421 
1430 DLL_EXPORT dsp_stream_p *dsp_stream_from_components(dsp_t* buf, int dims, int *sizes, int components);
1431 
1442 DLL_EXPORT dsp_stream_p *dsp_buffer_rgb_to_components(void* buf, int dims, int *sizes, int components, int bpp, int stretch);
1443 
1451 DLL_EXPORT void dsp_buffer_components_to_rgb(dsp_stream_p *stream, void* rgb, int components, int bpp);
1452 
1461 DLL_EXPORT dsp_t* dsp_file_composite_2_bayer(dsp_stream_p *src, int red, int width, int height);
1462 
1470 DLL_EXPORT void dsp_file_write_fits_bayer(const char* filename, int components, int bpp, dsp_stream_p* stream);
1471 
1480 DLL_EXPORT dsp_t* dsp_file_bayer_2_composite(dsp_t *src, int red, int width, int height);
1481 
1490 DLL_EXPORT int dsp_align_get_offset(dsp_stream_p ref, dsp_stream_p to_align, double tolerance, double target_score);
1491 
1498 DLL_EXPORT int dsp_qsort_double_asc (const void *arg1, const void *arg2);
1499 
1506 DLL_EXPORT int dsp_qsort_double_desc (const void *arg1, const void *arg2);
1507 
1514 DLL_EXPORT int dsp_qsort_star_diameter_asc (const void *arg1, const void *arg2);
1515 
1522 DLL_EXPORT int dsp_qsort_star_diameter_desc (const void *arg1, const void *arg2);
1523 
1526 #include <fits_extensions.h>
1527 
1528 #ifdef __cplusplus
1529 }
1530 #endif
1531 
1532 #endif //_DSP_H
DLL_EXPORT int dsp_get_debug_level()
get the debug level
DLL_EXPORT void dsp_set_stderr(FILE *f)
set the error log streeam
DLL_EXPORT unsigned long int dsp_max_threads(unsigned long value)
get/set the maximum number of threads allowed
DLL_EXPORT void dsp_set_debug_level(int value)
set the debug level
DLL_EXPORT void dsp_set_stdout(FILE *f)
set the output log streeam
DLL_EXPORT void dsp_print(int x, char *str)
log a message to the error or output streams
DLL_EXPORT char * dsp_get_app_name()
get the application name
DLL_EXPORT void dsp_set_app_name(char *name)
set the application name
void *(* dsp_func_t)(void *,...)
Multi-dimensional processing delegate function.
Definition: dsp.h:349
struct dsp_region_t dsp_region
Delimits a region in a single dimension of a buffer.
struct dsp_offset_t dsp_offset
Indicates an offset.
struct dsp_point_t dsp_point
Indicates a dot or line inside a dsp_stream.
struct dsp_triangle_t dsp_triangle
A star or object contained into a buffer.
struct dsp_align_info_t dsp_align_info
Alignment informations needed.
struct dsp_stream_t dsp_stream
Contains a set of informations and data relative to a buffer and how to use it.
union dsp_location_t dsp_location
The location type.
struct dsp_star_t dsp_star
A star or object contained into a buffer.
struct dsp_stream_t * phase
Fourier transform phase.
Definition: dsp.h:412
double samplerate
Sample rate of the buffers.
Definition: dsp.h:404
void * arg
Optional argument for the func() callback.
Definition: dsp.h:378
fftw_complex * fftw
Complex number type array used with libFFTW.
Definition: dsp.h:307
char name[128]
Friendly name of the stream.
Definition: dsp.h:364
struct dsp_location_t::@1 xyz
The location in xyz coordinates.
double imaginary
Imaginary part of the complex number.
Definition: dsp.h:304
int err
Errors.
Definition: dsp.h:289
double * pixel_sizes
Sensor size.
Definition: dsp.h:402
dsp_point center
The center of the star.
Definition: dsp.h:239
int frame_number
Frame number (if part of a series)
Definition: dsp.h:426
double theta
The inclination of the triangle.
Definition: dsp.h:256
int triangles_count
Triangles of stars or objects quantity.
Definition: dsp.h:422
int dims
Dimensions limit.
Definition: dsp.h:279
double * factor
Scaling factor.
Definition: dsp.h:277
double decimals
Decimals.
Definition: dsp.h:287
double wavelength
Wavelength observed, used as reference with signal generators or filters.
Definition: dsp.h:392
double focal_ratio
Focal ratio.
Definition: dsp.h:394
int start
Starting point within the buffer.
Definition: dsp.h:318
double * center
Center of rotation coordinates.
Definition: dsp.h:273
struct dsp_stream_t * parent
The parent stream.
Definition: dsp.h:380
int * sizes
Sizes of each dimension.
Definition: dsp.h:372
double * location
Center of the point.
Definition: dsp.h:217
dsp_complex dft
Fourier transform.
Definition: dsp.h:376
int red
Red pixel (Bayer)
Definition: dsp.h:400
double * radians
Rotational offset.
Definition: dsp.h:275
double index
The index of the triangle.
Definition: dsp.h:252
dsp_star * stars
Stars or objects identified into the buffers - TODO.
Definition: dsp.h:416
struct timespec starttimeutc
Time at the beginning of the stream.
Definition: dsp.h:390
dsp_star * stars
The stars of the triangle.
Definition: dsp.h:262
double * sizes
The sizes of the triangle.
Definition: dsp.h:258
double * buf
Linear double array containing complex numbers.
Definition: dsp.h:309
double * target
Target coordinates.
Definition: dsp.h:388
struct dsp_location_t::@2 geographic
The location in geographic coordinates.
int stars_count
Stars or objects quantity.
Definition: dsp.h:418
struct dsp_stream_t * magnitude
Fourier transform magnitude.
Definition: dsp.h:410
double diameter
The diameter of the star.
Definition: dsp.h:241
int dims
The dimensions of the triangle.
Definition: dsp.h:254
double coordinates[3]
A 3d double array containing the location.
Definition: dsp.h:343
double diameter
Diameter.
Definition: dsp.h:396
dsp_align_info align_info
Align/scale/rotation settings.
Definition: dsp.h:424
dsp_triangle * triangles
Triangles of stars or objects.
Definition: dsp.h:420
dsp_func_t func
Callback function.
Definition: dsp.h:408
int dims
Dimensions limit of the point.
Definition: dsp.h:230
char name[150]
The name of the star.
Definition: dsp.h:243
int dims
Number of dimensions of the buffers.
Definition: dsp.h:370
dsp_location * location
Location coordinates pointer, can be extended to the main buffer size as location companion.
Definition: dsp.h:386
double * offset
Center of the point.
Definition: dsp.h:228
struct dsp_stream_t ** children
Children streams.
Definition: dsp.h:382
dsp_t * buf
buffer
Definition: dsp.h:374
int len
Length of the region.
Definition: dsp.h:320
int triangles_count
Triangles quantity.
Definition: dsp.h:283
double SNR
SNR.
Definition: dsp.h:398
int dims
Dimensions limit of the point.
Definition: dsp.h:219
int child_count
Children streams count.
Definition: dsp.h:384
double score
Match score.
Definition: dsp.h:285
int is_copy
Increments by one on the copied stream.
Definition: dsp.h:366
double * ratios
The sizes of the triangle.
Definition: dsp.h:260
dsp_triangle triangles[2]
Reference triangles.
Definition: dsp.h:281
dsp_region * ROI
Regions of interest for each dimension.
Definition: dsp.h:414
int len
The buffers length.
Definition: dsp.h:368
pthread_t thread
Thread type for future usage.
Definition: dsp.h:406
double real
Real part of the complex number.
Definition: dsp.h:302
double * offset
Translation offset.
Definition: dsp.h:271
DLL_EXPORT void dsp_buffer_sum(dsp_stream_p stream, dsp_t *in, int len)
Sum elements of one stream to another's.
DLL_EXPORT void dsp_buffer_log(dsp_stream_p stream, dsp_t *in, int len)
Logarithm elements of one stream using another's as base.
DLL_EXPORT void dsp_buffer_median(dsp_stream_p stream, int size, int median)
Median elements of the input stream.
DLL_EXPORT void dsp_buffer_shift(dsp_stream_p stream)
Shift a stream on each dimension.
DLL_EXPORT void dsp_buffer_deviate(dsp_stream_p stream, dsp_t *deviation, dsp_t mindeviation, dsp_t maxdeviation)
Deviate forward the first input stream using the second stream as indexing reference.
DLL_EXPORT void dsp_buffer_div1(dsp_stream_p stream, double val)
Divide elements of the input stream to a value.
DLL_EXPORT void dsp_buffer_removemean(dsp_stream_p stream)
Subtract mean from stream.
DLL_EXPORT void dsp_buffer_1sub(dsp_stream_p stream, dsp_t val)
Subtract each element of the input stream a value.
DLL_EXPORT void dsp_buffer_max(dsp_stream_p stream, dsp_t *in, int len)
Subtract elements of one stream from another's.
DLL_EXPORT void dsp_buffer_sigma(dsp_stream_p stream, int size)
Standard deviation of each element of the input stream within the given size.
DLL_EXPORT void dsp_buffer_div(dsp_stream_p stream, dsp_t *in, int len)
Divide elements of one stream to another's.
DLL_EXPORT void dsp_buffer_sum1(dsp_stream_p stream, dsp_t val)
Sum elements of the input stream to a value.
DLL_EXPORT void dsp_buffer_mul(dsp_stream_p stream, dsp_t *in, int len)
Multiply elements of one stream to another's.
DLL_EXPORT void dsp_buffer_pow1(dsp_stream_p stream, double val)
Expose elements of the input stream to the given power.
DLL_EXPORT void dsp_buffer_log1(dsp_stream_p stream, double val)
Logarithm elements of the input stream using the given base.
DLL_EXPORT void dsp_buffer_pow(dsp_stream_p stream, dsp_t *in, int len)
Expose elements of one stream to another's.
DLL_EXPORT void dsp_buffer_min(dsp_stream_p stream, dsp_t *in, int len)
Sum elements of one stream to another's.
DLL_EXPORT void dsp_buffer_1div(dsp_stream_p stream, double val)
Divide a value to each element of the input stream.
DLL_EXPORT void dsp_buffer_sub(dsp_stream_p stream, dsp_t *in, int len)
Subtract elements of one stream from another's.
DLL_EXPORT void dsp_buffer_sub1(dsp_stream_p stream, dsp_t val)
Subtract a value from elements of the input stream.
DLL_EXPORT void dsp_buffer_mul1(dsp_stream_p stream, double val)
Multiply elements of the input stream to a value.
DLL_EXPORT void dsp_convolution_correlation(dsp_stream_p stream, dsp_stream_p matrix)
A cross-correlation processor.
DLL_EXPORT void dsp_convolution_convolution(dsp_stream_p stream, dsp_stream_p matrix)
A cross-convolution processor.
DLL_EXPORT void dsp_stream_free(dsp_stream_p stream)
Free the DSP stream passed as argument.
DLL_EXPORT void dsp_stream_scale(dsp_stream_p stream)
Scale a stream.
DLL_EXPORT void dsp_stream_set_dim(dsp_stream_p stream, int dim, int size)
Set a dimension size to a DSP stream.
DLL_EXPORT void dsp_stream_rotate(dsp_stream_p stream)
Rotate a stream around an axis and offset.
DLL_EXPORT void dsp_stream_del_triangle(dsp_stream_p stream, int index)
Remove the triangle with index n to a DSP stream.
DLL_EXPORT void * dsp_stream_exec(dsp_stream_p stream, void *args,...)
Execute the function callback pointed by the func field of the passed stream.
DLL_EXPORT int dsp_stream_set_position(dsp_stream_p stream, int *pos)
Obtain the position the DSP stream by parsing multidimensional indexes.
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.
DLL_EXPORT void dsp_stream_add_triangle(dsp_stream_p stream, dsp_triangle triangle)
Add a triangle to the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_add_child(dsp_stream_p stream, dsp_stream_p child)
Add a child to the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_del_dim(dsp_stream_p stream, int n)
Remove the dimension with index n to a DSP stream.
DLL_EXPORT dsp_t * dsp_stream_get_buffer(dsp_stream_p stream)
Return the buffer of the stream passed as argument.
DLL_EXPORT void dsp_stream_set_buffer(dsp_stream_p stream, void *buffer, int len)
Set the buffer of the stream passed as argument to a specific memory location.
DLL_EXPORT void dsp_stream_del_child(dsp_stream_p stream, int n)
Remove the child with index n to a DSP stream.
DLL_EXPORT dsp_stream_p dsp_stream_new(void)
Allocate a new DSP stream type.
DLL_EXPORT void dsp_stream_add_dim(dsp_stream_p stream, int len)
Add a dimension with length len to a DSP stream.
DLL_EXPORT void dsp_stream_alloc_buffer(dsp_stream_p stream, int len)
Allocate a buffer with length len on the stream passed as argument.
DLL_EXPORT void dsp_stream_crop(dsp_stream_p stream)
Crop the buffers of the stream passed as argument by reading the ROI field.
DLL_EXPORT void dsp_stream_translate(dsp_stream_p stream)
Translate a stream.
DLL_EXPORT void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_del_star(dsp_stream_p stream, int n)
Remove the star with index n to a DSP stream.
DLL_EXPORT void dsp_stream_add_star(dsp_stream_p stream, dsp_star star)
Add a star to the DSP Stream passed as argument.
DLL_EXPORT void dsp_stream_calc_triangles(dsp_stream_p stream)
Calculate the triangles in the stream struct.
DLL_EXPORT void dsp_buffer_components_to_rgb(dsp_stream_p *stream, void *rgb, int components, int bpp)
Convert a component dsp_stream_p array into an RGB dsp_t array.
DLL_EXPORT dsp_stream_p * dsp_file_read_png(const char *filename, int *channels, int stretch)
Read a PNG file and fill a array of dsp_stream_p with its content, each color channel has its own str...
DLL_EXPORT void dsp_file_write_jpeg_composite(const char *filename, int components, int quality, dsp_stream_p *stream)
Write the components dsp_stream_p array into a JPEG file,.
DLL_EXPORT dsp_stream_p * dsp_stream_from_components(dsp_t *buf, int dims, int *sizes, int components)
Convert a color component dsp_t array into a dsp_stream_p array each element containing the single co...
DLL_EXPORT int dsp_qsort_double_asc(const void *arg1, const void *arg2)
Callback function for qsort for double type ascending ordering.
DLL_EXPORT dsp_t * dsp_file_bayer_2_gray(dsp_t *src, int width, int height)
Convert a bayer pattern dsp_t array into a grayscale array.
DLL_EXPORT void dsp_file_write_fits_bayer(const char *filename, int components, int bpp, dsp_stream_p *stream)
Write a FITS file from a dsp_stream_p array.
DLL_EXPORT void dsp_file_write_fits_composite(const char *filename, int components, int bpp, dsp_stream_p *stream)
Write the components dsp_stream_p array into a JPEG file,.
DLL_EXPORT dsp_t * dsp_file_bayer_2_rgb(dsp_t *src, int red, int width, int height)
Convert a bayer pattern dsp_t array into a ordered 3 RGB array.
DLL_EXPORT void dsp_file_write_jpeg(const char *filename, int quality, dsp_stream_p stream)
Write the stream into a JPEG file,.
DLL_EXPORT int dsp_align_get_offset(dsp_stream_p ref, dsp_stream_p to_align, double tolerance, double target_score)
Calculate offsets, rotation and scaling of two streams giving reference alignment point.
DLL_EXPORT dsp_stream_p * dsp_buffer_rgb_to_components(void *buf, int dims, int *sizes, int components, int bpp, int stretch)
Convert an RGB color dsp_t array into a dsp_stream_p array each element containing the single compone...
DLL_EXPORT dsp_t * dsp_file_composite_2_bayer(dsp_stream_p *src, int red, int width, int height)
Convert a component dsp_stream_p array into a bayer dsp_t array.
DLL_EXPORT dsp_stream_p * dsp_file_read_jpeg(const char *filename, int *channels, int stretch)
Read a JPEG file and fill a array of dsp_stream_p with its content, each color channel has its own st...
DLL_EXPORT int dsp_qsort_star_diameter_asc(const void *arg1, const void *arg2)
Callback function for qsort for dsp_star ascending ordering by their diameters.
DLL_EXPORT void dsp_file_write_png_composite(const char *filename, int components, int compression, dsp_stream_p *stream)
Write the components dsp_stream_p array into a PNG file,.
DLL_EXPORT dsp_stream_p * dsp_file_read_fits(const char *filename, int *channels, int stretch)
Read a FITS file and fill a dsp_stream_p with its content.
DLL_EXPORT int dsp_qsort_star_diameter_desc(const void *arg1, const void *arg2)
Callback function for qsort for dsp_star descending ordering by their diameters.
DLL_EXPORT void dsp_file_write_fits(const char *filename, int bpp, dsp_stream_p stream)
Write the dsp_stream_p into a FITS file,.
DLL_EXPORT int dsp_qsort_double_desc(const void *arg1, const void *arg2)
Callback function for qsort for double type descending ordering.
DLL_EXPORT dsp_t * dsp_file_bayer_2_composite(dsp_t *src, int red, int width, int height)
Convert a bayer pattern dsp_t array into a contiguos component array.
DLL_EXPORT void dsp_filter_lowpass(dsp_stream_p stream, double frequency)
A low pass filter.
DLL_EXPORT void dsp_filter_bandreject(dsp_stream_p stream, double LowFrequency, double HighFrequency)
A band reject filter.
DLL_EXPORT void dsp_filter_bandpass(dsp_stream_p stream, double LowFrequency, double HighFrequency)
A band pass filter.
DLL_EXPORT void dsp_filter_highpass(dsp_stream_p stream, double frequency)
A high pass filter.
DLL_EXPORT void dsp_filter_squarelaw(dsp_stream_p stream)
A square law filter.
DLL_EXPORT dsp_complex dsp_fourier_phase_mag_array_get_complex(double *mag, double *phi, int len)
Obtain a complex array from phase and magnitude arrays.
DLL_EXPORT void dsp_fourier_2fftw(dsp_stream_p stream)
Obtain the complex fourier tranform from the current magnitude and phase buffers.
DLL_EXPORT double * dsp_fourier_complex_array_get_phase(dsp_complex in, int len)
Obtain a complex number's array phases.
DLL_EXPORT void dsp_fourier_idft(dsp_stream_p stream)
Perform an inverse discrete Fourier Transform of a dsp_stream.
DLL_EXPORT double * dsp_fourier_complex_array_get_magnitude(dsp_complex in, int len)
Obtain a complex number's array magnitudes.
DLL_EXPORT void dsp_fourier_2dsp(dsp_stream_p stream)
Fill the magnitude and phase buffers with the current data in stream->dft.
DLL_EXPORT void dsp_fourier_dft(dsp_stream_p stream, int exp)
Perform a discrete Fourier Transform of a dsp_stream.
DLL_EXPORT void dsp_signals_sawtoothwave(dsp_stream_p stream, double samplefreq, double freq)
Generate a sawtooth wave.
DLL_EXPORT void dsp_signals_sinewave(dsp_stream_p stream, double samplefreq, double freq)
Generate a sinusoidal wave.
DLL_EXPORT void dsp_signals_triwave(dsp_stream_p stream, double samplefreq, double freq)
Generate a triangular wave.
DLL_EXPORT void dsp_modulation_amplitude(dsp_stream_p stream, double samplefreq, double freq)
Generate an amplitude modulated wave.
DLL_EXPORT void dsp_modulation_frequency(dsp_stream_p stream, double samplefreq, double freq, double bandwidth)
Generate a frequency modulated wave.
DLL_EXPORT void dsp_signals_whitenoise(dsp_stream_p stream)
Generate white noise.
DLL_EXPORT double * dsp_stats_histogram(dsp_stream_p stream, int size)
Histogram of the inut stream.
Alignment informations needed.
Definition: dsp.h:269
Indicates an offset.
Definition: dsp.h:226
Indicates a dot or line inside a dsp_stream.
Definition: dsp.h:215
Delimits a region in a single dimension of a buffer.
Definition: dsp.h:316
A star or object contained into a buffer.
Definition: dsp.h:237
Contains a set of informations and data relative to a buffer and how to use it.
Definition: dsp.h:362
A star or object contained into a buffer.
Definition: dsp.h:250
Complex number array struct, used in Fourier Transform functions.
Definition: dsp.h:297
The location type.
Definition: dsp.h:327