How to verify if my cross-correlation algorithm works?

So I have a signal generator which can produce two separate signals.

I use a spectrum analyzer to read these signals, and can interface with Python.

I wrote a Python code which takes in these two signals, perform the FFT of both, take the complex conjugate of one of them, and multiply together which gives me the cross-correlated frequency spectrum?

My problem is, I want some validity checks to see if this works or not. The main objective is noise floor reduction, but I am not sure how much the noise should drop by, etc. This signal generator is connected to the spectrum analyzer using BNC coaxial cables and that is it. I am sending in simple sinusoidal waves of frequency 2kHz.

There are two issues / concerns with this approach in that you may not be getting what you want. The primary one is the equivalent of post detection averaging by using the post-processed results from a spectrum analyzer, and the second is that the result of your complex conjugate multiplied FFT is actually in the time domain since you started in the frequency domain (so the FFT processing is actually converting to the the time domain where you perform the multiplication.-- I suspect but am not certain that your goal is to observe the frequency domain spectrum after cross-correlation of your signals?).

Most significantly, spectrum analyzers "detect" the signal in that the result is dB magnitude, and regardless of the dB conversion which could easily be undone, all phase information is lost such that any processing gain through coherent averaging can no longer be done. This is equivalent to the difference in adjusting the resolution bandwidth (RBW) versus the video bandwidth (VBW) of the spectrum analyzer . Since you are already using a spectrum analyzer, playing with those knobs will actually provide a great demonstration of pre-detection versus post-detection averaging, which will give you much further insight into what you are trying to accomplish. For that reason, I will first go into that in more detail of that, starting with a simple functionally equivalent block diagram of a spectrum analyzer:

In this simplified but functionally equivalent view of a spectrum analyzer an input signal (in this diagram a 70 MHz tone) is frequency translated by the voltage controlled oscillator (VCO) and mixer to be swept through the Bandpass Filter with resolution bandwidth RBW. It may be helpful to envision the sweep rate as being extremely slow in comparison to the inverse of the filter bandwidth, such that the operation for explanation here is similar to stepping the VCO through each frequency one at a time and statically processing each result (pixel on the display) before stepping to the next frequency. This will avoid us getting into constraints on the sweep rate which exist. Thus at any given moment, the power detector is converting the entire power that is within the bandwidth RBW to a power level. This power level passes through a low pass filter with bandwidth VBW, in converted to dB and then used to control the vertical position of the pixel on the screen representing the power level of our signal under test. Similarly the ramp rate controls the horizontal position representing the frequency at that moment in time.

By adjusting the bandwidth RBW we reduce the total power that would be presented to the power detector. If the signal is centered on our tone (in this case 70 MHz), the power of the tone would dominate and we would see no change in the power detector output regardless of the bandwidth of RBW, as long as the bandpass filter remained centered on our signal under test, and assuming the signal under test was a pure tone. In this case the apparent bandwidth of that signal, as displayed in the diagram above is actually the bandwidth of RBW shown as the single tone is swept through our filter during the horizontal trace. This would be very apparent by adjusting RBW and observing the result. More notably you would see the noise floor everywhere else go down at $$10Log(N)$$ where N is the decrease in RBW. (If you half RBW, the noise floor goes down by 3 dB). I believe this is a direct demonstration of the noise floor reduction you seek to that the extent correlation has mathematical similarity to averaging, as in this case you would observe that the signal level would remain unchanged. In this case, this is the result of "Pre-detection" averaging which is exactly what a bandpass filter is doing (with the averaging operation mathematically translated to the center frequency of the filter). In the plot shown in the figure above, the noise floor is approximately -90 dBm. Both the noise floor and the width of the tone suggest that the RBW is about 1 MHz, so I will assume that was the case. If we adjusted RBW to 500 KHz, we would see the noise floor drop to -93 dBm while the peak of the tone would remain unchanged.

Similarly if you adjust the bandwidth of the lowpass filter (VBW), you are simply smoothing (averaging) the noise power already measured but not decreasing it! In the plot above we would see the "noise on the noise" get smoother, but it will remain at the -90 dBm level. Thus we are simply averaging the result of the noise without reducing it.

To accomplish what you want, I would consider cross-correlating the signals directly in the time domain. The complex conjugate multiplication of the FFT of these time domain signals would then represent the spectrum of the cross correlation, if that is what was ultimately desired.

• Just your last paragraph: are you suggesting that I cross-correlate the two signals in the time domain first, before I FFT them and complex conjugate multiply them? – anony Feb 14 at 14:32
• My goal is to observe the frequency spectrum and how it changes. for eg. I am sending in a signal A with 2 kHz, and a signal B which is mixed at 2kHz and 3kHz. If I take the FFT of the time domain data of these two signals, complex conjugate multiply them, this should result in the spectrum after cross-correlation? So in this case, the 3 kHz is almost like it has been attenuated? – anony Feb 14 at 14:34
• Yes that is correct – Dan Boschen Feb 14 at 14:59
• But in your earlier comment- the result of doing a complex conjugate multiply of the FFT of each time domain signal IS the FFT of the (circular) cross correlationâ€” so you simply need to do that multiplication after taking the FFTâ€” the cross correlation is already done in that process – Dan Boschen Feb 14 at 15:01
• That I understand, so the result is the FFT of the cross correlation. This means, according to my second comment, the 3 kHz peak should not be visible? In my code, I still see peaks at 2kHz and 3kHz – anony Feb 14 at 15:26