소스 검색

Further precision increase eliminates DC offset

dds
Transmogrifox 7 년 전
부모
커밋
6424ffbb26
2개의 변경된 파일16개의 추가작업 그리고 20개의 파일을 삭제
  1. +6
    -8
      input_adc.cpp
  2. +10
    -12
      input_adcs.cpp

+ 6
- 8
input_adc.cpp 파일 보기

#include "utility/pdb.h" #include "utility/pdb.h"
#include "utility/dspinst.h" #include "utility/dspinst.h"


#define COEF_HPF_DCBLOCK (1048300<<4) // DC Removal filter coefficient in S7.24
#define COEF_HPF_DCBLOCK (1048300<<10) // DC Removal filter coefficient in S1.30


DMAMEM static uint16_t analog_rx_buffer[AUDIO_BLOCK_SAMPLES]; DMAMEM static uint16_t analog_rx_buffer[AUDIO_BLOCK_SAMPLES];
audio_block_t * AudioInputAnalog::block_left = NULL; audio_block_t * AudioInputAnalog::block_left = NULL;
// Probably not useful to spin cycles here stabilizing // Probably not useful to spin cycles here stabilizing
// since DC blocking is similar to te external analog filters // since DC blocking is similar to te external analog filters
tmp = (uint16_t) analogRead(pin); tmp = (uint16_t) analogRead(pin);
tmp = ( ((int32_t) tmp) << 8);
tmp = ( ((int32_t) tmp) << 14);
hpf_x1 = tmp; // With constant DC level x1 would be x0 hpf_x1 = tmp; // With constant DC level x1 would be x0
hpf_y1 = 0; // Output will settle here when stable hpf_y1 = 0; // Output will settle here when stable


// y = a*(x[n] - x[n-1] + y[n-1]) // y = a*(x[n] - x[n-1] + y[n-1])
// The coefficient "a" is as follows: // The coefficient "a" is as follows:
// a = UNITY*e^(-2*pi*fc/fs) // a = UNITY*e^(-2*pi*fc/fs)
// UNITY = 2^20
// fc = 2
// fs = 44100
// fc = 2 @ fs = 44100
// //
p = out_left->data; p = out_left->data;
end = p + AUDIO_BLOCK_SAMPLES; end = p + AUDIO_BLOCK_SAMPLES;
do { do {
tmp = (uint16_t)(*p); tmp = (uint16_t)(*p);
tmp = ( ((int32_t) tmp) << 8);
tmp = ( ((int32_t) tmp) << 14);
int32_t acc = hpf_y1 - hpf_x1; int32_t acc = hpf_y1 - hpf_x1;
acc += tmp; acc += tmp;
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1);
hpf_x1 = tmp; hpf_x1 = tmp;
s = signed_saturate_rshift(hpf_y1, 16, 8);
s = signed_saturate_rshift(hpf_y1, 16, 14);
*p++ = s; *p++ = s;
} while (p < end); } while (p < end);



+ 10
- 12
input_adcs.cpp 파일 보기



#if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)


#define COEF_HPF_DCBLOCK (1048300<<4) // DC Removal filter coefficient in S7.24
#define COEF_HPF_DCBLOCK (1048300<<10) // DC Removal filter coefficient in S1.30


DMAMEM static uint16_t left_buffer[AUDIO_BLOCK_SAMPLES]; DMAMEM static uint16_t left_buffer[AUDIO_BLOCK_SAMPLES];
DMAMEM static uint16_t right_buffer[AUDIO_BLOCK_SAMPLES]; DMAMEM static uint16_t right_buffer[AUDIO_BLOCK_SAMPLES];
// Probably not useful to spin cycles here stabilizing // Probably not useful to spin cycles here stabilizing
// since DC blocking is similar to te external analog filters // since DC blocking is similar to te external analog filters
tmp = (uint16_t) analogRead(pin0); tmp = (uint16_t) analogRead(pin0);
tmp = ( ((int32_t) tmp) << 8);
tmp = ( ((int32_t) tmp) << 14);
hpf_x1[0] = tmp; // With constant DC level x1 would be x0 hpf_x1[0] = tmp; // With constant DC level x1 would be x0
hpf_y1[0] = 0; // Output will settle here when stable hpf_y1[0] = 0; // Output will settle here when stable


tmp = (uint16_t) analogReadADC1(pin1); tmp = (uint16_t) analogReadADC1(pin1);
tmp = ( ((int32_t) tmp) << 8);
tmp = ( ((int32_t) tmp) << 14);
hpf_x1[1] = tmp; // With constant DC level x1 would be x0 hpf_x1[1] = tmp; // With constant DC level x1 would be x0
hpf_y1[1] = 0; // Output will settle here when stable hpf_y1[1] = 0; // Output will settle here when stable


// y = a*(x[n] - x[n-1] + y[n-1]) // y = a*(x[n] - x[n-1] + y[n-1])
// The coefficient "a" is as follows: // The coefficient "a" is as follows:
// a = UNITY*e^(-2*pi*fc/fs) // a = UNITY*e^(-2*pi*fc/fs)
// UNITY = 2^20
// fc = 2
// fs = 44100
// fc = 2 @ fs = 44100
// //


// DC removal, LEFT // DC removal, LEFT
end = p + AUDIO_BLOCK_SAMPLES; end = p + AUDIO_BLOCK_SAMPLES;
do { do {
tmp = (uint16_t)(*p); tmp = (uint16_t)(*p);
tmp = ( ((int32_t) tmp) << 8);
tmp = ( ((int32_t) tmp) << 14);
int32_t acc = hpf_y1[0] - hpf_x1[0]; int32_t acc = hpf_y1[0] - hpf_x1[0];
acc += tmp; acc += tmp;
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1);
hpf_x1[0] = tmp; hpf_x1[0] = tmp;
s = signed_saturate_rshift(hpf_y1[0], 16, 8);
s = signed_saturate_rshift(hpf_y1[0], 16, 14);
*p++ = s; *p++ = s;
} while (p < end); } while (p < end);


end = p + AUDIO_BLOCK_SAMPLES; end = p + AUDIO_BLOCK_SAMPLES;
do { do {
tmp = (uint16_t)(*p); tmp = (uint16_t)(*p);
tmp = ( ((int32_t) tmp) << 8);
tmp = ( ((int32_t) tmp) << 14);
int32_t acc = hpf_y1[1] - hpf_x1[1]; int32_t acc = hpf_y1[1] - hpf_x1[1];
acc += tmp; acc += tmp;
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1);
hpf_x1[1] = tmp; hpf_x1[1] = tmp;
s = signed_saturate_rshift(hpf_y1[1], 16, 8);
s = signed_saturate_rshift(hpf_y1[1], 16, 14);
*p++ = s; *p++ = s;
} while (p < end); } while (p < end);



Loading…
취소
저장