2
$\begingroup$

I have a real audio signal $x[n]$, and I'd like to apply a frequency shift by $f$ and then envelope it by $\cos(\omega n + \phi)$.

If I wanted to do the frequency shift in the ideal sense, from posts here like this one, I think I'd first construct an analytic signal using the Hilbert transform of $x$,

$$x_\mathrm{a} \triangleq x[n] + j \hat{x}[n]$$

where $\hat{x}[n]$ is the Hilbert Transform of $x[n]$.

$$ \hat{x}[n] \triangleq \mathscr{H}\Big\{ x[n] \Big\} = (h*x)[n] $$

and

$$ h[n] = \begin{cases} \frac{\big(1 - (-1)^n\big)}{\pi n} \quad & n \ne 0 \\ \\ 0 & n = 0 \end{cases}$$

and then shift the frequency

$$\tilde{x}[n] = e^{-2\pi j n \frac{f}{f_{s}}} \left(x[n] + j \hat{x}[n]\right)$$

Right so far?

Now I have a complex audio signal, and so I'm not sure how to apply the envelope.

An envelope on a real signal would just be $\cos(\omega n + \phi) x[n]$. But since it's now complex, do I take the real part of $\tilde{x}[n]$ and then scale by $\cos(\omega n + \phi)$? Or do I need to stay in the complex domain and make the envelope analytic before applying it, and then I take the real part?

I'd guess the former.

But if it's the latter, or they end up being the same, I would be confused why an analytic signal for the envelope $\exp(j \omega n)$ just resembles another frequency shift, when I'm trying to apply an envelope not a frequency shift.

$\endgroup$
3
  • $\begingroup$ It would really help if you can describe in more detail what your application and goal is. For normal audio signals (like music or speech) this really doesn't make any sense at all, but maybe you have a very specific kind of audio signal you are working with $\endgroup$
    – Hilmar
    Nov 28, 2022 at 6:25
  • $\begingroup$ I'm trying to shift a signal down by, say, 10 Hz and then modulate its volume with a specific envelope. And specifically just trying to understand the ideal case for now instead of what's most efficient. $\endgroup$ Nov 29, 2022 at 3:52
  • $\begingroup$ I understand what you are trying to do but I don't understand why. Most audio signals will sound quite bad if you downshift them by 10 Hz (since that breaks the harmonics). Is this a communication application ? Are you trying to build a modem. $\endgroup$
    – Hilmar
    Nov 30, 2022 at 4:25

1 Answer 1

4
$\begingroup$

It kind of depends on why you're modulating with a cosine. What you're doing is the same shape as a frequency-shifter combined with a ring-modulator, so I'm going to write an answer assuming that's your goal.

The short answer is: you still want the real-valued cosine, and it doesn't matter whether you do the cosine-modulation or the complex-sinusoid-modulation first.

It does matter whether you modulate before or after the Hilbert filter, and that can affect what happens to low frequencies.

Details

Here's the spectrum of a real signal, which includes negative frequencies:

spectral energy of real signal, symmetric around f=0

An analytic/Hilbert filter (ideally infinite, approximated with finite FIR or IIR in practice) removes the negative frequencies:

spectral energy of a Hilbert-filtered signal, with no negative energy.

Modulating (multiplying) by a complex sinusoid shifts the spectrum upwards:

complex-modulated spectrum, shifted upwards in frequency, annotated with the spectrum of the modulator, which is a single spike.

I think the clearest way to think about this is with the convolution theorem: multiplying (modulating) in the time-domain convolves in the frequency-domain. A complex sinusoid's spectrum is an offset spike, so convolution just shifts everything to the right.

The spectrum of the cosine signal is similar, but you have two spikes (after all, a cosine can be expressed as the sum of two complex exponentials):

cosine spectrum (with two spikes symmetrical around f=0), and two modulated copies of the spectrum

The result of that is two copies of the spectrum which get added together. This gives the signature sound of a ring-modulator: every frequency peak in the input becomes doubled.

If you Hilbert-filtered this cosine, you'd lose that doubling and be left with a one-sided (Bode) frequency-shift.

Order of operations

It doesn't matter whether you modulate with the complex sinusoid or the cosine first. The end result is the same - you end up with two shifted copies of the spectrum (from the cosine) combined with a horizontal shift (from the frequency-shift):

spectrum of a complex-modulated cosine, which has two peaks (just like the real cosine) but not centred around f=0.

So actually, you could cut out the middle-man and (instead of using a cosine) modulate by these two complex sinusoids, and add together the results. This is equivalent, but you explicitly control the location of these spikes, instead of their centre & spacing.

However, it does matter whether you do these modulations before or after the Hilbert. It also makes a difference whether you're shifting up or down, in terms of whether you get any reflections or negative frequencies in your result:

2x2 grid, showing the spectrum when shifting up/down, and before/after the Hilbert.

Any negative frequencies here will be reflected back into positive frequencies when you take the real result. It's up to you to decide which of these look right.

If you're using "sum of two complex-modulated copies" (instead of the cosine-modulator) then you could even make different choices for both sides, depending whether they're up or down.

If you're modulating with a cosine and then a frequency-shift, there's an additional option of modulating right at the end (on the real output), or doing the cosine before the Hilbert and the complex-shift afterwards. The diagrams would get a bit cluttered so I've skipped them, but you should be able to figure out the results yourself.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.