espressif / esp-dsp

DSP library for ESP-IDF
Apache License 2.0
465 stars 87 forks source link

Implement a int32 version of all the conv functions (DSP-72) #27

Closed StephanAAU closed 1 year ago

StephanAAU commented 3 years ago

I have borrowed your dsps_corr_f32_ansi implementation and made a int32 version of it for my own project.

I did this because the internal ADC, when used together with the internal I2S controller, uses 12bit integer values and to avoid converting back and forth.

Maybe an specific ae implementation would give some performance improvement compared to C implementation?

Code snippet below to show what I mean (it's a very minor modification of the variabels :D)

void corr_s32(const int32_t *Signal, const int siglen, const int32_t *Pattern, const int patlen, int32_t *dest)
{
    for (size_t n = 0; n < (siglen - patlen); n++) {
        int32_t k_corr = 0;
        for (size_t m = 0; m < patlen; m++) {
            k_corr += Signal[n + m] * Pattern[m];
        }
        dest[n] = k_corr;
    }
}
dmitry1945 commented 1 year ago

Hi @StephanAAU , the int16 has 2 bytes size, and int32 and float both have the same size – 4 bytes. For some applications is useful to use int16 for signal processing because ~96 dB signal to noise range is enough for such kind of applications. If you would like to use 4 bytes width, it’s better to use float because it has much more dynamic range and it’s much more efficient to use float for any processing. You can simpley convert your int32 to float (xtensa have spetial instruction for that). In esp-dsp we have no support 32bit integer and have int16 and float support, because esp32, esp32s3 have special instructions for that (we have mac16 and FPU units). We will include function that will convert int32 to float and float to int32 in future.

Thank you, Dmitry