# Reflecting negative frequency to positive frequency

Started by April 11, 2015
```I am trying to sample the magnitudes of a shifted window in the
frequency domain. But I wonder what to do when a part of the window sits
in the negative frequency.

Here is an example: if the window (ps. a real symmetrical, ie. H[-k] =
H[k]) is centered at 80 Hz, and the sampling interval (the interval
between two bins) is 43 Hz. These are the bins around the center of the
window to be sampled:

bin[center] : 86 Hz
bin[center - 1]: 43 Hz
bin[center - 2]: 0 Hz
bin[center - 3]: -43 Hz

bin[center + 1]: 129 Hz
bin[center + 2]: 172 Hz
bin[center + 3]: 215 Hz

The bin[center -3], sits in the negative frequency. I read somewhere
saying that the magnitude at bin[center -3] should be added to
bin[center + 3] after a complex conjugation. As the complex conjugation
is just flipping the sign of the imaginary part, I figure it would just
mean to add the real part of the magnitude of the window at bin[center
+3] twice. However with this approach I got a very distorted signal.
What am I doing wrong? Any advices would be very appreciated!

Cheers,
mf
---------------------------------------
Posted through http://www.DSPRelated.com
```
```On Sat, 11 Apr 2015 05:49:06 -0500, mfl wrote:

> I am trying to sample the magnitudes of a shifted window in the
> frequency domain. But I wonder what to do when a part of the window sits
> in the negative frequency.
>
> Here is an example: if the window (ps. a real symmetrical, ie. H[-k] =
> H[k]) is centered at 80 Hz, and the sampling interval (the interval
> between two bins) is 43 Hz. These are the bins around the center of the
> window to be sampled:
>
> bin[center] : 86 Hz bin[center - 1]: 43 Hz bin[center - 2]: 0 Hz
> bin[center - 3]: -43 Hz
>
> bin[center + 1]: 129 Hz bin[center + 2]: 172 Hz bin[center + 3]: 215 Hz
>
> The bin[center -3], sits in the negative frequency. I read somewhere
> saying that the magnitude at bin[center -3] should be added to
> bin[center + 3] after a complex conjugation. As the complex conjugation
> is just flipping the sign of the imaginary part, I figure it would just
> mean to add the real part of the magnitude of the window at bin[center
> +3] twice. However with this approach I got a very distorted signal.
> What am I doing wrong? Any advices would be very appreciated!

What are you really trying to do?  It doesn't seem that you have enough
frequency resolution in your FFT to usefully do what you're trying.

So -- are you trying to filter data and put it back into the time
domain?  Are you trying to analyze the spectral magnitude of the data?
What?

--
www.wescottdesign.com
```
```>On Sat, 11 Apr 2015 05:49:06 -0500, mfl wrote:
>
>> I am trying to sample the magnitudes of a shifted window in the
>> frequency domain. But I wonder what to do when a part of the window
sits
>> in the negative frequency.
>>
>> Here is an example: if the window (ps. a real symmetrical, ie. H[-k]
> H[k]) is centered at 80 Hz, and the sampling interval (the interval
>> between two bins) is 43 Hz. These are the bins around the center of
the
>> window to be sampled:
>>
>> bin[center] : 86 Hz bin[center - 1]: 43 Hz bin[center - 2]: 0 Hz
>> bin[center - 3]: -43 Hz
>>
>> bin[center + 1]: 129 Hz bin[center + 2]: 172 Hz bin[center + 3]: 215
Hz
>>
>> The bin[center -3], sits in the negative frequency. I read somewhere
>> saying that the magnitude at bin[center -3] should be added to
>> bin[center + 3] after a complex conjugation. As the complex
conjugation
>> is just flipping the sign of the imaginary part, I figure it would
just
>> mean to add the real part of the magnitude of the window at
bin[center
>> +3] twice. However with this approach I got a very distorted signal.
>> What am I doing wrong? Any advices would be very appreciated!
>
>What are you really trying to do?  It doesn't seem that you have enough

>frequency resolution in your FFT to usefully do what you're trying.
>
>So -- are you trying to filter data and put it back into the time
>domain?  Are you trying to analyze the spectral magnitude of the data?

>What?
>
>--
>www.wescottdesign.com

Hi Tim,

the FFT size to 2048 then I won&rsquo;t run into this problem when sampling
80 Hz. However, I would like to stick to 1024 for some reasons (ex. I
can have finer frequency modulations over fft frames, etc)

I am trying to synthesize sine waves using a window function as a
&ldquo;spectral motif&rdquo;. For example, in order to generate a sine wave at
frequency 440 Hz, I&rsquo;ll center a window (ex. blackman or chebyshev) at
440 Hz in the frequency domain, and sample a few bins around its main
lobe and possibly also the first side lobe to represent the sine wave.

There are a few different variations on implementing this, but you can
read about how to handle negative frequencies on Eq. 10 here: (it&rsquo;s
near the end of the page, just search for reflection on the page if you
are curious). However I can't get it work properly, so wonder if
something wrong with the equation.

But from your perspective, does it sound weird to handle negative
frequency in this situation?

Cheers,
MF
---------------------------------------
Posted through http://www.DSPRelated.com
```
```On Sat, 11 Apr 2015 12:23:46 -0500, mfl wrote:

>>On Sat, 11 Apr 2015 05:49:06 -0500, mfl wrote:
>>
>>> I am trying to sample the magnitudes of a shifted window in the
>>> frequency domain. But I wonder what to do when a part of the window
> sits
>>> in the negative frequency.
>>>
>>> Here is an example: if the window (ps. a real symmetrical, ie. H[-k]
>> H[k]) is centered at 80 Hz, and the sampling interval (the interval
>>> between two bins) is 43 Hz. These are the bins around the center of
> the
>>> window to be sampled:
>>>
>>> bin[center] : 86 Hz bin[center - 1]: 43 Hz bin[center - 2]: 0 Hz
>>> bin[center - 3]: -43 Hz
>>>
>>> bin[center + 1]: 129 Hz bin[center + 2]: 172 Hz bin[center + 3]: 215
> Hz
>>>
>>> The bin[center -3], sits in the negative frequency. I read somewhere
>>> saying that the magnitude at bin[center -3] should be added to
>>> bin[center + 3] after a complex conjugation. As the complex
> conjugation
>>> is just flipping the sign of the imaginary part, I figure it would
> just
>>> mean to add the real part of the magnitude of the window at
> bin[center
>>> +3] twice. However with this approach I got a very distorted signal.
>>> What am I doing wrong? Any advices would be very appreciated!
>>
>>What are you really trying to do?  It doesn't seem that you have enough
>
>>frequency resolution in your FFT to usefully do what you're trying.
>>
>>So -- are you trying to filter data and put it back into the time
>>domain?  Are you trying to analyze the spectral magnitude of the data?
>
>>What?
>>
>>--
>>www.wescottdesign.com
>
> Hi Tim,
>
> the FFT size to 2048 then I won&rsquo;t run into this problem when sampling 80
> Hz. However, I would like to stick to 1024 for some reasons (ex. I can
> have finer frequency modulations over fft frames, etc)
>
> I am trying to synthesize sine waves using a window function as a
> &ldquo;spectral motif&rdquo;. For example, in order to generate a sine wave at
> frequency 440 Hz, I&rsquo;ll center a window (ex. blackman or chebyshev) at
> 440 Hz in the frequency domain, and sample a few bins around its main
> lobe and possibly also the first side lobe to represent the sine wave.
>
> There are a few different variations on implementing this, but you can
> read about how to handle negative frequencies on Eq. 10 here: (it&rsquo;s near
> the end of the page, just search for reflection on the page if you are
> curious). However I can't get it work properly, so wonder if something
> wrong with the equation.
>
> But from your perspective, does it sound weird to handle negative
> frequency in this situation?

I'm not up to reading that whole thing, so hopefully someone who's more
into audio will respond.

The short story that I can give is that if you're doing an FFT of
something real, then the FFT will have positive and negative parts that
are complex conjugates of each other (i.e., X[-k] = X[k]).  If you want
to filter something by taking it's FFT, multiplying it by some vector in
the frequency domain, and then transforming it back, then to keep the
output real and not complex your vector by which you multiply needs to
have the same property: A[-k] = A[k]*.

I would suggest that you re-read the paper, with greater care, and see if
what they're suggesting makes sense in light of the property of FFT's
that I mention above.

--
www.wescottdesign.com
```
```On 4/11/15 2:32 PM, Tim Wescott wrote:
> On Sat, 11 Apr 2015 12:23:46 -0500, mfl wrote:
>
>>> On Sat, 11 Apr 2015 05:49:06 -0500, mfl wrote:
>>>
>>>> I am trying to sample the magnitudes of a shifted window in the
>>>> frequency domain. But I wonder what to do when a part of the window
>> sits
>>>> in the negative frequency.
>>>>
>>>> Here is an example: if the window (ps. a real symmetrical, ie. H[-k]
>>> H[k]) is centered at 80 Hz, and the sampling interval (the interval
>>>> between two bins) is 43 Hz. These are the bins around the center of
>> the
>>>> window to be sampled:
>>>>
>>>> bin[center] : 86 Hz bin[center - 1]: 43 Hz bin[center - 2]: 0 Hz
>>>> bin[center - 3]: -43 Hz
>>>>
>>>> bin[center + 1]: 129 Hz bin[center + 2]: 172 Hz bin[center + 3]: 215
>> Hz
>>>>
>>>> The bin[center -3], sits in the negative frequency. I read somewhere
>>>> saying that the magnitude at bin[center -3] should be added to
>>>> bin[center + 3] after a complex conjugation. As the complex
>> conjugation
>>>> is just flipping the sign of the imaginary part, I figure it would
>> just
>>>> mean to add the real part of the magnitude of the window at
>> bin[center
>>>> +3] twice. However with this approach I got a very distorted signal.
>>>> What am I doing wrong? Any advices would be very appreciated!
>>>
>>> What are you really trying to do?  It doesn't seem that you have enough
>>
>>> frequency resolution in your FFT to usefully do what you're trying.
>>>
>>> So -- are you trying to filter data and put it back into the time
>>> domain?  Are you trying to analyze the spectral magnitude of the data?
>>
>>> What?
>>>
>>> --
>>> www.wescottdesign.com
>>
>> Hi Tim,
>>
>> the FFT size to 2048 then I won&rsquo;t run into this problem when sampling 80
>> Hz. However, I would like to stick to 1024 for some reasons (ex. I can
>> have finer frequency modulations over fft frames, etc)
>>
>> I am trying to synthesize sine waves using a window function as a
>> &ldquo;spectral motif&rdquo;. For example, in order to generate a sine wave at
>> frequency 440 Hz, I&rsquo;ll center a window (ex. blackman or chebyshev) at
>> 440 Hz in the frequency domain, and sample a few bins around its main
>> lobe and possibly also the first side lobe to represent the sine wave.
>>
>> There are a few different variations on implementing this, but you can
>> read about how to handle negative frequencies on Eq. 10 here: (it&rsquo;s near
>> the end of the page, just search for reflection on the page if you are
>> curious). However I can't get it work properly, so wonder if something
>> wrong with the equation.
>>
>> But from your perspective, does it sound weird to handle negative
>> frequency in this situation?
>
> I'm not up to reading that whole thing, so hopefully someone who's more
> into audio will respond.
>
> The short story that I can give is that if you're doing an FFT of
> something real, then the FFT will have positive and negative parts that
> are complex conjugates of each other (i.e., X[-k] = X[k]).  If you want
> to filter something by taking it's FFT, multiplying it by some vector in
> the frequency domain, and then transforming it back, then to keep the
> output real and not complex your vector by which you multiply needs to
> have the same property: A[-k] = A[k]*.
>

it's an interesting patent from Jean Laroche, someone i have a lotta
respect for.  it looks alot like the phase-vocoder stuff that he was
presenting (like at Mohonk) and publishing back in them days (ca. 2000).

i would say this, try looking at the DFT (or "FFT" if you like) of a
windowed sinusoid of some known frequency.  unless you use a Gaussian
window or the like, you will get more than just a main lobe to worry
about.  if you're trying to synthesize a chirp-like sinusoid (one where
the frequency doesn't change *all* that fast), with a Gaussian window,
the math for that is laborious, but straight forward.  (Gaussains and
chirps in the time domain look like similar functions in the frequency
domain.)  back in my more productive days, i did a paper in 2001 about
that (maybe even referenced Jean in it) that you can get at

https://www.researchgate.net/publication/3927319_Intraframe_time-scaling_of_nonstationary_sinusoids_within_the_phase_vocoder

when you FFT back to time-domain, your sinusoid will have a Gaussian
window centered with the frame, but you can change that to a

but just do it all in positive frequency, as if negative frequency does
not exist.  when you have your frame's spectrum completely specified
(for positive frequency), then reflect it to negative frequency (complex
conjugate when reflecting it) and translate that to the latter half of
the inverse FFT buffer.  after the iFFT, divide by the Gaussian window
and multiply by a Hann window (which is complementary with the Hann
window of the previous frame) and overlap-add.

--

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."

```
```>it's an interesting patent from Jean Laroche, someone i have a lotta
>respect for.  it looks alot like the phase-vocoder stuff that he was
>presenting (like at Mohonk) and publishing back in them days (ca.
>2000).
>
>i would say this, try looking at the DFT (or "FFT" if you like) of a
>windowed sinusoid of some known frequency.  unless you use a Gaussian
>window or the like, you will get more than just a main lobe to worry
>about.  if you're trying to synthesize a chirp-like sinusoid (one where
>
>the frequency doesn't change *all* that fast), with a Gaussian window,
>the math for that is laborious, but straight forward.  (Gaussains and
>chirps in the time domain look like similar functions in the frequency
>domain.)  back in my more productive days, i did a paper in 2001 about
>that (maybe even referenced Jean in it) that you can get at
>
>
>https://www.researchgate.net/publication/3927319_Intraframe_time-scaling_of_nonstationary_sinusoids_within_the_phase_vocoder
>
>
>
>
>when you FFT back to time-domain, your sinusoid will have a Gaussian
>window centered with the frame, but you can change that to a
>
>but just do it all in positive frequency, as if negative frequency does
>
>not exist.  when you have your frame's spectrum completely specified
>(for positive frequency), then reflect it to negative frequency (complex
>
>conjugate when reflecting it) and translate that to the latter half of
>the inverse FFT buffer.  after the iFFT, divide by the Gaussian window
>and multiply by a Hann window (which is complementary with the Hann
>window of the previous frame) and overlap-add.
>
>
>--
>
>r b-j                  rbj@audioimagination.com
>
>"Imagination is more important than knowledge."

Hi Robert,

am just starting to learn DSP, it&rsquo;ll be a long journey for me to get a
grasp of the whole mathematics behind it :)

I&rsquo;ve done something pretty similar to what you suggested, just without
the complex conjugate for the negative frequency part. I got pretty clean
signal with it. However, to synthesize low frequencies is still an issue.
With complex conjugate you suggested, the sound has improved quite a bit
but there is still audible noise. I wonder if it&rsquo;s because of the
missing data in the negative frequency side. To elaborate what I mean,
I&rsquo;ve put some screen shots of the spectral motif for 80 Hz with frame
size 1024 and 2048 here.

When using frame size 2048, I&rsquo;ll be able to generate a complete spectral
motif, and the signal also comes out pretty clean. But with DFT size of
1024 there is audible noise all over the place around 100 to 10K Hz.
I&rsquo;ve also tried with higher oversample factor for the window function,
but didn&rsquo;t help. Any suggestions on where to trouble shoot the noise
issue?

Thanks!
MF
---------------------------------------
Posted through http://www.DSPRelated.com
```
```So I think I found a way to improve the problem. If the window function
has very thin main lobe width and low side lobe level, it&rsquo;s more likely
to have a complete representation for low frequency signal. For example,
chebyshev works better than blackman window (which I used before). Will
keep testing with other variations.

Cheers,
mf
---------------------------------------
Posted through http://www.DSPRelated.com
```