ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_view.cpp
Go to the documentation of this file.
1#include "dsps_view.h"
2#include <math.h>
3#include "esp_log.h"
4#include <limits>
5#include <inttypes.h>
6
7
8void dsps_view(const float *data, int32_t len, int width, int height, float min, float max, char view_char)
9{
10 uint8_t *view_data = new uint8_t[width * height];
11 float *view_data_min = new float[width];
12 float *view_data_max = new float[width];
13 //
14
15 for (int y = 0; y < height ; y++) {
16 for (int x = 0 ; x < width ; x++) {
17 view_data[y * width + x] = ' ';
18 }
19 }
20 for (int i = 0 ; i < width ; i++) {
21 view_data_min[i] = max;
22 view_data_max[i] = min;
23 }
24 float x_step = (float)(width) / (float)len;
25 float y_step = (float)(height - 1) / (max - min);
26 float data_min = std::numeric_limits<float>::max();
27 float data_max = std::numeric_limits<float>::min();
28 int min_pos = 0;
29 int max_pos = 0;
30
31 for (int i = 0 ; i < len ; i++) {
32 int x_pos = i * x_step;
33 if (data[i] < view_data_min[x_pos]) {
34 view_data_min[x_pos] = data[i];
35 }
36 if (data[i] > view_data_max[x_pos]) {
37 view_data_max[x_pos] = data[i];
38 }
39
40 if (view_data_min[x_pos] < min) {
41 view_data_min[x_pos] = min;
42 }
43 if (view_data_max[x_pos] > max) {
44 view_data_max[x_pos] = max;
45 }
46 ESP_LOGD("view", "for i=%i, x_pos=%i, max=%f, min=%f, data=%f", i, x_pos, view_data_min[x_pos], view_data_max[x_pos], data[i]);
47 if (data[i] > data_max) {
48 data_max = data[i];
49 max_pos = i;
50 }
51 if (data[i] < data_min) {
52 data_min = data[i];
53 min_pos = i;
54 }
55 }
56 ESP_LOGI("view", "Data min[%i] = %f, Data max[%i] = %f", min_pos, data_min, max_pos, data_max);
57 ESP_LOGD("view", "y_step = %f", y_step);
58 for (int x = 0 ; x < width ; x++) {
59 int y_count = (view_data_max[x] - view_data_min[x]) * y_step + 1;
60 ESP_LOGD("view", "For x= %i y_count=%i ,min =%f, max=%f, ... ", x, y_count, view_data_min[x], view_data_max[x]);
61 for (int y = 0 ; y < y_count ; y++) {
62 int y_pos = (max - view_data_max[x]) * y_step + y;
63 ESP_LOGD("view", " %i, ", y_pos);
64 view_data[y_pos * width + x] = view_char;
65 }
66 ESP_LOGD("view", " ");
67 }
68
69 // Simple output
70 // for (int i=0 ; i< len ; i++)
71 // {
72 // float x_step = (float)(width-1)/(float)len;
73 // float y_step = (float)(height-1)/(max - min);
74 // int x_pos = i*x_step;
75 // int y_pos = data[i]*y_step;
76 // if (data[i] >= max) y_pos = 0;
77 // if (data[i] <= min) y_pos = height-1;
78 // view_data[y_pos*width + x_pos] = view_char;
79 // printf("For data[%i]=%f, x_pos%i, y_pos=%i\n", i, data[i], x_pos, y_pos);
80 // }
81 // printf("\n");
82 printf(" ");
83 for (int x = 0 ; x < width ; x++) {
84 printf("_");
85 }
86 printf("\n");
87 for (int y = 0; y < height ; y++) {
88 printf("%i", y % 10);
89 for (int x = 0 ; x < width ; x++) {
90 printf("%c", view_data[y * width + x]);
91 }
92 printf("|\n");
93 }
94 printf(" ");
95 for (int x = 0 ; x < width ; x++) {
96 printf("%i", x % 10);
97 }
98 printf("\n");
99 ESP_LOGI("view", "Plot: Length=%i, min=%f, max=%f", (int)len, min, max);
100 delete[] view_data;
101 delete[] view_data_min;
102 delete[] view_data_max;
103}
104
105void dsps_view_s16(const int16_t *data, int32_t len, int width, int height, float min, float max, char view_char)
106{
107 float *view_data = new float[len];
108 for (size_t i = 0; i < len; i++) {
109// view_data[i] = ((float)data[i])/32768.0f;
110 view_data[i] = data[i];
111 view_data[i] /= 32768;
112 }
113 dsps_view(view_data, len, width, height, min, max, view_char);
114 delete[] view_data;
115}
116
117void dsps_view_spectrum(const float *data, int32_t len, float min, float max)
118{
119 dsps_view(data, len, 64, 10, min, max, '|');
120}
void dsps_view_s16(const int16_t *data, int32_t len, int width, int height, float min, float max, char view_char)
void dsps_view(const float *data, int32_t len, int width, int height, float min, float max, char view_char)
plot view
Definition dsps_view.cpp:8
void dsps_view_spectrum(const float *data, int32_t len, float min, float max)
spectrum view
#define ESP_LOGD
Definition esp_log.h:22
static float data[128 *2]
Definition test_fft2r.c:34
float y[1024]
Definition test_fir.c:11
float x[1024]
Definition test_fir.c:10