Hello,
I am writing a program for a sonar application and using FMCW pulse. I am using the audio expander capelet to output from 2 speakers and pick up echo on 4 mics.
At the moment I'm outputting to speakers from the expander output pins, and reading through documentation, I'm getting slightly different messages on how to scale my FMCW pulse before sending.
Here's the portion of code where I write one of my puises and send
if(t_mod < T_c){ //first pulse
double N = T_c/gInverseSampleRate;
double n = t_mod/gInverseSampleRate;
double w_n = sin((float)M_PI*n/N);//hann window
double gPhase = Fc*t_mod + B*pow(t_mod,2)/(2*T_c);
out_0 = w_n*w_n*cos(2.0f * (float)M_PI * gPhase);
analogWriteOnce(context, n, S_0, out_0*.4);// values will be sent at end of render()
}
t_mod += gInverseSampleRate; //increment time
I found an example for audio expander capelet on the Bela board that suggests multiplying signal by .4 within analogWriteOnce:
// when using the capelet, the analog output is AC-coupled,
// so we center it around 0, exactly the same as for the audio out
analogWriteOnce(context, n, S_0, out_0*.4);
And on the website https://github.com/BelaPlatform/Bela/wiki/Using-the-Audio-Expander-Capelet
in the "Under the Hood" section, they recommend first shift by 1 before scaling:
"Using analogWriteOnce(), the signal would normally be scaled between 0 and 1, not between -1 and 1 as with audioWrite(). To rescale an audio signal to this range, you should add 1 and multiply by 0.5."
analogWriteOnce(context, n, S_0, (1+out_0)*.4);
Is there a reason one might wish to use one or the other before writing to analog pin?
Thanks in advance!