diff --git a/sndlock.cpp b/sndlock.cpp index 3be9baa..0e904cf 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -39,6 +39,7 @@ static float in_wave[HIST_DEPTH]; static std::atomic multiplier[SND_PCHAN]; static std::atomic lpf_bandwidth[SND_PCHAN]; +static std::atomic> ramc[SND_PCHAN]; static std::atomic principal_angle[SND_PCHAN]; static std::atomic li_principal[SND_PCHAN]; @@ -216,7 +217,7 @@ static void dsp_thread() } for(int j=0;j lockin_out = lockin[j].update(sample); + std::complex lockin_out = lockin[j].update(sample) - (std::complex)ramc[j]; double principal = std::real(lockin_out*std::polar(1.0, (double)principal_angle[j])); li_principal[j] = principal; @@ -360,6 +361,7 @@ int main(int argc, char* argv[]) amplitude[i] = 1.0; multiplier[i] = 1; lpf_bandwidth[i] = 8.5; + ramc[i] = { 0.0, 0.0 }; principal_angle[i] = M_PI/4.0; servo_state[i] = "DISABLED"; init_current_cooling[i] = 310.0f; @@ -395,6 +397,9 @@ int main(int argc, char* argv[]) }; std::atexit(SetShutdown); + bool ramc_enable[SND_PCHAN] = { false }; + float ramc_mag[SND_PCHAN] = { 0.0f }; + float ramc_phase[SND_PCHAN] = { 0.0f }; int plot_sel[SND_PCHAN] = { 0 }; while(!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -469,6 +474,33 @@ int main(int argc, char* argv[]) sprintf(str, "3f##%d", i); ImGui::RadioButton(str, &multiplier_l, 3); multiplier[i] = multiplier_l; + + ImGui::SameLine(); + ImGui::Text("| RAM cancellation:"); + sprintf(str, "enable##ramc%d", i); + ImGui::SameLine(); + ImGui::Checkbox(str, &ramc_enable[i]); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x / 7.0f); + sprintf(str, "magnitude##ramc%d", i); + ImGui::SameLine(); + ImGui::InputFloat(str, &ramc_mag[i], 0.001f, 0.01f, "%.4f"); + sprintf(str, "phase##ramc%d", i); + ImGui::SameLine(); + ImGui::InputFloat(str, &ramc_phase[i], 0.1f, 0.5f, "%.4f"); + ImGui::PopItemWidth(); + ImGui::SameLine(); + sprintf(str, "baseline##ramc%d", i); + if(ImGui::Button(str)) { + std::lock_guard guard(li_hist_mutex); + std::complex new_ramc = std::polar(li_hist_mag[i][HIST_DEPTH-1], li_hist_phase[i][HIST_DEPTH-1]) + (std::complex)ramc[i]; + ramc_mag[i] = std::abs(new_ramc); + ramc_phase[i] = std::arg(new_ramc); + } + if(ramc_enable[i]) + ramc[i] = std::polar(ramc_mag[i], ramc_phase[i]); + else + ramc[i] = { 0.0, 0.0 }; + sprintf(str, "LPF BW##%d", i); float lpf_bandwidth_l = lpf_bandwidth[i]; ImGui::SliderFloat(str, &lpf_bandwidth_l, 0.5f, 200.0f);