Comments (3)
I should have spent a little more time investigating before putting this post up. Reducing the change in frequency to 0.001 i have been able to hear the filter working somewhat correctly as i go from f=0.5 and up.
It starts off with okay values (still a lot of distortion)
[filter-dsp] change f 0.69699: 0.69799
[filter-dsp] Coefficients 0: 12.48261
[filter-dsp] Coefficients 1: 24.96522
[filter-dsp] Coefficients 2: 12.48261
[filter-dsp] Coefficients 3: 12.13230
[filter-dsp] Coefficients 4: 36.79814
And as it increases, the values become greater and greater creating a decimation effect
[filter-dsp] change f 0.72899: 0.72999
[filter-dsp] Coefficients 0: 71.31686
[filter-dsp] Coefficients 1: 142.63373
[filter-dsp] Coefficients 2: 71.31686
[filter-dsp] Coefficients 3: 31.77969
[filter-dsp] Coefficients 4: 252.48778
These values continue to climb before i start seeing nan values.
from esp-dsp.
Hi @mrSilkie ,
Thank you for the feedback.
Yes, the frequency is from 0 up to 0.5, where 1 is a sample frequency. The values above 0.5 I this are not correct.
The LPF and HPF filters are very sensitive to the qFactor.
I've planed to release the demo application this week with LyraT board and processing audio. There will be just playing samples with volume/bass/treble.
You are right, first the samples from codec should be converted from int16 to float, and then back from float to int16.
We will implement biquad filter for the stereo samples soon (next few weeks).
Thank you,
Dmitry
from esp-dsp.
I got it working, I wasn't converting the int buffer to a float and back correctly.
Now that I've got it working all I can say is that it sounds like trash. A lot of digital distortion. It's getting tricky to debug the Lyra-T as SD card and Aux in both interfere with JTAG. I'll probably have to code in a file or oscillator to atleast have some test data for verification.
I have been using my button to sweep Q's and filter frequencies. Is the Q in log 10? so values 0.001 and 100 are both valid in some sense? Anyway, here is my code so far.
void int16_to_float_stereo(int16_t* input, float* output, int size, bool mode){
switch (mode) {
case true:
for (int i = 0; i < size;i ++)
{
output[i] = input[(2*i)+1] / (float)INT16_MAX;
}
break;
default:
for (int i = 0; i < size; i++)
{
output[i] = input[2*i] / (float)INT16_MAX;
}
break;
}
}
void float_to_int16_stereo(float* input, int16_t* output, int size, bool mode){
switch (mode) {
case true:
for (int i = 1; i < size; i++) {
output[i] = (int16_t)(input[(2*i)+1] * INT16_MAX);
}
break;
default:
for (int i = 0; i < size; i++) {
output[i] = (int16_t)(input[2*i] * INT16_MAX);
}
}
}
// Function shows result of IIR filter
void IIRfilter(int16_t* input, int16_t* output, float freq, float qFactor, bool show, uint8_t channelMode)
{
esp_err_t ret = ESP_OK;
static float last_freq = -1.0;
static float coeffs_lpf[5];
static float filter_History_L[2] = {0};
static float filter_History_R[2] = {0};
float FloatDspBuf_IN[I2S_READLEN] = {0};
float FloatDspBuf_OUT[I2S_READLEN] = {0};
// INT TO FLOAT
switch (channelMode)
{
case LEFT:
int16_to_float_stereo(input, FloatDspBuf_IN, I2S_READLEN, 0);
break;
case RIGHT:
int16_to_float_stereo(input, FloatDspBuf_IN, I2S_READLEN, 1);
break;
default:
// no mono right now
memcpy(output, input, I2S_READLEN);
return;
}
// PRE DSP
if (channelMode != LEFT && freq != last_freq)
{
printf("[filter-dsp] New F:%2.5f . . . Current Q: %2.3f\r\n", freq, qFactor);
last_freq = freq;
// Calculate iir filter coefficients
ret = dsps_biquad_gen_hpf_f32(coeffs_lpf, (freq), qFactor);
// printf all of the coefficients
printf("[filter-dsp] Coefficients %1.5f\t%1.5f\t%1.5f\t%1.5f\t%1.5f\r\n",
coeffs_lpf[0],coeffs_lpf[1],coeffs_lpf[2],coeffs_lpf[3],coeffs_lpf[4]);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "Operation error = %i", ret);
return;
}
}
// DSP
switch (channelMode)
{
case LEFT:
ret = dsps_biquad_f32_ansi(FloatDspBuf_IN, FloatDspBuf_OUT, I2S_READLEN_HALF, coeffs_lpf, filter_History_L);
break;
case RIGHT:
ret = dsps_biquad_f32_ansi(FloatDspBuf_IN, FloatDspBuf_OUT, I2S_READLEN_HALF, coeffs_lpf, filter_History_R);
break;
default:
break;
}
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "Operation error = %i", ret);
return;
}
// POST DSP
// FLOAT TO INT
switch (channelMode)
{
case LEFT:
float_to_int16_stereo(FloatDspBuf_OUT, output, I2S_READLEN_HALF, 0);
break;
case RIGHT:
float_to_int16_stereo(FloatDspBuf_OUT, output, I2S_READLEN_HALF, 1);
break;
default:
memcpy(output, input, I2S_READLEN);
break;
}
// 0 out memory
}
from esp-dsp.
Related Issues (20)
- dsps_fft2r_sc16_aes3 different result from dsps_fft2r_sc16_ansi, incorrect FFT (DSP-102) HOT 7
- SOLVED: A 1½cycle/tap fp32 FIR filter of arbitrary length and decimation (DSP-101) HOT 6
- Extended Kalman Filter 计算速度 (DSP-105) HOT 4
- Wrong output when running dsps_mulc_s16_ functions (DSP-108) HOT 3
- Feature Request: Python wrapper (DSP-109)
- ESP-IDF 5.1 Support? (DSP-110) HOT 8
- Two environments with different actions were specified for the same target (DSP-115) HOT 4
- esp32s3 fft4real hangs if fft4r related codes are removed. (DSP-117) HOT 4
- SOLVED: TRIAC delayed-trigger compensation routine for ESP32(-S3) (DSP-119) HOT 2
- FIR Convolution algorithm error (DSP-120) HOT 4
- dsps_dotprod_f32 is slow on first call (examples/dotprod) (DSP-121) HOT 1
- Mismatch between latest repository tag and latest component manager tag (DSP-122) HOT 4
- IIR inconsistencies and documentation problems (DSP-123)
- FFT is wrong by factor 2. Violation of the Parseval–Plancherel identity (DSP-130) HOT 2
- 是否会支持esp-p4的芯片的指令 (DSP-132) HOT 2
- esp-dsp支持idf的最新master分支吗 (DSP-134) HOT 1
- 作为一个信号处理的库,是否应该包括IFFT (DSP-135)
- Compile `esp-dsp` for `IDF_TARGET=linux` (DSP-136)
- FIR for s16 (int16_t) type. (DSP-138) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-dsp.