diff --git a/algorithm/signals/esp32_pd120_hot_spot.wav b/algorithm/signals/esp32_pd120_hot_spot.wav new file mode 100644 index 0000000..bed2575 Binary files /dev/null and b/algorithm/signals/esp32_pd120_hot_spot.wav differ diff --git a/algorithm/signalsandsettings.m b/algorithm/signalsandsettings.m index 1674faf..2a6e0a0 100644 --- a/algorithm/signalsandsettings.m +++ b/algorithm/signalsandsettings.m @@ -17,7 +17,8 @@ %x = audioread("signals/teensy4_0_pd80r.wav");x=(x-mean(x))*4;padtype='pd80r';%x = x(1:390000, :);% %x = audioread("signals/teensy4_0_pd80r_hot_spot.wav");x=(x-mean(x))*4;padtype='pd80r'; %x = audioread("signals/teensy4_0_pd120_hot_spot.wav");x=(x-mean(x))*4; -x = audioread("signals/esp32_pd120.wav");x=x/8; +%x = audioread("signals/esp32_pd120.wav");x=x/8; +x = audioread("signals/esp32_pd120_hot_spot.wav");x=x/8; %x = audioread("signals/esp32_pd8.wav");x=x/8;padtype='pd8'; %x = audioread("signals/pd120_pos_sense.wav");%x=x(10600:15000);%x = x(2900:10000, :);%x = x(55400:58000, :);% %x = audioread("signals/pd120_pos_sense2.wav"); diff --git a/common.h b/common.h index 64e7fc0..8cc0164 100644 --- a/common.h +++ b/common.h @@ -8,6 +8,7 @@ // #define USE_SERIAL_DEBUG_PLOTTING // #define USE_OCTAVE_SAMPLE_IMPORT_EXPORT // #define USE_LOW_SAMPLING_RATE_SAMPLE_MONITOR +// #define USE_CAPTURE_ONE_BLOCK_OF_SAMPLES #define VERSION_MAJOR 0 #define VERSION_MINOR 10 @@ -109,3 +110,25 @@ class FastWriteFIFO #else # define DBG_FCT_LOW_SAMPLING_RATE_SAMPLE_MONITOR() #endif + +// Debugging: capture one block of samples +#ifdef USE_CAPTURE_ONE_BLOCK_OF_SAMPLES +# undef USE_MIDI +# define DBG_FCT_CAPTURE_ONE_BLOCK_OF_SAMPLES() \ + const int number_samples = 9000; \ + static uint16_t s[number_samples]; \ + static int cnt = 0; \ + if (cnt >= 0) s[cnt] = sample_org[0][0]; \ + cnt++; \ + if (cnt >= number_samples) \ + { \ + cnt = 0; \ + Serial.println(String(0) + "\t" + String(0)); \ + for (int j = 0; j < number_samples; j++) \ + { \ + Serial.println(s[j]); \ + } \ + } +#else +# define DBG_FCT_CAPTURE_ONE_BLOCK_OF_SAMPLES() +#endif diff --git a/edrumulus.cpp b/edrumulus.cpp index 113537c..1206dcf 100644 --- a/edrumulus.cpp +++ b/edrumulus.cpp @@ -113,6 +113,7 @@ void Edrumulus::process() sample_org); DBG_FCT_LOW_SAMPLING_RATE_SAMPLE_MONITOR(); + DBG_FCT_CAPTURE_ONE_BLOCK_OF_SAMPLES(); // for load indicator we need to store current time right after blocking function if (use_load_indicator) diff --git a/tools/misc/capture_samples.m b/tools/misc/capture_samples.m new file mode 100644 index 0000000..359d957 --- /dev/null +++ b/tools/misc/capture_samples.m @@ -0,0 +1,140 @@ +% Copyright (c) 2020-2026 Volker Fischer +% SPDX-License-Identifier: GPL-2.0-or-later + +% capture samples which were recorded on the ESP32 device + +close all +pkg load instrument-control + + +% optionally, post process recorded data +if false + + load('recording2026-01-20-08-34-33.mat'); + o{1} = out; + load('recording2026-01-20-08-37-55.mat'); + o{2} = out; + load('recording2026-01-20-08-41-06.mat'); + o{3} = out; + load('recording2026-01-20-08-42-15.mat'); + o{4} = out; + load('recording2026-01-20-08-43-25.mat'); + o{5} = out; + load('recording2026-01-20-08-44-28.mat'); + o{6} = out; + + % o1: + id{1} = [ 4, 6, 8, 9, 10]; + rg{1} = {1:8426, 400:8100, 1:8000, 1:8000, 1:7800}; + % o2: + id{2} = [ 5, 10]; + rg{2} = {1:7400, 600:8300}; + % o3: + id{3} = [ 2, 6, 7, 9, 10]; + rg{3} = {1:7300, 1:8390, 1:7400, 1:7600, 1:7700}; + % o4: + id{4} = [ 4, 5, 9]; + rg{4} = {400:7800, 1:8400, 600:8000}; + % o5: + id{5} = [ 3, 4, 5, 7, 8, 10]; + rg{5} = {1000:8000, 1:8400, 1:8000, 1:8000, 1:8400, 600:8200}; + % o6: + id{6} = [ 3, 4, 6, 7, 9]; + rg{6} = {1:7700, 800:7900, 1:8000, 1:7300, 1:7300}; + + %n = 1; + %for i = 1:length(id{n}) + % cur_id = id{n}(i); + % figure; plot(o{n}{cur_id}); title(num2str(cur_id)); + % %figure; plot(o{n}{cur_id}(rg{n}{i})); title(num2str(cur_id)); + %end + + out = []; + for n = 1:length(id) + for i = 1:length(id{n}) + cur_id = id{n}(i); + out = [out; o{n}{cur_id}(rg{n}{i})]; + end + end + out = out(~isnan(out)); + figure; plot(out); + audiowrite('testout.wav', (out - mean(out)) / 4096, 8000); + + return; +end + + + + + +% prepare serial port +try + a = serialport("/dev/ttyUSB0", 115200); + %set(a, 'bytesize', 8); + %set(a, 'parity', 'n'); + %set(a, 'stopbits', 1); +catch + disp('error'); +end + + +figure; + +N = 3; +out = cell(N, 1); + +for k = 1:N + + block_end_found = false; + out{k} = []; + + while ~block_end_found + + % carriage return is 13 + 10 -> use 10 as start and 13 as end marker + while fread(a, 1) ~= 10 + end + + end_found = false; + samples = ''; + while ~end_found + + x = fread(a, 1); + samples = [samples, char(x)]; + + if x == 13 + end_found = true; + end + + end + + % convert from string to numbers for all channels + try + y = strsplit(samples, '\t'); + catch + disp(samples) + disp(test) + end_try_catch + + if length(y) == 1 + out{k} = [out{k}; str2double(y{1})]; + else + block_end_found = true; + end + + end + + plot(out{k}, '.-'); + drawnow; + +end + +%disp(out) + +%fn = strcat('recording', datestr(now, 'yyyy-mm-dd-HH-MM-SS'), '.mat'); +%save(fn, 'out'); +%system('play -q -n synth 0.2 sine 1000'); + +clear a + + + diff --git a/tools/misc/capture_samples/capture_samples.ino b/tools/misc/capture_samples/capture_samples.ino deleted file mode 100644 index 814861b..0000000 --- a/tools/misc/capture_samples/capture_samples.ino +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (c) 2020-2026 Volker Fischer -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "soc/sens_reg.h" -#include "driver/dac.h" - -//#define DO_MULT_INPUT_CAPTURE_TEST -//#define DO_SAMPLE_RATE_TEST -//#define DO_INPUT_CAPTURE -#define DO_INPUT_BUFFER_CAPTURE - -const int analog_pin = 35;//25; -const int num_all_pins = 12;//15; -// ADC: 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 -const int all_analog_pins[num_all_pins] = { 36, 39, 34, 35, 32, 33, 25, 26, 27, 14, 12, 13};//, 4, 2, 15 }; -const int Fs = 8000; -const int samplerate_max_cnt = 1000; // samples -int samplerate_prev_micros_cnt = 0; -unsigned long samplerate_prev_micros = micros(); -volatile SemaphoreHandle_t timer_semaphore; -hw_timer_t* timer = nullptr; -const int dc_offset_est_len = 5000; // samples -float dc_offset = 0.0f; -int prvious_sample1 = 0; -int prvious_sample2 = 0; -int prvious_sample1_out = 0; - -void IRAM_ATTR on_timer() -{ - // tell the main loop that a sample can be read by setting the semaphore - xSemaphoreGiveFromISR ( timer_semaphore, NULL ); -} - -// Since arduino-esp32 library version 1.0.5, the analogRead was changed to use the IDF interface -// which made the analogRead function so slow that we cannot use that anymore for Edrumulus: -// https://github.com/espressif/arduino-esp32/issues/4973, https://github.com/espressif/arduino-esp32/pull/3377 -// As a workaround, we had to write our own analogRead function. -void my_init_analogRead() -{ - // if the GIOP 25/26 are used, we have to set the DAC to 0 to get correct DC offset - // estimates and reduce the number of large spikes - dac_i2s_enable(); - dac_output_enable(DAC_CHANNEL_1); - dac_output_voltage(DAC_CHANNEL_1, 0); - dac_output_disable(DAC_CHANNEL_1); - dac_output_enable(DAC_CHANNEL_2); - dac_output_voltage(DAC_CHANNEL_2, 0); - dac_output_disable(DAC_CHANNEL_2); - dac_i2s_disable(); - - // set attenuation of 11 dB - WRITE_PERI_REG(SENS_SAR_ATTEN1_REG, 0x0FFFFFFFF); - WRITE_PERI_REG(SENS_SAR_ATTEN2_REG, 0x0FFFFFFFF); - - // set both ADCs to 12 bit resolution using 8 cycles and 1 sample - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_CYCLE, 8, SENS_SAR1_SAMPLE_CYCLE_S); // cycles - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_CYCLE, 8, SENS_SAR2_SAMPLE_CYCLE_S); - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_NUM, 0, SENS_SAR1_SAMPLE_NUM_S); // # samples - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_NUM, 0, SENS_SAR2_SAMPLE_NUM_S); - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_CLK_DIV, 1, SENS_SAR1_CLK_DIV_S); // clock div - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_CLK_DIV, 1, SENS_SAR2_CLK_DIV_S); - SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR1_BIT_WIDTH, 3, SENS_SAR1_BIT_WIDTH_S); // width - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_BIT, 3, SENS_SAR1_SAMPLE_BIT_S); - SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR2_BIT_WIDTH, 3, SENS_SAR2_BIT_WIDTH_S); - SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_BIT, 3, SENS_SAR2_SAMPLE_BIT_S); - - // some other initializations - SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DATA_INV); - SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV); - SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_FORCE_M); // SAR ADC1 controller (in RTC) is started by SW - SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD_FORCE_M); // SAR ADC1 pad enable bitmap is controlled by SW - SET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_FORCE_M); // SAR ADC2 controller (in RTC) is started by SW - SET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD_FORCE_M); // SAR ADC2 pad enable bitmap is controlled by SW - CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR_M); // force XPD_SAR=0, use XPD_FSM - SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_AMP, 0x2, SENS_FORCE_XPD_AMP_S); // force XPD_AMP=0 - CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_CTRL_REG, 0xfff << SENS_AMP_RST_FB_FSM_S); // clear FSM - SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT1, 0x1, SENS_SAR_AMP_WAIT1_S); - SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT2, 0x1, SENS_SAR_AMP_WAIT2_S); - SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_SAR_AMP_WAIT3, 0x1, SENS_SAR_AMP_WAIT3_S); - while (GET_PERI_REG_BITS2(SENS_SAR_SLAVE_ADDR1_REG, 0x7, SENS_MEAS_STATUS_S) != 0); - - // configure all pins to analog read - for (int i = 0; i < total_number_inputs; i++) - { - pinMode(input_pin[i], ANALOG); - } -} - -uint16_t my_analogRead(uint8_t pin) -{ - const int8_t channel = digitalPinToAnalogChannel(pin); - - pinMode(pin, ANALOG); - - if (channel > 9) - { - const int8_t channel_modified = channel - 10; - CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M); - SET_PERI_REG_BITS(SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD, (1 << channel_modified), SENS_SAR2_EN_PAD_S); - SET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M); - while (GET_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DONE_SAR) == 0); - return GET_PERI_REG_BITS2(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DATA_SAR, SENS_MEAS2_DATA_SAR_S); - } - else - { - CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M); - SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD, (1 << channel), SENS_SAR1_EN_PAD_S); - SET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M); - while (GET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR) == 0); - return GET_PERI_REG_BITS2(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DATA_SAR, SENS_MEAS1_DATA_SAR_S); - } -} - - -void my_analogRead2 ( uint8_t pin1, uint8_t pin2, uint16_t& out1, uint16_t& out2 ) -{ - const int8_t channel = digitalPinToAnalogChannel ( pin1 ); - const int8_t channel2 = digitalPinToAnalogChannel ( pin2 ); - -/* - pinMode ( pin1, ANALOG ); - pinMode ( pin2, ANALOG ); -*/ - - if ( channel > 9 ) - { - const int8_t channel_modified = channel - 10; - CLEAR_PERI_REG_MASK ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M ); - SET_PERI_REG_BITS ( SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD, ( 1 << channel_modified ), SENS_SAR2_EN_PAD_S ); - SET_PERI_REG_MASK ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M ); - } - else - { - CLEAR_PERI_REG_MASK ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M ); - SET_PERI_REG_BITS ( SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD, ( 1 << channel ), SENS_SAR1_EN_PAD_S ); - SET_PERI_REG_MASK ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M ); - } - - if ( channel2 > 9 ) - { - const int8_t channel_modified = channel2 - 10; - CLEAR_PERI_REG_MASK ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M ); - SET_PERI_REG_BITS ( SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD, ( 1 << channel_modified ), SENS_SAR2_EN_PAD_S ); - SET_PERI_REG_MASK ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_SAR_M ); - } - else - { - CLEAR_PERI_REG_MASK ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M ); - SET_PERI_REG_BITS ( SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD, ( 1 << channel2 ), SENS_SAR1_EN_PAD_S ); - SET_PERI_REG_MASK ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_SAR_M ); - } - - if ( channel > 7 ) - { - while ( GET_PERI_REG_MASK ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DONE_SAR ) == 0 ); - out1 = GET_PERI_REG_BITS2 ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DATA_SAR, SENS_MEAS2_DATA_SAR_S ); - } - else - { - while ( GET_PERI_REG_MASK ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR ) == 0 ); - out1 = GET_PERI_REG_BITS2 ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DATA_SAR, SENS_MEAS1_DATA_SAR_S ); - } - - if ( channel2 > 7 ) - { - while ( GET_PERI_REG_MASK ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DONE_SAR ) == 0 ); - out2 = GET_PERI_REG_BITS2 ( SENS_SAR_MEAS_START2_REG, SENS_MEAS2_DATA_SAR, SENS_MEAS2_DATA_SAR_S ); - } - else - { - while ( GET_PERI_REG_MASK ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR ) == 0 ); - out2 = GET_PERI_REG_BITS2 ( SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DATA_SAR, SENS_MEAS1_DATA_SAR_S ); - } -} - - -void setup() -{ -#if defined ( DO_MULT_INPUT_CAPTURE_TEST ) || defined ( DO_SAMPLE_RATE_TEST ) || defined ( DO_INPUT_BUFFER_CAPTURE ) - Serial.begin ( 115200 ); -#else - Serial.begin ( 500000 ); -#endif - - my_init_analogRead(); - - // estimate the DC offset - float dc_offset_sum = 0.0f; - - for ( int i = 0; i < dc_offset_est_len; i++ ) - { - dc_offset_sum += my_analogRead ( analog_pin ); - delayMicroseconds ( 100 ); - } - -// TEST -for ( int i = 0; i < num_all_pins / 2; i++ ) -{ - pinMode ( all_analog_pins[i], ANALOG ); - pinMode ( all_analog_pins[i + 6], ANALOG ); -} - - dc_offset = dc_offset_sum / dc_offset_est_len; - - // prepare timer at a rate of given sampling rate - timer_semaphore = xSemaphoreCreateBinary(); - timer = timerBegin ( 0, 80, true ); // prescaler of 80 (i.e. below we have 1 MHz instead of 80 MHz) - timerAttachInterrupt ( timer, &on_timer, true ); - timerAlarmWrite ( timer, 1000000 / Fs, true ); // here we define the sampling rate (1 MHz / Fs) - timerAlarmEnable ( timer ); -} - -void loop() -{ - // wait for the timer to get the correct sampling rate when reading the analog value - if ( xSemaphoreTake ( timer_semaphore, portMAX_DELAY ) == pdTRUE ) - { - -#ifdef DO_SAMPLE_RATE_TEST -/* -// TEST -int sample_org[num_all_pins]; -for ( int i = 0; i < num_all_pins; i++ ) -{ - sample_org[i] = my_analogRead ( all_analog_pins[i] ); -} -*/ - -uint16_t sample_org2[num_all_pins]; -for ( int i = 0; i < num_all_pins / 2; i++ ) -{ - my_analogRead2 ( all_analog_pins[i], all_analog_pins[i + 6], sample_org2[i], sample_org2[i + 6] ); -} - - - if ( samplerate_prev_micros_cnt >= samplerate_max_cnt ) - { - const float sample_rate = 1.0f / ( micros() - samplerate_prev_micros ) * samplerate_max_cnt * 1e6f; - Serial.println ( sample_rate, 7 ); - - samplerate_prev_micros_cnt = 0; - samplerate_prev_micros = micros(); - } - samplerate_prev_micros_cnt++; -#endif - - -#ifdef DO_MULT_INPUT_CAPTURE_TEST - // capture from all analog inputs - -// TEST -uint16_t sample_org[num_all_pins]; -for ( int i = 0; i < num_all_pins / 2; i++ ) -{ - my_analogRead2 ( all_analog_pins[i], all_analog_pins[i + 6], sample_org[i], sample_org[i + 6] ); -} - -// TODO we have a better implementation of this in the edrumulus class -Serial.println ( String ( sample_org[0] ) + "\t" + - String ( sample_org[1] ) + "\t" + - String ( sample_org[2] ) + "\t" + - String ( sample_org[3] ) + "\t" + - String ( sample_org[4] ) + "\t" + - String ( sample_org[5] ) + "\t" + - String ( sample_org[6] ) + "\t" + - String ( sample_org[7] ) + "\t" + - String ( sample_org[8] ) + "\t" + - String ( sample_org[9] ) + "\t" + - String ( sample_org[10] ) + "\t" + - String ( sample_org[11] ) ); - -#endif - -#ifdef DO_INPUT_CAPTURE - const int sample_raw = my_analogRead ( analog_pin ); - -// TEST -int sample = sample_raw; // TEST - - // for debugging: send samples to Octave with binary format via serial interface - byte send_buf[4]; - send_buf[0] = 0xFF; - send_buf[1] = 0xFF; - send_buf[2] = sample >> 8; // high byte - send_buf[3] = sample & 0xFF; // low byte - Serial.write ( send_buf, 4 ); -#endif - -#ifdef DO_INPUT_BUFFER_CAPTURE - - // capture one block of samples - const int number_samples = 200; - uint16_t sample_org[number_samples][num_all_pins]; - - for ( int j = 0; j < number_samples; j++ ) - { - for ( int i = 0; i < num_all_pins / 2; i++ ) - { - // read with given sampling rate - if ( xSemaphoreTake ( timer_semaphore, portMAX_DELAY ) == pdTRUE ) - { - my_analogRead2 ( all_analog_pins[i], all_analog_pins[i + 6], sample_org[j][i], sample_org[j][i + 6] ); - } - } - } - - // first, transfer marker - Serial.println ( String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) + "\t" + - String ( 0 ) ); - - // transfer complete buffer - for ( int j = 0; j < number_samples; j++ ) - { - Serial.println ( String ( sample_org[j][0] ) + "\t" + - String ( sample_org[j][1] ) + "\t" + - String ( sample_org[j][2] ) + "\t" + - String ( sample_org[j][3] ) + "\t" + - String ( sample_org[j][4] ) + "\t" + - String ( sample_org[j][5] ) + "\t" + - String ( sample_org[j][6] ) + "\t" + - String ( sample_org[j][7] ) + "\t" + - String ( sample_org[j][8] ) + "\t" + - String ( sample_org[j][9] ) + "\t" + - String ( sample_org[j][10] ) + "\t" + - String ( sample_org[j][11] ) ); - } - -#endif - } -} diff --git a/tools/misc/capture_samples/capture_samples.m b/tools/misc/capture_samples/capture_samples.m deleted file mode 100644 index 9bc2622..0000000 --- a/tools/misc/capture_samples/capture_samples.m +++ /dev/null @@ -1,107 +0,0 @@ -% Copyright (c) 2020-2026 Volker Fischer -% SPDX-License-Identifier: GPL-2.0-or-later - -% capture samples which were recorded on the ESP32 device - -close all -pkg load instrument-control -pkg load statistics - - -do_input_capture = false; - - -% #ifdef DO_INPUT_CAPTURE ------------------------------------------------------ -if do_input_capture - - % prepare serial port - try - a = serialport("/dev/ttyUSB0", 500000); % note that we increased the transfer rate, now it is different from the default - catch - end - flush(a); - - val = double(fread(a, 1 * 8000)); - marker_pos = find(val == 255); - - val = val(marker_pos(1):end); - val(1 + marker_pos - marker_pos(1)) = []; - if mod(length(val), 2) ~= 0 - val = val(1:end - 1); - end - x = val(1:2:end) * 255 + val(2:2:end); - - % the data seems to be corrupt, remove obviously incorrect data - x(x > 2^12) = nan; - - figure; subplot(2, 1, 1), plot(x); grid on; title('raw linear sample data'); - axis([0, length(x), 0, 2^12]); - - subplot(2, 1, 2), plot(20 * log10(abs(x - nanmean(x)))); grid on; ylabel('dB'); title('power'); - - %audiowrite('testout.wav',(x-1893)/4096,8000); - - -% #ifdef DO_INPUT_BUFFER_CAPTURE ----------------------------------------------- -else - - % prepare serial port - try - a = serialport("/dev/ttyUSB0", 115200); - set(a, 'bytesize', 8); - set(a, 'parity', 'n'); - set(a, 'stopbits', 1); - catch - end - -% Windows: Enable the flush once and then disable it to get correct results: -%flush(a); - -% TEST -number_samples = 500;%50000; - - out = zeros(number_samples, 12); - - for i = 1:number_samples - - % carriage return is 13 + 10 -> use 10 as start and 13 as end marker - while fread(a, 1) ~= 10 - end - - end_found = false; - samples = ''; -test=[]; - while ~end_found - - x = fread(a, 1); -test = [test;x]; - samples = [samples, char(x)]; - - if x == 13 - end_found = true; - end - - end - - % convert from string to numbers for all channels - try - y = strsplit(samples, '\t'); - catch - disp(samples) - disp(test) - end_try_catch - - for j = 1:length(y) - out(i, j) = str2double(y{j}); - end - - end - - figure; plot(out, '.-') - %disp(out) - - save -ascii 'recording.txt' out - -end - -