Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help: Two different M5 Core 2 device giving different output. #5

Open
bhupiister opened this issue Apr 8, 2022 · 2 comments
Open

Comments

@bhupiister
Copy link

I have set a sample code to record audio signal. One device is with my partner in USA and other is with me in India. Both device are M5 Core 2. We both get different Zero line for output. Our code is 100% same as same firmware is built and flash by me.

My Partner's output
image
My output
image

My I2S setting to record audio

esp_err_t err;
const i2s_port_t I2S_PORT = I2S_NUM_0;
// i2s config for reading from both m5stack mic
i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM),
    .sample_rate = 16000,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
    .communication_format = I2S_COMM_FORMAT_I2S,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count = 4,
    .dma_buf_len = dmaBufCount,
};

// i2s pins
i2s_pin_config_t i2s_pins = {
    .bck_io_num = GPIO_NUM_12,
    .ws_io_num = GPIO_NUM_0,
    .data_out_num = I2S_PIN_NO_CHANGE,
    .data_in_num = GPIO_NUM_34};

This is in Loop of 2 milliseconds to record audio. (Sample rate 500Hz)

  esp_err_t result = i2s_read(I2S_PORT, i2sData, 16, &bytesRead, 10);
  if (result == ESP_OK && bytesRead >= 16)
  {
    for (int i = 0; i < bytesRead / 2; i += 2)
    {
      soundAvg += (i2sData[i] + i2sData[i + 1]) / 2;
    }
    soundAvg = soundAvg / 8;
    AvgSound = soundAvg;
  }

If my settings are incorrect. Can you please let me know what should be the optimum setting to record at 500Hz, we are capturing industrial noise along with vibrations being recorded in same loop from MPU6886.

@DrJaymz
Copy link

DrJaymz commented Mar 16, 2023

I think the problem is that the microphone is terrible and that every one is different. Mine has a huge DC offset which then settles after a moment and it looks like they all do and they all start at a different value. For frequency analysis though, provided you get clear of the initial spike you can remove the DC value and the frequency will analysis will still be valid. If you got a better result somehow let me know.

@sybrenstuvel
Copy link
Collaborator

I've also noted a significant DC offset with my device. I solved it by averaging the samples and removing the average. Seems to work pretty well: 22b7b0f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants