Part Number: TMS320C5505
Tool/software: Code Composer Studio
Hello all,
Does anyone know how to implement integration in c code?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: TMS320C5505
Tool/software: Code Composer Studio
Hello all,
Does anyone know how to implement integration in c code?
Hi,
First of all, thanks for your quick reply.
I am implementing parametric loudspeaker. In these speakers, we modulate the audio signal (envelope) on ultrasonic carrier signal of high frequency and send this modulated signal in air. The sound heard by the listener is proportional to the second time derivative of square of envelope .
Thus,my objective is to read audio input, integrate it , then square root it and then use this square rooted signal as envelope.
I don't know how to write the code to integrate the audio signal before taking its square root.
Please help if you can.
Thanks and regards,
Satyajit
You are darn close to an rms algorithm:
en.wikipedia.org/.../Root_mean_square
Just don't square the input.
Assuming you have equal samples, you need to sum a set of your values and divide by the time interval.
I did an experiment. By averaging over a subset of the data, I could get this:
Which is darn close to an integration. But, if the averaging interval = the period you get this:
Which makes sense when you think about it. Here is the code:
Because it intrigued me I did an experiment. The code is in C# so you may need to tweak a bit:
const int points = 50000;
const int cycles = 5;
const int intpoints = 10000;
float[] datSine = new float[points];
float[] datInt = new float[points];
float[] datrms = new float[points];
for (int i = 0; i < points; i++)
{
datSine[i] = (float) Math.Sin(2 * Math.PI * i* cycles / points);
datInt[i] = 0.0f;
}
for (int i = intpoints / 2; i < points - intpoints / 2; i++)
{
if (i > points - 1) break;
float sum = 0;
float sumsq = 0;
for (int j = i; j < i + intpoints; j++)
{
if (j > points - 1) break;
sum += datSine[j];
sumsq += datSine[j] * datSine[j];
}
datInt[i] = sum / intpoints ;
datrms[i] = (float)Math.Sqrt(sumsq / intpoints);
}