add multiplier
This commit is contained in:
parent
875650345b
commit
d4cb319ddb
@ -47,6 +47,7 @@ template<unsigned int order>
|
|||||||
class Lockin {
|
class Lockin {
|
||||||
private:
|
private:
|
||||||
double scale = 1.0;
|
double scale = 1.0;
|
||||||
|
phase_t multiplier = 1;
|
||||||
phase_t phase = 0;
|
phase_t phase = 0;
|
||||||
Lowpass<std::complex<double>, order> lpf;
|
Lowpass<std::complex<double>, order> lpf;
|
||||||
public:
|
public:
|
||||||
@ -54,12 +55,15 @@ class Lockin {
|
|||||||
void set_scale(double s) {
|
void set_scale(double s) {
|
||||||
scale = s;
|
scale = s;
|
||||||
}
|
}
|
||||||
|
void set_multiplier(phase_t m) {
|
||||||
|
multiplier = m;
|
||||||
|
}
|
||||||
void set_bandwidth(double f) {
|
void set_bandwidth(double f) {
|
||||||
lpf.set_bandwidth(f);
|
lpf.set_bandwidth(f);
|
||||||
}
|
}
|
||||||
std::complex<double> update(double x) {
|
std::complex<double> update(double x) {
|
||||||
std::complex<double> rotated;
|
std::complex<double> rotated;
|
||||||
rotated = x*std::polar(scale, phase*2.0*M_PI/(double)PHASE_MAX);
|
rotated = x*std::polar(scale, multiplier*phase*2.0*M_PI/(double)PHASE_MAX);
|
||||||
phase -= ftw; // wraps on underflow
|
phase -= ftw; // wraps on underflow
|
||||||
return lpf.update(rotated);
|
return lpf.update(rotated);
|
||||||
}
|
}
|
||||||
|
36
sndlock.cpp
36
sndlock.cpp
@ -35,6 +35,7 @@ static std::atomic<int> in_wave_trigger;
|
|||||||
static std::mutex in_wave_mutex;
|
static std::mutex in_wave_mutex;
|
||||||
static float in_wave[HIST_DEPTH];
|
static float in_wave[HIST_DEPTH];
|
||||||
|
|
||||||
|
static std::atomic<int> multiplier[SND_PCHAN];
|
||||||
static std::atomic<double> lpf_bandwidth[SND_PCHAN];
|
static std::atomic<double> lpf_bandwidth[SND_PCHAN];
|
||||||
static std::mutex li_hist_mutex;
|
static std::mutex li_hist_mutex;
|
||||||
static std::atomic<bool> li_hist_pause[SND_PCHAN];
|
static std::atomic<bool> li_hist_pause[SND_PCHAN];
|
||||||
@ -108,8 +109,10 @@ static void dsp_thread()
|
|||||||
poll(pfd, nfds, INFTIM);
|
poll(pfd, nfds, INFTIM);
|
||||||
int revents = sio_revents(hdl, pfd);
|
int revents = sio_revents(hdl, pfd);
|
||||||
|
|
||||||
for(int i=0;i<SND_PCHAN;i++)
|
for(int i=0;i<SND_PCHAN;i++) {
|
||||||
|
lockin[i].set_multiplier(multiplier[i]);
|
||||||
lockin[i].set_bandwidth(lpf_bandwidth[i]/SND_RATE);
|
lockin[i].set_bandwidth(lpf_bandwidth[i]/SND_RATE);
|
||||||
|
}
|
||||||
|
|
||||||
if(revents & POLLOUT) {
|
if(revents & POLLOUT) {
|
||||||
if(buf_out_offset == sizeof(buf_out)) {
|
if(buf_out_offset == sizeof(buf_out)) {
|
||||||
@ -263,6 +266,7 @@ int main(int argc, char* argv[])
|
|||||||
for(int i=0;i<SND_PCHAN;i++) {
|
for(int i=0;i<SND_PCHAN;i++) {
|
||||||
frequency[i] = 441.0 + 202.0*i;
|
frequency[i] = 441.0 + 202.0*i;
|
||||||
amplitude[i] = 1.0;
|
amplitude[i] = 1.0;
|
||||||
|
multiplier[i] = 1;
|
||||||
lpf_bandwidth[i] = 10.0;
|
lpf_bandwidth[i] = 10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +345,26 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
sprintf(str, "Channel %d", i);
|
sprintf(str, "Channel %d", i);
|
||||||
ImGui::SeparatorText(str);
|
ImGui::SeparatorText(str);
|
||||||
|
ImGui::AlignTextToFramePadding();
|
||||||
|
ImGui::Text("multiplier:");
|
||||||
|
int multiplier_l = multiplier[i];
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "f##%d", i);
|
||||||
|
ImGui::RadioButton(str, &multiplier_l, 1);
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "2f##%d", i);
|
||||||
|
ImGui::RadioButton(str, &multiplier_l, 2);
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "3f##%d", i);
|
||||||
|
ImGui::RadioButton(str, &multiplier_l, 3);
|
||||||
|
multiplier[i] = multiplier_l;
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("/");
|
||||||
|
bool pause_l = li_hist_pause[i];
|
||||||
|
ImGui::SameLine();
|
||||||
|
sprintf(str, "pause##%d", i);
|
||||||
|
ImGui::Checkbox(str, &pause_l);
|
||||||
|
li_hist_pause[i] = pause_l;
|
||||||
sprintf(str, "LPF BW##%d", i);
|
sprintf(str, "LPF BW##%d", i);
|
||||||
float lpf_bandwidth_l = lpf_bandwidth[i];
|
float lpf_bandwidth_l = lpf_bandwidth[i];
|
||||||
ImGui::SliderFloat(str, &lpf_bandwidth_l, 0.5f, 200.0f);
|
ImGui::SliderFloat(str, &lpf_bandwidth_l, 0.5f, 200.0f);
|
||||||
@ -354,16 +378,6 @@ int main(int argc, char* argv[])
|
|||||||
ImGui::PlotLines(str, li_hist_mag[i], HIST_DEPTH, 0, 0, -0.0f, 0.1f*plot_scale[i], ImVec2(0.0f, 200.0f));
|
ImGui::PlotLines(str, li_hist_mag[i], HIST_DEPTH, 0, 0, -0.0f, 0.1f*plot_scale[i], ImVec2(0.0f, 200.0f));
|
||||||
sprintf(str, "phase##%d", i);
|
sprintf(str, "phase##%d", i);
|
||||||
ImGui::PlotLines(str, li_hist_phase[i], HIST_DEPTH, 0, 0, -M_PI, M_PI, ImVec2(0.0f, 200.0f));
|
ImGui::PlotLines(str, li_hist_phase[i], HIST_DEPTH, 0, 0, -M_PI, M_PI, ImVec2(0.0f, 200.0f));
|
||||||
}
|
|
||||||
bool pause_l = li_hist_pause[i];
|
|
||||||
sprintf(str, "pause##%d", i);
|
|
||||||
ImGui::Checkbox(str, &pause_l);
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("/");
|
|
||||||
li_hist_pause[i] = pause_l;
|
|
||||||
ImGui::SameLine();
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> guard(li_hist_mutex);
|
|
||||||
ImGui::Text("values: %8.5f %8.5f rad", li_hist_mag[i][511], li_hist_phase[i][511]);
|
ImGui::Text("values: %8.5f %8.5f rad", li_hist_mag[i][511], li_hist_phase[i][511]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user