Add global DC-Filter and remove all individual DC-Filters
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
#define PI M_PI
|
||||
|
||||
#define CUT_OFF_H 300.0 /* cut-off frequency for high-pass filters */
|
||||
#define CUT_OFF_H 100.0 /* cut-off frequency for high-pass filter */
|
||||
|
||||
static void gen_sine(double *samples, int num, int samplerate, double freq)
|
||||
{
|
||||
@@ -106,8 +106,6 @@ void de_emphasis(emphasis_t *state, double *samples, int num)
|
||||
double x, y, y_last, factor, amp;
|
||||
int i;
|
||||
|
||||
filter_process(&state->d.hp, samples, num);
|
||||
|
||||
y_last = state->d.y_last;
|
||||
factor = state->d.factor;
|
||||
amp = state->d.amp;
|
||||
@@ -126,3 +124,9 @@ void de_emphasis(emphasis_t *state, double *samples, int num)
|
||||
state->d.y_last = y_last;
|
||||
}
|
||||
|
||||
/* high pass filter to remove DC and low frequencies */
|
||||
void dc_filter(emphasis_t *state, double *samples, int num)
|
||||
{
|
||||
filter_process(&state->d.hp, samples, num);
|
||||
}
|
||||
|
||||
|
@@ -17,4 +17,5 @@ typedef struct emphasis {
|
||||
int init_emphasis(emphasis_t *state, int samplerate, double cut_off);
|
||||
void pre_emphasis(emphasis_t *state, double *samples, int num);
|
||||
void de_emphasis(emphasis_t *state, double *samples, int num);
|
||||
void dc_filter(emphasis_t *state, double *samples, int num);
|
||||
|
||||
|
@@ -30,30 +30,26 @@
|
||||
* audio level calculation
|
||||
*/
|
||||
|
||||
/* return average value (rectified value), that can be 0..1 */
|
||||
/* Return average value (rectified value)
|
||||
* The input must not have any dc offset!
|
||||
* For a perfect rectangualr wave, the result would equal the peak level.
|
||||
* For a sine wave the result would be factor (2 / PI) below peak level.
|
||||
*/
|
||||
double audio_level(sample_t *samples, int length)
|
||||
{
|
||||
double bias;
|
||||
double level;
|
||||
int sk;
|
||||
double level, sk;
|
||||
int n;
|
||||
|
||||
/* calculate bias */
|
||||
bias = 0;
|
||||
for (n = 0; n < length; n++)
|
||||
bias += samples[n];
|
||||
bias = bias / length;
|
||||
|
||||
/* level calculation */
|
||||
level = 0;
|
||||
for (n = 0; n < length; n++) {
|
||||
sk = samples[n] - bias;
|
||||
sk = samples[n];
|
||||
if (sk < 0)
|
||||
level -= (double)sk;
|
||||
if (sk > 0)
|
||||
level += (double)sk;
|
||||
}
|
||||
level = level / (double)length / 32767.0;
|
||||
level = level / (double)length;
|
||||
|
||||
return level;
|
||||
}
|
||||
@@ -79,17 +75,10 @@ void audio_goertzel_init(goertzel_t *goertzel, double freq, int samplerate)
|
||||
*/
|
||||
void audio_goertzel(goertzel_t *goertzel, sample_t *samples, int length, int offset, double *result, int k)
|
||||
{
|
||||
double bias;
|
||||
double sk, sk1, sk2;
|
||||
double cos2pik;
|
||||
int i, n;
|
||||
|
||||
/* calculate bias to remove DC */
|
||||
bias = 0;
|
||||
for (n = 0; n < length; n++)
|
||||
bias += samples[n];
|
||||
bias = bias / length;
|
||||
|
||||
/* we do goertzel */
|
||||
for (i = 0; i < k; i++) {
|
||||
sk = 0;
|
||||
@@ -98,7 +87,7 @@ void audio_goertzel(goertzel_t *goertzel, sample_t *samples, int length, int off
|
||||
cos2pik = goertzel[i].coeff;
|
||||
/* note: after 'length' cycles, offset is restored to its initial value */
|
||||
for (n = 0; n < length; n++) {
|
||||
sk = (cos2pik * sk1) - sk2 + samples[offset++] - bias;
|
||||
sk = (cos2pik * sk1) - sk2 + samples[offset++];
|
||||
sk2 = sk1;
|
||||
sk1 = sk;
|
||||
if (offset == length)
|
||||
|
@@ -281,7 +281,7 @@ cant_recover:
|
||||
display_wave(inst, samples[i], count);
|
||||
sender_receive(inst, samples[i], count);
|
||||
}
|
||||
/* do pre emphasis towards radio, not wave_write */
|
||||
/* do pre emphasis towards radio */
|
||||
if (inst->pre_emphasis)
|
||||
pre_emphasis(&inst->estate, samples[i], count);
|
||||
/* set paging signal */
|
||||
@@ -331,9 +331,11 @@ transmit_later:
|
||||
/* rx gain */
|
||||
if (inst->rx_gain != 1.0)
|
||||
gain_samples(samples[i], count, inst->rx_gain);
|
||||
/* do de emphasis from radio (then write_wave/wave_read), receive audio, process echo test */
|
||||
if (inst->de_emphasis)
|
||||
/* do filter and de-emphasis from radio receive audio, process echo test */
|
||||
if (inst->de_emphasis) {
|
||||
dc_filter(&inst->estate, samples[i], count);
|
||||
de_emphasis(&inst->estate, samples[i], count);
|
||||
}
|
||||
if (inst->loopback != 1) {
|
||||
display_wave(inst, samples[i], count);
|
||||
sender_receive(inst, samples[i], count);
|
||||
|
Reference in New Issue
Block a user