# How to implement an RF Mixer for chirp signal in python?

According to this link, all I need to do to mix two signals is to multiply them.

I have two chirp signals with same properties, one leading the other. If I multiply them to get the IF output, I don't get a constant frequency which is what I expect, I get double the frequency:

from scipy.signal import chirp, spectrogram
import matplotlib.pyplot as plt
import numpy as np
import math

def plot_spectrogram(title, w, fs):
ff, tt, Sxx = spectrogram(w, fs=fs)
plt.pcolormesh(tt, ff, Sxx, cmap='gray_r')
plt.title(title)
plt.xlabel('Second(s)')
plt.ylabel('Hz')
plt.grid()

fig, ax = plt.subplots()

T = 0.4
fs = 7200
t = np.arange(0, int(T*fs)) / fs
f0, f1 = 5, 120
sc = chirp(t, f0=f0, f1=f1, t1=T)
rc = chirp(t, f0=f0, f1=f1, t1=T, phi=90.)

plt.figure(1)
ax.plot(t, sc, 'blue', lw=1.25, label='sent')
ax.plot(t, rc, 'green', lw=1.25, label='recv')

plt.figure(2)
plot_spectrogram(f'Chirp mul, f(0)={f0}, f({T})={f1}', sc * rc, fs)

plt.show()


Wouldn't mixing them give you a sum and difference frequency and you have to lowpass filter to get the difference frequency only? Also your chirps are the same frequency, just out of phase? So the difference would be zero and the sum would be double.

So:

1. Actually create a chirp that is a different frequency from the original, not just out of phase.
2. After mixing, lowpass filter to keep only the difference frequency
• Isn't being out of phase enough? I'm trying to simulate a radar echo. Also can you show me how to do the low pass filter? Feb 19 at 21:27
• As it sounds like you are asking, to confirm yes indeed the product of two signals occupying specific frequencies (tones) would be the sum and the difference. We see this in the trigonometric product identities such as $\cos(\alpha)\cos(\beta) = \frac{1}{2}cos(\alpha+\beta) + \frac{1}{2}cos(\alpha-\beta)$ Since the frequencies are so far apart, the simplest filter (for someone less familiar with any filtering) is a moving average. The short-term average of the signal will reveal the difference signal. Feb 20 at 0:24

What you're seeing is correct. When mixing two chirps as you're doing, you will get a doubling of the frequency.

Consider two chirps with a bandwidth $$B$$ and pulse length $$\tau$$. We'll use the complex form to simplify the math

$$x_1(t) = e^{j{\pi}\frac{\beta}{\tau}t^2}$$ $$x_2(t) = e^{j({\pi}\frac{\beta}{\tau} + \phi)}$$

We introduced the arbitrary phase difference to be more general. Mixing this signals we get

$$s(t) = x_1(t)x_2(t) = e^{j{\pi}\frac{\beta}{\tau}t^2}e^{j({\pi}\frac{\beta}{\tau}t^2 + \phi)} = e^{j({\pi}\frac{2\beta}{\tau}t^2 + \phi)}$$

We see that the chirp rate is now $$2\beta/\tau$$, so the resulting chirp will will change frequency twice as fast, and have a phase offset of $$\phi$$.

Resolving the return using a FMCW radar is a different story. In order to simulate it, you must introduce the target's delay. The mixing process is very similar, but with a slight tweak.

Let the chirped signal we transmit be

$$s_{tx}(t) = e^{j\pi\frac{\beta}{\tau}t^2}$$

After reflecting from a target we receive the signal after some delay $$t_d$$, we have

$$s_{rx}(t) = e^{j\pi\frac{\beta}{\tau}(t - t_d)^2} = e^{j\pi\frac{\beta}{\tau}(t^2 - 2tt_d + t_d^2)}$$

After mixing $$s_{rx}(t)$$ with the complex conjugate of $$s_{tx}(t)$$, the higher order term containing $$e^{j\pi\frac{\beta}{\tau}t^2}$$ drops off and we're left with

$$x(t) = e^{j\pi\frac{\beta}{\tau}(-2tt_d + t_d^2)} = e^{-j\pi\frac{\beta}{\tau}2tt_d}\,e^{j\pi\frac{\beta}{\tau}t_d^2}$$

Equating terms this result is equivalent to

$$e^{j({2\pi}f_bt+ \phi)}$$

This is simply a sinusoid at the beat frequency $$f_b$$. We can ignore the $$\phi$$ term since it will have no effect on our ability to resolve the target's range. Equating the the phase functions

$$-\pi\frac{\beta}{\tau}2tt_d = 2{\pi}f_bt$$

So that then we have

$$f_b = -\frac{\beta}{\tau}t_d$$

Since we know our pulse travels at the speed of light $$c$$, we can rewrite the target's delay in terms of range $$R$$ and yield the mapping between target range and its beat frequency

$$t_d = \frac{2R}{c} => f_b = -\frac{2R\beta}{c\tau}$$

• @Envidia- When you use the complex form to simplify the math, don’t you lose the important point that the OP will see the sum and the difference (the difference is the signal of interest, the sum we filter out). If we were to use complex form (which we could also implement for this very purpose using Hilbert transforms ) then one of the two should be negated such that we only get the difference and no further filtering is needed) Feb 20 at 15:56
• @DanBoschen You're definitely right and I lost track of that fact. I also wanted to avoid putting too much into one post, but maybe this is one of those times where it would result in a much better answer. Once I have some time I'll augment this answer and introduce filtering of the unwanted signals. Feb 21 at 22:11
• @Envdia I think it's a great answer especially when you add that detail. Feb 21 at 22:13