I tried to extract a pure signal from the noisy signal using a lock-in amplifier with the help of python code. The output is from a photodetector circuit. Reference signal

Expected voltage and noisy output

Reconstructed signal from Lock-in amplifier

These are the reference signal, expected voltage Vz noisy output and extracted signal.

As you can see from the output, the extracted signal is not having the same time period as the expected one.

I have also calculated the SNR of both.

SNR of Input Noisy Signal: -6.83 dB

SNR of Extracted Output: -2.24 dB

This is how I implemented the lock-in amplifier.

X = np.mean(voltage_with_noise * reference_signal)
Y = np.mean(voltage_with_noise * reference_quadrature)
reconstructed_signal = X * np.array(reference_signal) + Y * reference_quadrature

Can anyone suggest how can I improve the extracted signal much better?

I am a newbie and please spare me if I am wrong

Edit 1: enter image description here

X (In-Phase Component): 0.420861516374354

Y (Quadrature Component): 0.24021383914038621

R (Magnitude): 0.4845896248161778

θ (Phase in radians): 0.5186472024872948

  • 1
    $\begingroup$ Please edit your question with an updated plot of the reference signal that includes both it and its quadrature version. While you're editing, please tell us why you're using a sinusoidal reference, and over what time period you're taking the means that get you your X and Y variables. $\endgroup$
    – TimWescott
    Aug 18, 2023 at 16:35
  • $\begingroup$ @TimWescott I am using a square reference signal. I have edited the post and added all the required plots. $\endgroup$
    – Teena
    Aug 18, 2023 at 18:05

1 Answer 1


Your quadrature signal is not actually a quadrature version of your reference signal, and isn't even periodic.

Both your reference and your quadrature signal have non-zero mean -- this is obvious because they go from 0 to 1, not, e.g., -1 to 1. The principle of a lock-in amplifier is that the amplifier itself only passes AC signals, then demodulates them to DC. While there are cases where it makes sense to add an offset to your signal (i.e. to provide bias for a sensor), if you really need the actual DC signal through your system then a lock-in amplifier may not be the correct approach.

This means that whatever you're doing to generate your reference and quadrature reference, that's your problem.

For most purposes, it would be best to use sine waves for your inphase and quadrature components of your reference. I.e., use $$\begin{align}x_r(t) & = \cos(2 \pi f t) \\ x_i(t) &= \sin(2 \pi f t)\end{align}$$

If you must use square waves, then make sure they're symmetrical and truly quadrature. This means that the period must be divisible by four so the zero-crossings of each land in the middle of the plateaus of the other, i.e. $$\begin{align} x_r(t) & = \begin{bmatrix}\cdots & 1 & 1 & 1 & -1 & -1 & -1 & -1 & 1 & 1 & 1 & \cdots\end{bmatrix} \\ x_i(t) &= \begin{bmatrix}\cdots & -1 & 1 & 1 & 1 & 1 & -1 & -1 & -1 & -1 & 1 & \cdots\end{bmatrix} \end{align}$$

  • $\begingroup$ I tried with your suggestion. It improved the SNR ratio. But my input is varying from 0 to 1. So if I use the reference signal from -1 to 1, the reconstructed signal has values from -0.5 to 0.5. How can solve this issue? Can i add a bias voltage and make it to 0 to 1V? Please spare me if I am wrong. $\endgroup$
    – Teena
    Aug 19, 2023 at 14:37
  • $\begingroup$ See my edits. Yes, it's fair to add in bias, but the fact that you need a reference that's exactly 0 and 1 -- and the seeming fact that you need square, rather than sine waves -- suggests that you're misusing a lock-in amplifier. You may want to start a different question along the lines of "Is a lock-in amplifier the correct approach?". Be prepared to share details of the actual system you're measuring. $\endgroup$
    – TimWescott
    Aug 19, 2023 at 14:47
  • $\begingroup$ I have posted a new question: dsp.stackexchange.com/questions/89087/… $\endgroup$
    – Teena
    Aug 19, 2023 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.