New filter settings

This commit is contained in:
Christophe Jacquet 2014-04-05 19:36:06 +02:00
parent 5e389fa49d
commit 62893331f7
4 changed files with 39 additions and 19 deletions

View File

@ -3,10 +3,10 @@
# This program uses Pydemod, see https://github.com/ChristopheJacquet/Pydemod # This program uses Pydemod, see https://github.com/ChristopheJacquet/Pydemod
import pydemod.app.rds as rds import pydemod.app.rds as rds
import pydemod.modulation.am as am
import numpy import numpy
import scipy.io.wavfile as wavfile import scipy.io.wavfile as wavfile
import io import io
import matplotlib.pyplot as plt
sample_rate = 228000 sample_rate = 228000
@ -29,16 +29,29 @@ def generate_bit_in_context(pattern, name):
l = 96 l = 96
count = 2 count = 2
shapedSamples = rds.unmodulated_signal(pattern, sample_rate)
out = shapedSamples #[offset:offset+l*count] sample = numpy.zeros(3*l)
sample[l] = 1
sample[2*l] = -1
# Apply the data-shaping filter
sf = rds.pulse_shaping_filter(96*8, 228000)
shapedSamples = numpy.convolve(sample, sf)
# shapedSamples = rds.unmodulated_signal(pattern, sample_rate)
out = shapedSamples[528-288:528+288] #[offset:offset+l*count]
plt.plot(sf)
plt.plot(out)
plt.show()
iout = (out * 20000./max(abs(out)) ).astype(numpy.dtype('>i2')) iout = (out * 20000./max(abs(out)) ).astype(numpy.dtype('>i2'))
wavfile.write(u"waveform_{}.wav".format(name), sample_rate, iout) wavfile.write(u"waveform_{}.wav".format(name), sample_rate, iout)
outc.write(u"float waveform_{name}[] = {{{values}}};\n\n".format( outc.write(u"float waveform_{name}[] = {{{values}}};\n\n".format(
name = name, name = name,
values = u", ".join(map(unicode, out/3.)))) values = u", ".join(map(unicode, out/2.5))))
# note: need to limit the amplitude so as not to saturate when the biphase # note: need to limit the amplitude so as not to saturate when the biphase
# waveforms are summed # waveforms are summed

View File

@ -42,6 +42,7 @@ struct {
#define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE+POLY_DEG)) #define BITS_PER_GROUP (GROUP_LENGTH * (BLOCK_SIZE+POLY_DEG))
#define SAMPLES_PER_BIT 192 #define SAMPLES_PER_BIT 192
#define FILTER_SIZE (sizeof(waveform_biphase)/sizeof(float)) #define FILTER_SIZE (sizeof(waveform_biphase)/sizeof(float))
#define SAMPLE_BUFFER_SIZE (8*SAMPLES_PER_BIT)
uint16_t offset_words[] = {0x0FC, 0x198, 0x168, 0x1B4}; uint16_t offset_words[] = {0x0FC, 0x198, 0x168, 0x1B4};
@ -118,7 +119,7 @@ void get_rds_group(int *buffer) {
void get_rds_samples(float *buffer, int count) { void get_rds_samples(float *buffer, int count) {
static int bit_buffer[BITS_PER_GROUP]; static int bit_buffer[BITS_PER_GROUP];
static int bit_pos = BITS_PER_GROUP; static int bit_pos = BITS_PER_GROUP;
static float sample_buffer[2*FILTER_SIZE] = {0}; static float sample_buffer[SAMPLE_BUFFER_SIZE] = {0};
static int prev_output = 0; static int prev_output = 0;
static int cur_output = 0; static int cur_output = 0;
@ -128,7 +129,7 @@ void get_rds_samples(float *buffer, int count) {
static int phase = 0; static int phase = 0;
static int in_sample_index = 0; static int in_sample_index = 0;
static int out_sample_index = FILTER_SIZE; static int out_sample_index = 0;
for(int i=0; i<count; i++) { for(int i=0; i<count; i++) {
if(sample_count >= SAMPLES_PER_BIT) { if(sample_count >= SAMPLES_PER_BIT) {
@ -142,21 +143,27 @@ void get_rds_samples(float *buffer, int count) {
prev_output = cur_output; prev_output = cur_output;
cur_output = prev_output ^ cur_bit; cur_output = prev_output ^ cur_bit;
inverting = (cur_output == 1) ? 1 : -1; inverting = (cur_output == 1);
// zero out last bit
int idx = in_sample_index-1;
for(int j=0; j<SAMPLES_PER_BIT; j++) {
if(idx<0) idx = SAMPLE_BUFFER_SIZE-1;
sample_buffer[idx] = 0;
idx--;
}
float *src = waveform_biphase; float *src = waveform_biphase;
int idx = in_sample_index; idx = in_sample_index;
for(int j=0; j<FILTER_SIZE; j++) { for(int j=0; j<FILTER_SIZE; j++) {
//printf("%d ", j); fflush(stdout); float val = (*src++);
if(j<FILTER_SIZE-SAMPLES_PER_BIT) { if(inverting) val = -val;
sample_buffer[idx++] += (*src++) * inverting; sample_buffer[idx++] += val;
} else { if(idx >= SAMPLE_BUFFER_SIZE) idx = 0;
sample_buffer[idx++] = (*src++) * inverting;
}
if(idx >= 2*FILTER_SIZE) idx = 0;
} }
in_sample_index += SAMPLES_PER_BIT; in_sample_index += SAMPLES_PER_BIT;
if(in_sample_index >= 2*FILTER_SIZE) in_sample_index -= 2*FILTER_SIZE; if(in_sample_index >= SAMPLE_BUFFER_SIZE) in_sample_index -= SAMPLE_BUFFER_SIZE;
bit_pos++; bit_pos++;
sample_count = 0; sample_count = 0;
@ -164,7 +171,7 @@ void get_rds_samples(float *buffer, int count) {
} }
float sample = sample_buffer[out_sample_index++]; float sample = sample_buffer[out_sample_index++];
if(out_sample_index >= 2*FILTER_SIZE) out_sample_index = 0; if(out_sample_index >= SAMPLE_BUFFER_SIZE) out_sample_index = 0;
// modulate at 57 kHz // modulate at 57 kHz
// use phase for this // use phase for this

File diff suppressed because one or more lines are too long

View File

@ -4,4 +4,4 @@
Released under the GNU GPL v3 license. Released under the GNU GPL v3 license.
*/ */
extern float waveform_biphase[575]; extern float waveform_biphase[576];