Weiter kommentiert
This commit is contained in:
56
main.c
56
main.c
@@ -54,7 +54,6 @@ static int16_t chess_storage(DMB) outputPort[BLOCK_LEN]; // chess_storage(DMB:OU
|
|||||||
extern "C" void isr0() property (isr) {
|
extern "C" void isr0() property (isr) {
|
||||||
actionRequired = 1;
|
actionRequired = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __chess__
|
#ifdef __chess__
|
||||||
extern "C"
|
extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -62,32 +61,27 @@ extern "C"
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
// Enum, welcher den Ausgabemodus definiert - wird in calc()-Funktion verwendet
|
// Enum, welcher den Ausgabemodus definiert - wird in calc()-Funktion verwendet
|
||||||
static OutputMode mode = OUTPUT_MODE_FIR_LMS;
|
static OutputMode mode = OUTPUT_MODE_FIR_LMS;
|
||||||
|
// Biquad Filter für C-Sensor und Acc-Sensor anlegen
|
||||||
// Initialize the signal path
|
// Alle 0 bis auf b[0] -> einfacher Gain auf 0,75
|
||||||
// Initialize the csensor signal subpath
|
|
||||||
// Instanciate the signal path state structs
|
|
||||||
|
|
||||||
// Deactivate preemphasis filter by initializing with coefficients {1., 0., 0., 0., 0.}
|
|
||||||
// biquad filter coefficients - off
|
|
||||||
double b0[5]={0.75, 0., 0., 0., 0.};
|
double b0[5]={0.75, 0., 0., 0., 0.};
|
||||||
double b1[5]={0.75, 0., 0., 0., 0.};
|
double b1[5]={0.75, 0., 0., 0., 0.};
|
||||||
int N_lms_fir_coeffs = MAX_FIR_COEFFS; // always test with max coeffs
|
int N_lms_fir_coeffs = MAX_FIR_COEFFS; // 64 Koeffizienten für ANR
|
||||||
|
|
||||||
//init-Funktion aufrufen
|
// Signale initialisieren, oben angelegte Structs mit Parametern füllen
|
||||||
init(
|
init(
|
||||||
&cSensorSignal, &accSensorSignal,
|
&cSensorSignal, &accSensorSignal, //Signal-Structs
|
||||||
//&ptr_fir_lms_delay_line, &ptr_fir_lms_coeffs,
|
b0, // Biqquad Koeffizienten C-Sensor
|
||||||
b0,
|
b1, // Biqquad Koeffizienten Acc-Sensor
|
||||||
b1,
|
2, // Sample Delay C-Sensor
|
||||||
2, // sample delayS
|
2, // Sample Delay Acc-Sensor
|
||||||
2,
|
0.9, //Gewichtung C-Sensor
|
||||||
0.9, // weight
|
0.9, //Gewichtung Acc-Sensor
|
||||||
0.9,
|
0.01, // Mu
|
||||||
0.01, // lms learning rate
|
N_lms_fir_coeffs // Anzahl Filterkoeffizienten
|
||||||
N_lms_fir_coeffs // Numer of lms fir coefficients
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (mode == OUTPUT_MODE_FIR){ //FIR filter mit fixen coeffizienten wenn nicht adaptiv
|
// Fixer Filter wenn nicht adaptiv
|
||||||
|
if (mode == OUTPUT_MODE_FIR){
|
||||||
for (int i=0; i<N_lms_fir_coeffs; i++){
|
for (int i=0; i<N_lms_fir_coeffs; i++){
|
||||||
#ifdef LPDSP16
|
#ifdef LPDSP16
|
||||||
ptr_fir_lms_coeffs.ptr_start[i] = ((pow(2, 15)-1) /N_lms_fir_coeffs);
|
ptr_fir_lms_coeffs.ptr_start[i] = ((pow(2, 15)-1) /N_lms_fir_coeffs);
|
||||||
@@ -97,7 +91,8 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SIMULATE // use the simulator with file I/O
|
//Simulationsmodus mit File I/O
|
||||||
|
#ifdef SIMULATE
|
||||||
FILE *fp1 = fopen("./test/testdata/input/chirp_disturber.txt", "r");
|
FILE *fp1 = fopen("./test/testdata/input/chirp_disturber.txt", "r");
|
||||||
FILE *fp2 = fopen("./test/testdata/input/disturber.txt", "r");
|
FILE *fp2 = fopen("./test/testdata/input/disturber.txt", "r");
|
||||||
FILE *fp3 = fopen("./test/testdata/output/out_simulated.txt", "w");
|
FILE *fp3 = fopen("./test/testdata/output/out_simulated.txt", "w");
|
||||||
@@ -105,14 +100,12 @@ int main(void) {
|
|||||||
int d0, d1;
|
int d0, d1;
|
||||||
|
|
||||||
while (!(feof(fp1) || feof(fp2))){
|
while (!(feof(fp1) || feof(fp2))){
|
||||||
|
|
||||||
for (int i=0; i<BLOCK_LEN; i++){
|
for (int i=0; i<BLOCK_LEN; i++){
|
||||||
fscanf(fp1, "%d", &d0); //load blocks
|
fscanf(fp1, "%d", &d0); //load blocks
|
||||||
fscanf(fp2, "%d", &d1);
|
fscanf(fp2, "%d", &d1);
|
||||||
intputPort[i] = (int16_t) d0;
|
intputPort[i] = (int16_t) d0;
|
||||||
intputPort[i+1] = (int16_t) d1;
|
intputPort[i+1] = (int16_t) d1;
|
||||||
}
|
}
|
||||||
|
|
||||||
calc(
|
calc(
|
||||||
&cSensorSignal, &accSensorSignal,
|
&cSensorSignal, &accSensorSignal,
|
||||||
//&ptr_fir_lms_delay_line, &ptr_fir_lms_coeffs,
|
//&ptr_fir_lms_delay_line, &ptr_fir_lms_coeffs,
|
||||||
@@ -121,7 +114,6 @@ int main(void) {
|
|||||||
&intputPort[1],
|
&intputPort[1],
|
||||||
outputPort
|
outputPort
|
||||||
);
|
);
|
||||||
|
|
||||||
for (int i=0; i<BLOCK_LEN; i++){
|
for (int i=0; i<BLOCK_LEN; i++){
|
||||||
fprintf(fp3, "%d\n", outputPort[i]);
|
fprintf(fp3, "%d\n", outputPort[i]);
|
||||||
}
|
}
|
||||||
@@ -130,19 +122,19 @@ int main(void) {
|
|||||||
fclose(fp2);
|
fclose(fp2);
|
||||||
fclose(fp3);
|
fclose(fp3);
|
||||||
|
|
||||||
#else // how its done in hw
|
// Hardwaremodus mit Interrupts
|
||||||
// enable the interrupts
|
#else
|
||||||
enable_interrupts();
|
enable_interrupts(); //Interrupts aktivieren
|
||||||
outPtr = &outputPort[1]; // start with second half of buffer
|
outPtr = &outputPort[1]; // Zweite Hälfte des Ausgangspuffers zuerst füllen - warum 1 statt 2?
|
||||||
sample_ptr = &sample;
|
sample_ptr = &sample;
|
||||||
|
|
||||||
/*Signalprocessing, called by an interrupt*/
|
//Endlosschleife für Interrupt-gesteuerte Verarbeitung
|
||||||
actionRequired = 0;
|
actionRequired = 0;
|
||||||
while (1){
|
while (1){
|
||||||
CssCmdGen = CSS_CMD_1; // indicate going to sleep to the cm3
|
CssCmdGen = CSS_CMD_1; // Interrupt Bit setzen um ARM zu signalisieren, dass der DSP abschaltet
|
||||||
core_halt();
|
core_halt();
|
||||||
if (actionRequired == 1) {
|
if (actionRequired == 1) {
|
||||||
CssCmdGen = CSS_CMD_0; // indicate wakeup to the cm3
|
CssCmdGen = CSS_CMD_0; // Interrupt Bit setzen um ARM zu signalisieren, dass der DSP arbeitet
|
||||||
actionRequired = 0;
|
actionRequired = 0;
|
||||||
|
|
||||||
outPtr = cyclic_add(outPtr, 2, outputPort, 4);
|
outPtr = cyclic_add(outPtr, 2, outputPort, 4);
|
||||||
|
|||||||
@@ -156,14 +156,15 @@ void static inline sig_circular_buffer_ptr_put_block(BufferPtr *buffer, int* blo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sig_init_preemph_coef(SingleSignalPath *signal, double b0, double b1, double b2, double a1, double a2, int scale_bits) {
|
void sig_init_preemph_coef(SingleSignalPath *signal, double b0, double b1, double b2, double a1, double a2, int scale_bits) {
|
||||||
// Check first if filter is actually activated
|
// Wenn b0=1 und Rest 0 -> kein Filter weil effektiv 1*Xn
|
||||||
if (b0 == 1. && b1 == 0. && b2 == 0. && a1 == 0. && a2 == 0.) {
|
if (b0 == 1. && b1 == 0. && b2 == 0. && a1 == 0. && a2 == 0.) {
|
||||||
signal->preemph_activated = 0;
|
signal->preemph_activated = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
signal->preemph_activated = 1;
|
signal->preemph_activated = 1; // Schreibe Eintrag in Struct
|
||||||
signal->_preemph_scale_nbits = scale_bits;
|
signal->_preemph_scale_nbits = scale_bits; // Schreibe Eintrag in Struct - wieviel Bits wird skaliert
|
||||||
int scale = pow(2, scale_bits) - 1;
|
int scale = pow(2, scale_bits) - 1; //2^n -1 Skalierung
|
||||||
|
// Skaliere Koeffizienten zu Interger und schreibe Eintrag in Struct
|
||||||
signal->b_preemph[0] = b0 * scale;
|
signal->b_preemph[0] = b0 * scale;
|
||||||
signal->b_preemph[1] = b1 * scale;
|
signal->b_preemph[1] = b1 * scale;
|
||||||
signal->b_preemph[2] = b2 * scale;
|
signal->b_preemph[2] = b2 * scale;
|
||||||
@@ -178,9 +179,11 @@ int sig_init_delay(SingleSignalPath *signal, int n_delay) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sig_init_weight(SingleSignalPath *signal, double weight, int scale_nbits) {
|
void sig_init_weight(SingleSignalPath *signal, double weight, int scale_nbits) {
|
||||||
|
// Wenn Gewichtung 1 -> kein Effekt
|
||||||
if (weight == 1.) {
|
if (weight == 1.) {
|
||||||
signal->weight_actived = 0;
|
signal->weight_actived = 0;
|
||||||
}
|
}
|
||||||
|
// Wenn Gewichtung != 1 -> Zu Integer skalieren und Eintrag in Struct schreiben
|
||||||
else{
|
else{
|
||||||
signal->weight_actived = 1;
|
signal->weight_actived = 1;
|
||||||
int scale = pow(2, scale_nbits) - 1;
|
int scale = pow(2, scale_nbits) - 1;
|
||||||
@@ -573,8 +576,6 @@ void adapt_coeffs_generic_single(BufferPtrDMB chess_storage(DMB) *ptr_fir_lms_de
|
|||||||
void init(
|
void init(
|
||||||
SingleSignalPath *cSensorSignal,
|
SingleSignalPath *cSensorSignal,
|
||||||
SingleSignalPath *accSensorSignal,
|
SingleSignalPath *accSensorSignal,
|
||||||
//BufferPtrDMB *ptr_fir_lms_delay_line,
|
|
||||||
//BufferPtr *ptr_fir_lms_coeffs,
|
|
||||||
double *b_c,
|
double *b_c,
|
||||||
double *b_acc,
|
double *b_acc,
|
||||||
int delay_c,
|
int delay_c,
|
||||||
@@ -590,19 +591,20 @@ void init(
|
|||||||
int scale_bits=31;
|
int scale_bits=31;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// C-Sensor Initialisierung: Biquad, Delay, Weight skalieren und in Struct schreiben
|
||||||
sig_init_preemph_coef(cSensorSignal, b_c[0], b_c[1], b_c[2], b_c[3], b_c[4], scale_bits);
|
sig_init_preemph_coef(cSensorSignal, b_c[0], b_c[1], b_c[2], b_c[3], b_c[4], scale_bits);
|
||||||
sig_init_delay(cSensorSignal, delay_c);
|
sig_init_delay(cSensorSignal, delay_c);
|
||||||
sig_init_weight(cSensorSignal, weight_c, scale_bits);
|
sig_init_weight(cSensorSignal, weight_c, scale_bits);
|
||||||
|
|
||||||
// // Initialize the accSensor signal subpath
|
// Acc-Sensor Initialisierung: Biquad, Delay, Weight skalieren und in Struct schreiben
|
||||||
sig_init_preemph_coef(accSensorSignal, b_acc[0], b_acc[1], b_acc[2], b_acc[3], b_acc[4], scale_bits);
|
sig_init_preemph_coef(accSensorSignal, b_acc[0], b_acc[1], b_acc[2], b_acc[3], b_acc[4], scale_bits);
|
||||||
sig_init_delay(accSensorSignal, delay_acc);
|
sig_init_delay(accSensorSignal, delay_acc);
|
||||||
sig_init_weight(accSensorSignal, weight_acc, 31);
|
sig_init_weight(accSensorSignal, weight_acc, 31);
|
||||||
|
|
||||||
// initialize the lms filter parameters
|
//Mu Skalierung und in globale Variable schreiben
|
||||||
int scale = pow(2, scale_bits) - 1;
|
int scale = pow(2, scale_bits) - 1;
|
||||||
mu = lms_mu * scale;
|
mu = lms_mu * scale;
|
||||||
// initialize the fir_lms buffers
|
// Buffer Initialisierung
|
||||||
#if BLOCK_LEN == 1
|
#if BLOCK_LEN == 1
|
||||||
sig_init_buffer_DMB(&ptr_fir_lms_delay_line, fir_lms_delay_line, lms_fir_num_coeffs, MAX_FIR_COEFFS);
|
sig_init_buffer_DMB(&ptr_fir_lms_delay_line, fir_lms_delay_line, lms_fir_num_coeffs, MAX_FIR_COEFFS);
|
||||||
sig_init_buffer(&ptr_fir_lms_coeffs, fir_lms_coeffs, lms_fir_num_coeffs, MAX_FIR_COEFFS);
|
sig_init_buffer(&ptr_fir_lms_coeffs, fir_lms_coeffs, lms_fir_num_coeffs, MAX_FIR_COEFFS);
|
||||||
|
|||||||
Reference in New Issue
Block a user