当ADC与I2S一起使用时,如何确定ADC的实际采样频率?
我在使用I2S测量来自ADC的信号时遇到问题当ADC与I2S一起使用时,如何确定ADC的实际采样频率?,c,matlab,signal-processing,esp32,adc,C,Matlab,Signal Processing,Esp32,Adc,我在使用I2S测量来自ADC的信号时遇到问题 // Initialization of I2S buffer uint16_t* i2sReadBuffer = (uint16_t*)calloc(DMA_BUFFER_LEN, sizeof(uint16_t)); size_t bytesRead; while (1) { // Read data in the buffer till its not full i2s_rea
// Initialization of I2S buffer
uint16_t* i2sReadBuffer = (uint16_t*)calloc(DMA_BUFFER_LEN, sizeof(uint16_t));
size_t bytesRead;
while (1) {
// Read data in the buffer till its not full
i2s_read(ADC_I2S_NUM, (void*)i2sReadBuffer, DMA_BUFFER_LEN * sizeof(uint16_t), &bytesRead, portMAX_DELAY);
for (size_t i = 0; i < DMA_BUFFER_LEN; i++) {
uint16_t value = i2sReadBuffer[i];
printf("%d\n", value);
}
}
滤波以1kHz的假设采样率工作,因为它是通过
fir1(100,[0.06 0.14],“stop')
调用设计的。0.06
和0.14
值被标准化(通过采样率)频率。因此,滤波器将衰减60-140Hz频带内的频率分量。通过根据所需速率更新这些值,可以使其在另一个采样速率下工作。但是请记住,如果增加采样率,还需要增加过滤器顺序以保持类似的过滤性能。@SleuthEye但我设置的采样率要高出10倍……我不熟悉esp32,因此我无法回答您的这部分问题。但是,您可以通过计算已知频率的正弦音调周期内的采样数来测量实际采样率,并查看它是否与您配置的频率相匹配。@SleuthEye谢谢,实际采样率降低了大约60倍。因此,它允许MATLAB过滤50-60 Hz的噪声,同时不失真ECG。该过滤以1kHz的假设采样率工作,因为它是通过fir1(100,[0.06 0.14],'stop')调用设计的。0.06
和0.14
值被标准化(通过采样率)频率。因此,滤波器将衰减60-140Hz频带内的频率分量。通过根据所需速率更新这些值,可以使其在另一个采样速率下工作。但是请记住,如果增加采样率,还需要增加过滤器顺序以保持类似的过滤性能。@SleuthEye但我设置的采样率要高出10倍……我不熟悉esp32,因此我无法回答您的这部分问题。但是,您可以通过计算已知频率的正弦音调周期内的采样数来测量实际采样率,并查看它是否与您配置的频率相匹配。@SleuthEye谢谢,实际采样率降低了大约60倍。因此,它允许MATLAB过滤50-60 Hz的噪声,同时不失真ECG。
xlsFile = 'ecg_data.xlsx';
[num, txt, raw] = xlsread(xlsFile);
input = cell2mat(raw);
a = fir1(100, [0.06 0.14], 'stop');
in = input(:, 2);
filtered = filter(a, 1, in);
y = fft(filtered);
N = length(y); % Length of a vector
f = (0:N - 1 ) * 100 / N; % Frequency vector
m = abs(y); % Magnitude
% y(m<1e-6) = 0;
p = unwrap(angle(y)); % Phase
X_vector = (1:3:N) / ((N - 1) * 1e-3);
title('Frequency spectrum')
subplot(2,2,1)
plot(f,m)
title('Magnitude')
ax = gca;
ax.XTick = X_vector;
subplot(2,2,2)
plot(f,p*180/pi)
title('Phase')
ax = gca;
ax.XTick = X_vector;
subplot(2,2,3)
plot(in)
title('Input singal')
xlabel('msec')
ax = gca;
subplot(2,2,4)
plot(filtered)
title('Filtered signal')
ax = gca;
#define SAMPLING_FREQ 10000
#define ADC_CHANNEL ADC1_CHANNEL_4
#define ADC_UNIT ADC_UNIT_1
#define DMA_BUFFER_LEN 1024
#define ADC_I2S_NUM I2S_NUM_0
static void init_i2s_adc(void) {
i2s_config_t i2s_config =
{
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),
.sample_rate = SAMPLING_FREQ,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_STAND_MSB,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = DMA_BUFFER_LEN,
.tx_desc_auto_clear = 1,
.use_apll = 0,
};
adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN_11db);
adc1_config_width(ADC_WIDTH_12Bit);
i2s_driver_install(ADC_I2S_NUM, &i2s_config, 0, NULL);
i2s_set_clk(ADC_I2S_NUM, SAMPLING_FREQ, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO);
i2s_set_adc_mode(ADC_UNIT, ADC_CHANNEL);
i2s_adc_enable(ADC_I2S_NUM);
}