arturzorzo
Member
Hello guys,
I'm using this code, for the teensy 3.6, to do system identification in the audio range based on adaptive filtering.
Is working really well but I would really like to know if there is a way of optimizing the code so I can use bigger filters with the same sampling rate. I've been working with signal processing for a while but I'm fairly new to embedded systems.
I read that the ARM cortex M4 has some built-in optimized DSP functions. How can I use them to make the code run faster? How can I make the Fir filtering with those functions?
I'm accepting any advices and tips.
Obs: Im not using the audio shield
/*
Created in : 15/06/2017 11:26:03
Author: Artur Zorzo
*/
/* System Identification with LMS and white noise //
// Teensy 3.6 */
#include <arduino.h>
// Declaration
long int a = 0; // Stop criterion
const int taps = 50; // Fir filter size
float w[taps]; // Fir filter vector
unsigned int x[taps]; // Signal Vector
signed int e; // Error variable
unsigned int r; // Random number
unsigned int y = 0; // Filter output
unsigned int d; // Input
float g; // Sum
//CONFIGURATIONS
void setup() {
analogReadResolution(12); // AD Resolution
analogWriteResolution(12); // DAC Resolution
Serial.begin(19200); // Serial communication
analogWrite(A22, 2048);
delayMicroseconds(30);
}// Setup end
//Loop
void loop() {
r = random(4095); // White noise generation
x[0] = r;
analogWrite(A22, r);
y = 0; // y initialization
for (int i = 0; i <= (taps - 1); i++) // Convolution
{
y = y + w * x;
}
d = analogRead(A0);
e = d - y; // Error calculation
for (int i = 0; i <= (taps - 1); i++) // Filter refresh
{
g = (((float)x * e) / (400000000.00));
w = w + g;
}
for (int i = (taps - 1); i >= 1; i--) // Signal vector refresh
x = x[i - 1];
}
// Show filter coeficients
if (a == 50000)
{
for (int i = 0; i <= (taps - 1); i++)
{
Serial.print(w);
Serial.print("\t");
}
while (1)
{
}
}
a = a + 1;
} // End Loop
I'm using this code, for the teensy 3.6, to do system identification in the audio range based on adaptive filtering.
Is working really well but I would really like to know if there is a way of optimizing the code so I can use bigger filters with the same sampling rate. I've been working with signal processing for a while but I'm fairly new to embedded systems.
I read that the ARM cortex M4 has some built-in optimized DSP functions. How can I use them to make the code run faster? How can I make the Fir filtering with those functions?
I'm accepting any advices and tips.
Obs: Im not using the audio shield
/*
Created in : 15/06/2017 11:26:03
Author: Artur Zorzo
*/
/* System Identification with LMS and white noise //
// Teensy 3.6 */
#include <arduino.h>
// Declaration
long int a = 0; // Stop criterion
const int taps = 50; // Fir filter size
float w[taps]; // Fir filter vector
unsigned int x[taps]; // Signal Vector
signed int e; // Error variable
unsigned int r; // Random number
unsigned int y = 0; // Filter output
unsigned int d; // Input
float g; // Sum
//CONFIGURATIONS
void setup() {
analogReadResolution(12); // AD Resolution
analogWriteResolution(12); // DAC Resolution
Serial.begin(19200); // Serial communication
analogWrite(A22, 2048);
delayMicroseconds(30);
}// Setup end
//Loop
void loop() {
r = random(4095); // White noise generation
x[0] = r;
analogWrite(A22, r);
y = 0; // y initialization
for (int i = 0; i <= (taps - 1); i++) // Convolution
{
y = y + w * x;
}
d = analogRead(A0);
e = d - y; // Error calculation
for (int i = 0; i <= (taps - 1); i++) // Filter refresh
{
g = (((float)x * e) / (400000000.00));
w = w + g;
}
for (int i = (taps - 1); i >= 1; i--) // Signal vector refresh
x = x[i - 1];
}
// Show filter coeficients
if (a == 50000)
{
for (int i = 0; i <= (taps - 1); i++)
{
Serial.print(w);
Serial.print("\t");
}
while (1)
{
}
}
a = a + 1;
} // End Loop