Instrument Neutral Distributed Interface INDI  2.0.2
stats.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 
22 double* dsp_stats_histogram(dsp_stream_p stream, int size)
23 {
24  if(stream == NULL)
25  return NULL;
26  int k;
27  long i = 0;
28  double* out = (double*)malloc(sizeof(double)*size);
29  dsp_t* tmp = (dsp_t*)malloc(sizeof(dsp_t)*stream->len);
30  dsp_buffer_set(out, size, 0.0);
31  memcpy(tmp, stream->buf, sizeof(dsp_t)*stream->len);
32  dsp_buffer_stretch(tmp, stream->len, 0, size-1);
33  for(k = 0; k < stream->len; k++) {
34  i = (long)tmp[k];
35  if(i > 0 && i < size)
36  out[i] ++;
37  }
38  free(tmp);
39  dsp_t mn = dsp_stats_min(out, size);
40  dsp_t mx = dsp_stats_max(out, size);
41  if(mn < mx)
42  dsp_buffer_stretch(out, size, 0, size);
43  return out;
44 }
double dsp_t
Definition: dsp.h:69
dsp_t * buf
buffer
Definition: dsp.h:375
int len
The buffers length.
Definition: dsp.h:369
#define dsp_buffer_set(buf, len, _val)
Fill the buffer with the passed value.
Definition: dsp.h:815
#define dsp_buffer_stretch(buf, len, _mn, _mx)
Stretch minimum and maximum values of the input stream.
Definition: dsp.h:792
#define dsp_stats_min(buf, len)
Gets the minimum value of the input stream.
Definition: dsp.h:562
double * dsp_stats_histogram(dsp_stream_p stream, int size)
Histogram of the inut stream.
Definition: stats.c:22
#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