Electronic – Emulate the effect of a lock-in amplifier on a signal with a programming script

amplifiersignalsignal processing

I'm working on a gas emission sensing project in the lab which requires the extraction of a signal in a really noisy environment. The features of interests of my signal are much smaller than the noise components. Literature shows experimental setups for similar purposes using lock-in amplifiers to extract the signal. I have never heard of lock-in amplifiers before and my electronics skills are fairly limited. After a quick search on the Internet, I have realized that lock-in amplifiers might be too bulky for my experimental setup and I was wondering if I could emulate the effect of such amplifiers with a programming script.

Let's say I have a noisy sin signal with know parameters:

  • Amplitude: 1 V
  • Offset: 3 V
  • Frequency: 4 Hz
  • For this example, noise is generated in the script

raw_signal

Based on what I have read about lock-in amplifiers, I would first have to multiply it by a reference signal of the same frequency to eliminate the effect of everything at a frequency other than 4 Hz. Let's say I take a sin wave, with an amplitude of 1V and a frequency of 4 Hz. The result is the following signal:

multiplied_signal

The average of the signal array would be 0.5; this value might change slightly depending on the noise. Now if I give any frequency other than 4 Hz to my reference signal, this average would be around 0 which seems to validate the theory.

Then, based on my understanding, the signal would go through a low-pass filter. I have programmed a butterworth filter of 6th order, with a sample rate of 30 Hz and a cutoff frequency of 3 Hz. Please note that I am not sure on how these numbers should be changed based on what I am trying to accomplish.

The resulting signal after the filter looks like this:
enter image description here

Does this make any sense at all in terms of emulating the effect of a lock-in?

Another question I have is with regards to my feature of interests. Let's say the features of interest I am looking to extract, in a perfectly clean signal would look something like this:

feature of interest

Now let's say this signal is completely buried in noise. What would be the best way to extract it and have it as clean as possible? Would a lock-in amplifier do the job?

Best Answer

First, as Dave Tweed has answered, you generally use a lock-in to recover a small signal buried in noise.

That said, your script is not properly implementing a lock-in amplifier, as evidenced by your second trace. Your problem is that the DC component of your original signal needs to be suppressed (the signal should be AC-coupled). If your reference sine wave has a DC component of zero (which it should) then for a signal with zero degrees of phase shift and an average of zero, the output will be a sine-squared wave (plus noise). Note that this will be rectified, with no signal component negative.This will allow a low-pass filter to recover the amplitude of the desired frequency, but not its shape.

What you seem to be trying to do is simple noise rejection, and there are two possibilities. Either your noise is broadband, with significant noise energy both above and below your frequency of interest, or the noise is only significant above your fundamental.

Assuming the latter, you can process your signal using only a high-pass filter, made arbitrarily sharp and close to your fundamental. If the former, you need a bandpass filter.

In either case, looking at the crossover distortion shown in the last figure is going to be very, very difficult. That's a low-energy, high-frequency artifact, and may not be easily recovered from the noise. If you really want to try, the first thing you need to do is simulate your signal, then perform an FFT on it to establish the frequency response your filter needs in order not to exclude the signal of interest. Then compare this to the noise spectrum and you'll probably see that they overlap.

Other than an extremely large averaging filter (many, many waveforms averaged), I don't see any good way to recover your feature of interest.

EDIT - Having stated that a signal in noise needs a bandpass filter to recover it, I should explain that the multiplier used acts as what is called "mixer" in the RF world, and its effect is to frequency shift the signal by the reference frequency. This is useful in the case of the lock-in amplifier because it shifts the signal frequency to DC. In this case, a bandpass filter on the original signal becomes a low-pass filter on the processed signal, and the trick of the lock-in is that it's MUCH easier to make a very sharp, narrow lowpass filter than it is a very sharp, narrow bandpass filter. To begin with, the lowpass filter response is intrinsically referenced to DC, or zero Hz. This means that there is no central frequency of the filter to drift with time and temperature, which is a major problem with bandpass filters.

On the other hand, since the desired signal is now DC, you cannot recover the signal shape. Every deviation from the fundamental frequency (sine wave) shows up as a frequency deviation in the processed signal. If the artifact of interest is part of the signal at the base frequency, the frequency deviations show up as harmonics, and the closest to the fundamental is at twice the fundamental. This means that any close filtering will eliminate the part of the signal which corresponds to the glitch.