# Lock-in Amplifier: How to improve the output of lock in amplifier?

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.

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)
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:

X (In-Phase Component): 0.420861516374354

R (Magnitude): 0.4845896248161778

• 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. Commented Aug 18, 2023 at 16:35
• @TimWescott I am using a square reference signal. I have edited the post and added all the required plots. Commented Aug 18, 2023 at 18:05

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}