Author: james

  • Pulse compression

    Active positioning systems such as sonar and radar can benefit from a process called pulse compression, increasing resolution and detectability. It effectively exploits knowledge of the transmitted waveform to more robustly extract a signal of interest from noisy data.

    Basic premise

    The fundamental idea of pulse compression is to pass the transmitted signal across the received signal and find when they closely match. This can be done with cross correlation of the complex transmit and receive signals and is shown below.

    Derivation

    A common transmit signal is a pulsed linear frequency modulation (LFM), also known as a chirp signal. This involves the baseband signal beginning the pulse at a frequency of 0, and linearly increasing the frequency while maintaining a continuous wave. It looks something like………..

    Applying the Hilbert transform to get into the complex domain allows this waveform to be expressed by the single phasor stx(t)s_{tx}\left(t\right),

    stx(t)=rect(tT2T)eikt2.s_{tx}\left(t\right) = \text{rect}\left(\frac{t-\frac{T}{2}}{T}\right) e^{ikt^2} \text{.}

    Here, kk is the chirp rate, describing how fast the frequency increases, and TT is the duration of the pulse. The rectangle function is equal to unity between t=0t=0 and t=Tt=T, but zero everywhere else.

    If an echo is received after a time dd with amplitude AA, the received waveform is given by the phasor srx(t)s_{rx}\left(t\right),

    srx(t)=Astx(td)=Arect(tdT2T)eik(td)2.s_{rx}\left(t\right) = As_{tx}\left(t-d\right) = A\text{rect}\left(\frac{t-d-\frac{T}{2}}{T}\right)e^{ik\left(t-d\right)^2} \text{.}

    The rectangle function here is unity between dd and d+Td+T but zero elsewhere.

    Cross correlation

    To compute the cross correlation, the resulting waveform r(t)r\left(t\right) is described by

    r(t)=stx(τt)srx(τ) dτ.r\left(t\right) = \int_{-\infty}^\infty \overline{s_{tx}\left(\tau-t\right)}s_{rx}\left(\tau\right)\ d\tau \text{.}

    Substituting the transmit and receive waveforms gives

    r(t)=rect(τtT2T)eik(τt)2Arect(τdT2T)eik(τd)2 dτ,r\left(t\right) = \int_{-\infty}^\infty \text{rect}\left(\frac{\tau-t-\frac{T}{2}}{T}\right) e^{-ik\left(\tau-t\right)^2} A\text{rect}\left(\frac{\tau-d-\frac{T}{2}}{T}\right)e^{ik\left(\tau-d\right)^2}\ d\tau \text{,}

    where the conjugate operator has inverted the sign on the first exponential.

    Since tt is seen only in the first rectangle and exponential function, varying tt varies the position of the first rectangle and not the second. Thus, values of tt which have no rectangle function overlap lead to the integrand being zero, as at least one of the rectangle functions is zero for all τ\tau.

    However, values of tt with rectangle overlap generally exist for the scenarios we are interested in. In these cases, the rectangles overlap, with the intersection being the interval (max(t,d),min(t,d)+T)\left( \text{max}\left(t, d\right), \text{min}\left(t,d\right)+T \right), with the conditions that t+Tdt+T \geq d and d+Ttd+T \geq t. Since the integrand is zero outside this interval, the bounds can be shrunk from ±\pm \infty to the interval. Furthermore, since inside the interval, both rectangle functions are equal to unity, they can be removed. Thus, we obtain

    r(t)=max(t,d)min(t,d)+TAeik(τt)2eik(τd)2 dτ.r\left(t\right) = \int_{\text{max}\left(t,d\right)}^{\text{min}\left(t,d\right)+T} Ae^{-ik\left(\tau-t\right)^2} e^{ik\left(\tau-d\right)^2}\ d\tau \text{.}

    Expanding the quadratic terms in the exponentials and employing exponential laws yields

    r(t)=Amax(t,d)min(t,d)+Teik(t2d2)e2ik(td)τ dτ.r\left(t\right) = A\int_{\text{max}\left(t,d\right)}^{\text{min}\left(t,d\right)+T} e^{-ik\left(t^2-d^2\right)} e^{2ik\left(t-d\right)\tau}\ d\tau \text{.}

    The first exponential is constant with respect to the integral variable τ\tau, leading to pretty simple integration:

    r(t)=Ak(td)12i[eik(t2d2)e2ik(td)τ]max(t,d)min(t,d)+T.r\left(t\right) = \frac{A}{k\left(t-d\right)} \frac{1}{2i}\left[ e^{-ik\left(t^2-d^2\right)} e^{2ik\left(t-d\right)\tau} \right]_{\text{max}\left(t,d\right)}^{\text{min}\left(t,d\right)+T} \text{.}

    Implementing the integral limits gives

    r(t)=Ak(td)12i[eik(t2d2)e2ik(td)(min(t,d)+T)eik(t2d2)e2ik(td)max(t,d)].r\left(t\right) = \frac{A}{k\left(t-d\right)} \frac{1}{2i}\left[ e^{-ik\left(t^2-d^2\right)} e^{2ik\left(t-d\right)\left(\text{min}\left(t,d\right)+T\right)} – e^{-ik\left(t^2-d^2\right)} e^{2ik\left(t-d\right)\text{max}\left(t,d\right)}\right]\text{.}

    Combining the exponential term pairs by summing the exponents leads to

    r(t)=Ak(td)12i[e2ik(td)(min(t,d)+T)ik(td)(t+d)e2ik(td)max(t,d)ik(td)(t+d)].r\left(t\right) = \frac{A}{k\left(t-d\right)} \frac{1}{2i}\left[ e^{2ik\left(t-d\right)\left(\text{min}\left(t,d\right)+T\right)-ik\left(t-d\right)\left(t+d\right)} – e^{2ik\left(t-d\right)\text{max}\left(t,d\right)-ik\left(t-d\right)\left(t+d\right)}\right]\text{.}

    Now taking the common factor of (td)\left(t-d\right) out of the exponents gives

    r(t)=Ak(td)12i[eik(td)(2min(t,d)+2Ttd)eik(td)(t+d2max(t,d))].r\left(t\right) = \frac{A}{k\left(t-d\right)} \frac{1}{2i}\left[ e^{ik\left(t-d\right)\left(2\text{min}\left(t,d\right)+2T-t-d\right)} – e^{-ik\left(t-d\right)\left(t+d-2\text{max}\left(t,d\right)\right)}\right]\text{.}

    Here we do something a little strange: We multiply the entire expression by eik(td)Teik(td)Te^{ik\left(t-d\right)T} e^{-ik\left(t-d\right)T}, which is equal to unity. Multiplying the second exponential inside the square brackets and applying exponential laws gives

    r(t)=Aeik(td)Tk(td)12i[eik(td)(2min(t,d)+2Ttd)ik(td)Teik(td)(t+d2max(t,d))ik(td)T].r\left(t\right) = \frac{Ae^{ ik\left(t-d\right)T}}{k\left(t-d\right)} \frac{1}{2i}\left[ e^{ik\left(t-d\right)\left(2\text{min}\left(t,d\right)+2T-t-d\right) – ik\left(t-d\right)T} – e^{-ik\left(t-d\right)\left(t+d-2\text{max}\left(t,d\right)\right) – ik\left(t-d\right)T}\right]\text{.}

    Further simplifying,

    r(t)=Aeik(td)Tk(td)12i[eik(td)(2min(t,d)+Ttd)eik(td)(t+d+T2max(t,d))].r\left(t\right) = \frac{Ae^{ ik\left(t-d\right)T}}{k\left(t-d\right)} \frac{1}{2i}\left[ e^{ik\left(t-d\right)\left(2\text{min}\left(t,d\right)+T-t-d\right)} – e^{-ik\left(t-d\right)\left(t+d+T-2\text{max}\left(t,d\right)\right)}\right]\text{.}

    Now we consider the minimum and maximum functions. If t>dt > d, then we have 2min(t,d)+Ttd=dt+T2\text{min}\left(t,d\right)+T-t-d = d-t+T and t+d+T2max(t,d)=dt+Tt+d+T-2\text{max}\left(t,d\right) = d-t+T. In contrast, if d>td>t, we have 2min(t,d)+Ttd=td+T2\text{min}\left(t,d\right)+T-t-d = t-d+T and t+d+T2max(t,d)=td+Tt+d+T-2\text{max}\left(t,d\right) = t-d+T. In other words, if t>dt>d, both expressions become dt+Td-t+T, but if d>td>t, both expressions become td+Tt-d+T. This can be simplified quite nicely by replacing all expressions with T|td|T-\left|t-d\right|. Therefore, we can replace the nasty expression in both exponentials with a much nicer one:

    r(t)=Aeik(td)Tk(td)[eik(td)(T|td|)eik(td)(T|td|)2i].r\left(t\right) = \frac{Ae^{ ik\left(t-d\right)T}}{k\left(t-d\right)} \left[ \frac{e^{ik\left(t-d\right)\left(T-\left|t-d\right|\right)} – e^{-ik\left(t-d\right)\left(T-\left|t-d\right|\right)}}{2i}\right]\text{.}

    Notice both exponentials have the same argument, but with the second one being negative. With the division by 2i2i, this is equivalent to a sine expression, and can be rewritten as

    r(t)=Aeik(td)Tk(td)sin(k(td)(T|td|)).r\left(t\right) = \frac{Ae^{ ik\left(t-d\right)T}}{k\left(t-d\right)} \sin \left(k\left(t-d\right)\left(T-\left|t-d\right|\right)\right) \text{.}

    This is looking pretty nice, but we can still do better. Notice that the denominator is the same as the first part of the sine argument. We now multiply numerator and denominator by the rest of the sine argument:

    r(t)=A(T|td|)eik(td)Tk(td)(T|td|)sin(k(td)(T|td|)).r\left(t\right) = \frac{A\left(T-\left|t-d\right|\right)e^{ ik\left(t-d\right)T}}{k\left(t-d\right)\left(T-\left|t-d\right|\right)} \sin \left(k\left(t-d\right)\left(T-\left|t-d\right|\right)\right) \text{.}

    We now have something of the form

    r(t)=Csinxx,r\left(t\right) = C \frac{\sin x}{x} \text{,}

    and can convert the sinusoid to a sinc function, giving the final expression for the derivation,

    r(t)=A(T|td|)eik(td)Tsinc(k(td)(T|td|)).r\left(t\right) = A\left(T-\left|t-d\right|\right)e^{ik\left(t-d\right)T} \text{sinc}\left(k\left(t-d\right)\left(T-\left|t-d\right|\right)\right) \text{.}

  • The magic of public key cryptography

    I find public key cryptography fascinating. It’s stunningly simple but incredibly secure against current compute technology.

    Basic idea

    The fundamental concept of public key cryptography is based on a few (usually very large) numbers. A public key is simply one of these numbers; a private key is another. However, the main difference is that the private key is kept secret, whereas the public key is distributed to anyone.

    The public key can be used to encrypt data, which can then be securely transmitted to someone. In my eyes, the interesting part is that once encrypted, most of the encrypted data is discarded before being transmitted; this is why reversing the encryption algorithm isn’t possible. Even if an eavesdropper captures the transmitted data, it’s not feasible to decrypt. Upon receipt of the encrypted data, the intended recipient can use the private key to decrypt and read the data.

    A simple example

    While computers use extremely large numbers for encryption, a basic example can be shown with small (human-understandable) numbers. This will use RSA encryption with a public key of 11 and a private key of 7 under modulo/base 10. These numbers have certain relations to one another and are computed in a certain way, but we won’t go over that here. Note again that the private key is known only to the recipient of the data.

    Encryption

    Let’s say you want to transmit a single number (0-9) to me. You choose a number, say, 8, and encrypt it using the following equation.

    Encrypted data=Plaintext datapublic key(mod (base))\text{Encrypted data} = \text{Plaintext data}^\text{public key} \text{(mod (base))}

    While that looks a little complicated, it’s rather simple. We take the plaintext data (8), raise it to the power of the public key (11), then take the modulo with the base (10). The module operation simply means we divide by the base, then take the remainder. Therefore,

    Encrypted data=811(mod 10)=8,589,934,592(mod 10)=2\text{Encrypted data} = 8^{11} \text{(mod 10)} = 8,589,934,592 \text{(mod 10)} = 2

    Therefore, the encrypted data is simply the number 2. Again, what makes this interesting is that we have discarded 8,589,934,590, meaning the exponentiation is not feasible to reverse.

    Decryption

    Once I received your message of 2, I can decrypt it with the private key. All I need to do is run the same operation you did, but with the private key instead:

    Decrypted data=27(mod 10)=128(mod 10)=8\text{Decrypted data} = 2^7 \text{(mod 10)} = 128 \text{(mod 10)} = 8

    We can see we’ve obtained the original data. One thing that makes this algorithm even better is that the mathematical operations are computationally cheap and very simple to implement. The difficulty comes with finding pairs of public and private keys, but the actual encryption and decryption are very easy to compute. Additionally, for many applications, the keys only need to be computed once and can be used many times.

    Eavesdropping

    A bad actor could fairly easily intercept your message of 2. However, they are unable to work out what the original data was without trial-and-erroring a bunch of options. This example is just using the digits 0-9, so this brute force approach is pretty simple: The eavesdropper can simply run the (public) encryption algorithm on every digit and find out which one results in 2.

    That being said, modern encryption algorithms use ridiculously large numbers (for human brains), and trial-and-error is basically impossible. With modern algorithms, it’s generally thought that brute forcing a decryption would take billions of years or more, and therefore they are considered safe.

    I will note here that with the early signs of quantum computing, it is possible these algorithms may be brute forced more easily in the future, but many smart people are working on this and finding solutions. Additionally, quantum computers are very much not ready for any task, so most people need not worry about it right now.

    Cryptographic signing

    Another application of this idea is digital signing to cryptographically “prove” someone has signed a document. Put simply, I could come up with a pair of keys and distribute the public key while keeping the private key secret. To digitally sign something, I could encrypt a message of something like “I am the real James and the 2026 rental contract was signed on Jan 3, 2026”. Once encrypted, I could attach the encrypted message to the document.

    The document with the encrypted message could be distributed along with the public key (which is known to come from me). Any recipient could easily run the encryption algorithm with the public key on the encrypted message, and would obtain the original message stating “I am the real James…”, indicating I have cryptographically signed it.

    Of course, there is more to this algorithm to increase its security, but the basic idea is nice and simple. A bad actor (without access to the private key) cannot come up with encrypted data that would lead to the same message, so it’s secure and reliable.

    Conclusion

    Public key cryptography has been around for decades and will likely be around for many more due to its combination of security and simplicity. There have been updates to the algorithms over the years, but they are usually related to the length of the keys; the process remains the same. Public key cryptography is a wonderful mathematical tool giving robust security and allowing the modern internet to exist.