# Reducing Spectral Leakage of Rectangular Window?

Started by April 17, 2012
```>On Thu, 19 Apr 2012 11:29:43 -0500, westocl wrote:
>
>>>On Wed, 18 Apr 2012 12:27:31 -0700, Fred Marshall wrote:
>>>
>>>> On 4/17/2012 3:34 PM, Tim Wescott wrote:
>>>>>> Everyone in agreance?
>>>>> Not me.  I think you'll always be able to make things look better on
>>>>> the surface, but I don't know if you'll be able to make them better
>> for
>>>>> real.
>>>>
>>>> Tim,
>>>>
>>>> As I understand the approach being discussed, it's not a generic
>>>> approach because it can't be.  So, better *is* "better for real".
But
>>>> maybe not "best" in even its own narrow context.
>>>>
>>>> The algorithm seems to be:
>>>>
>>>> 1) Grab more data than you need.
>>>>
>>>> 2) Truncate the data at some propitious point with the objective of
>>>> matching the values and perhaps the first derivative.  This implies a
>>>> reasonable degree of searching I should think.  Method to be used for
>>>> this remains unstated.
>>>>
>>>> If that's the case then it's data dependent and, thus, not generic.
>>>>
>>>> If that approach is used then the objective serves to avoid one sharp
>>>> discontinuity.
>>>>
>>>> If sharp discontinuities, even one, is avoided then a good deal of
>>>> spectral spreading / "new frequencies" / aliasing is eliminated over
>>>> having NOT done this.
>>>>
>>>> The model case is starting with a sinusoid of arbitrary frequency and
>>>> deciding to capture exactly an integer number of periods.  The result
>> is
>>>> that there will be *no* energy outside.  In this case the method
works
>>>> perfectly in meeting the one objective.
>>>>
>>>> I suppose one could do a study:
>>>> Perhaps add sin[Kt] to sin[(K/2 + 0.5)t] where K is an even integer
so
>>>> that now the best you can do is grab a waveform with a discontinuity.
>>>> The worst case one might imagine would be when there is exactly an
>>>> integer number of periods of sin(Kt) and exactly 1/2 period of the
>> other
>>>> at the end of its windows.  Indeed, that shows that all of the
>>>> spectral spreading is due to the latter and none due to the former.
>>>>
>>>> As the composite waveform becomes more complex, or indescribable
even,
>>>> then maybe the best you can do *in this context* is the proposed
>> method.
>>>> Again, some kind of study that measures leakage energy vs. arbitrary
>>>> window lengths might be interesting to provide a notion of "is this
>> sort
>>>> of optimum or not?"
>>>> But that doesn't mean that ordinary windowing might not be better.
>>>
>>>That's why I suggested that an FFT may not be the solution to the root
>>>problem.
>>>
>>>--
>>>My liberal friends think I'm a conservative kook. My conservative
>>>friends think I'm a liberal kook. Why am I not happy that they have
>>>found common ground?
>>>
>>>Tim Wescott, Communications, Control, Circuits & Software
>>>http://www.wescottdesign.com
>>>
>>>
>>
>>> Understood... So the general feel is that I can do atleast somewhat
>>> better by taking a DFT record length that looks to be visually
periodic
>>> instead of blindly taking a record length?
>>>
>>> Everyone in agreance?
>>
>> Not me.  I think you'll always be able to make things look better on
the
>> surface, but I don't know if you'll be able to make them better for
>> real.
>>
>> What are you really trying to find out from the data?  Maybe the FFT
>> isn't the best thing to use.
>>
>>
>>
>> I want an 'accurate' estimate the spectral phase of the signal (not to
>> get too much into it.. but thats what i want.) Delving into what is
>> meant by 'accurate' is a brand new can of worms id rather not open. ML
>> estimate, CLB, LS... dont want to open it.
>>
>> Wanting the spectral phase the reason i feel that i am forced out of
>> having windows as an option.  Some of the frequency components may be
>> weak, so leakage will just destroy the estimate even more so i was
>> trying to avoid it as much as i could with the liberty of being able to
>> choose the record lenghth... thats how the question came about.
>
>What do you mean by "spectral phase"???
>
>--
>Tim Wescott
>Control system and signal processing consulting
>www.wescottdesign.com
>

angle(FFT(x))

where x is some sequence
```
```On Fri, 20 Apr 2012 10:45:27 -0500, "westocl"
<cweston_@n_o_s_p_a_m.hotmail.com> wrote:

[Snipped by Lyons]
>
>angle(FFT(x))
>
>where x is some sequence

Hi westocl,
The phase values of FFT samples are
*VERY* susceptible to noise.  To measure
phase your FFT input signal must
have a pretty darned high signal-to-noise
ratio.

I'm wondering; is the signal, whose spectral
phase you're trying to measure, a narrowband
signal?  Is all it's spectral energy contained
in a bandwidth that's less than the bin spacing

[-Rick-]

```
```>On Fri, 20 Apr 2012 10:45:27 -0500, "westocl"
><cweston_@n_o_s_p_a_m.hotmail.com> wrote:
>
>   [Snipped by Lyons]
>>
>>angle(FFT(x))
>>
>>where x is some sequence
>
>Hi westocl,
>   The phase values of FFT samples are
>*VERY* susceptible to noise.  To measure
>phase your FFT input signal must
>have a pretty darned high signal-to-noise
>ratio.
>
>I'm wondering; is the signal, whose spectral
>phase you're trying to measure, a narrowband
>signal?  Is all it's spectral energy contained
>in a bandwidth that's less than the bin spacing
>
>[-Rick-]
>

In my test case, I am assured the signal has essentially infinite SNR
because at this time Im just generating it from MATLAB, so leakage is my
number one enemy in doing the FFT and trying to extract the phase.

>Is all it's spectral energy contained
>in a bandwidth that's less than the bin spacing

No. Not at all. The spectrum is much more smooth than 'peaky'. In my
application i have reason to assume there can be information exploited in
futher analysis of the spectral phase authough the signal has pretty good
bandwith.

>
>
```
```>
>I want an 'accurate' estimate the spectral phase of the signal (not to
get
>too much into it.. but thats what i want.) Delving into what is meant by
>'accurate' is a brand new can of worms id rather not open. ML estimate,
>CLB, LS... dont want to open it.
>
>Wanting the spectral phase the reason i feel that i am forced out of
having
>windows as an option.  Some of the frequency components may be weak, so
>leakage will just destroy the estimate even more so i was trying to avoid
>it as much as i could with the liberty of being able to choose the record
>lenghth... thats how the question came about.
>
>
If you want to avoid a sharp discontinuity at the end of your data, you can
force the signal to become periodic by mirroring the input signal around
the last data point to create a new input signal.  In this way it should
not matter what data points you use.  This technique is discussed as an
attempt to reduce the gibbs phenomenon in the design of a windowless
digital filter in the below article:

http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-6221.pdf

to quote page 2...
"It eliminates the discontinuities at the end points of the data with no
weighting of the data points in between." and "will not affect the spectral
content of the original data."

An alternative approach is presented in the article titled:
"New method of estimation of phase, amplitude and frequency based on all
phase FFT spectrum analysis."  A quick google search will give you the
article on ieeexplore.ieee.org though you may have to pay for it.

I haven't tried either technique myself but they may be worth a read for
you.
```
```On 4/26/12 10:52 AM, Lightbulb85 wrote:
>
> If you want to avoid a sharp discontinuity at the end of your data, you can
> force the signal to become periodic by mirroring the input signal around
> the last data point to create a new input signal.  In this way it should
> not matter what data points you use.  This technique is discussed as an
> attempt to reduce the gibbs phenomenon in the design of a windowless
> digital filter in the below article:
>
> http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-6221.pdf
>

dunno what the article says, but that mirroring is essentially what is
behind the DCT (discreet cosine transform)

--

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."

```
```On Thu, 26 Apr 2012 09:52:28 -0500, "Lightbulb85"
<david.graham.1985@n_o_s_p_a_m.hotmail.co.uk> wrote:

>>
>>I want an 'accurate' estimate the spectral phase of the signal (not to
>get
>>too much into it.. but thats what i want.) Delving into what is meant by
>>'accurate' is a brand new can of worms id rather not open. ML estimate,
>>CLB, LS... dont want to open it.
>>
>>Wanting the spectral phase the reason i feel that i am forced out of
>having
>>windows as an option.  Some of the frequency components may be weak, so
>>leakage will just destroy the estimate even more so i was trying to avoid
>>it as much as i could with the liberty of being able to choose the record
>>lenghth... thats how the question came about.
>>
>>
>If you want to avoid a sharp discontinuity at the end of your data, you can
>force the signal to become periodic by mirroring the input signal around
>the last data point to create a new input signal.  In this way it should
>not matter what data points you use.  This technique is discussed as an
>attempt to reduce the gibbs phenomenon in the design of a windowless
>digital filter in the below article:
>
>http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-6221.pdf
>
>to quote page 2...
>"It eliminates the discontinuities at the end points of the data with no
>weighting of the data points in between." and "will not affect the spectral
> content of the original data."

[Snipped by Lyons]

Hi Lightbulb85,
That paper is interesting, but I'm a little
suspicious.  The author's explanations are difficult
for me to understand, he discusses variables that he
has not defined, and he gives equations where the
indices of various sequences are not integers.
How can an index value for a sequence have the value
of 1/2?

I'll have to study his technique further before I'll
believe his claims.

[-Rick-]
```
```On 5/17/2012 3:56 PM, Rick Lyons wrote:
> On Thu, 26 Apr 2012 09:52:28 -0500, "Lightbulb85"
> <david.graham.1985@n_o_s_p_a_m.hotmail.co.uk>  wrote:
>
>>>
>>> I want an 'accurate' estimate the spectral phase of the signal (not to
>> get
>>> too much into it.. but thats what i want.) Delving into what is meant by
>>> 'accurate' is a brand new can of worms id rather not open. ML estimate,
>>> CLB, LS... dont want to open it.
>>>
>>> Wanting the spectral phase the reason i feel that i am forced out of
>> having
>>> windows as an option.  Some of the frequency components may be weak, so
>>> leakage will just destroy the estimate even more so i was trying to avoid
>>> it as much as i could with the liberty of being able to choose the record
>>> lenghth... thats how the question came about.
>>>
>>>
>> If you want to avoid a sharp discontinuity at the end of your data, you can
>> force the signal to become periodic by mirroring the input signal around
>> the last data point to create a new input signal.  In this way it should
>> not matter what data points you use.  This technique is discussed as an
>> attempt to reduce the gibbs phenomenon in the design of a windowless
>> digital filter in the below article:
>>
>> http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-6221.pdf
>>
>> to quote page 2...
>> "It eliminates the discontinuities at the end points of the data with no
>> weighting of the data points in between." and "will not affect the spectral
>> content of the original data."
>
>                  [Snipped by Lyons]
>
> Hi Lightbulb85,
>     That paper is interesting, but I'm a little
> suspicious.  The author's explanations are difficult
> for me to understand, he discusses variables that he
> has not defined, and he gives equations where the
> indices of various sequences are not integers.
> How can an index value for a sequence have the value
> of 1/2?
>
> I'll have to study his technique further before I'll
> believe his claims.
>
> [-Rick-]

Others here have mentioned flipping and doubling N in that manner but I
think the objective was different.

The author seems to confuse Gibbs phenomenon between time and frequency
from the outset - it can occur both places.
Anyway, I don't see how spectral spreading can be suppressed by this
method because there is no mention of the resulting end points - only
the middle point.
Or did I miss something?

Fred
```
```On 5/19/2012 4:22 PM, Fred Marshall wrote:
> On 5/17/2012 3:56 PM, Rick Lyons wrote:
>> On Thu, 26 Apr 2012 09:52:28 -0500, "Lightbulb85"
>> <david.graham.1985@n_o_s_p_a_m.hotmail.co.uk> wrote:
>>
>>>>
>>>> I want an 'accurate' estimate the spectral phase of the signal (not to
>>> get
>>>> too much into it.. but thats what i want.) Delving into what is
>>>> meant by
>>>> 'accurate' is a brand new can of worms id rather not open. ML estimate,
>>>> CLB, LS... dont want to open it.
>>>>
>>>> Wanting the spectral phase the reason i feel that i am forced out of
>>> having
>>>> windows as an option. Some of the frequency components may be weak, so
>>>> leakage will just destroy the estimate even more so i was trying to
>>>> avoid
>>>> it as much as i could with the liberty of being able to choose the
>>>> record
>>>> lenghth... thats how the question came about.
>>>>
>>>>
>>> If you want to avoid a sharp discontinuity at the end of your data,
>>> you can
>>> force the signal to become periodic by mirroring the input signal around
>>> the last data point to create a new input signal. In this way it should
>>> not matter what data points you use. This technique is discussed as an
>>> attempt to reduce the gibbs phenomenon in the design of a windowless
>>> digital filter in the below article:
>>>
>>> http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-6221.pdf
>>>
>>> to quote page 2...
>>> "It eliminates the discontinuities at the end points of the data with no
>>> weighting of the data points in between." and "will not affect the
>>> spectral
>>> content of the original data."
>>
>> [Snipped by Lyons]
>>
>> Hi Lightbulb85,
>> That paper is interesting, but I'm a little
>> suspicious. The author's explanations are difficult
>> for me to understand, he discusses variables that he
>> has not defined, and he gives equations where the
>> indices of various sequences are not integers.
>> How can an index value for a sequence have the value
>> of 1/2?
>>
>> I'll have to study his technique further before I'll
>> believe his claims.
>>
>> [-Rick-]
>
> Others here have mentioned flipping and doubling N in that manner but I
> think the objective was different.
>
> The author seems to confuse Gibbs phenomenon between time and frequency
> from the outset - it can occur both places.
> Anyway, I don't see how spectral spreading can be suppressed by this
> method because there is no mention of the resulting end points - only
> the middle point.
> Or did I miss something?
>
> Fred

And, I guess it's worth mentioning that the Gibbs phenomenon and

When there is a sharp discontinuity in frequency such as a brick wall
lowpass filter then:

- the inverse transform (impulse response) will have temporal spreading
that looks like a sinc.
- the step response will have temporal ringing; i.e. the Gibbs
phenomenon.  The step is a sharp discontinuity too...
The latter can be considered in a couple of ways:
- the convolution of the impulse response with the step response makes
the integral relationship pretty clear.
- multiplying in frequency of the lowpass with the "spectrum" of the
step cuts off all the high frequencies which causes the temporal ringing.
They are but an integral apart.  The Gibbs ringing is the integral of
the sinc.

When there is a sharp discontinuity in time: such as a rectangular pulse
or "gate" then:

- the transform (frequency) will have spectral spreading that looks like
a sinc.

- the convolution of the frequency response with the lowpass response
makes the integral relationship pretty clear.
- multiplying in time of the gate with the "spectrum" of the lowpass
cuts off all the high temporal "tails" in the since which causes
frequency ringing.

Just the dual transform pair thing...

Fred
```
```On Sat, 19 May 2012 16:22:42 -0700, Fred Marshall
<fmarshallxremove_the_x@acm.org> wrote:

[Snipped by Lyons]
>>
>> Hi Lightbulb85,
>>     That paper is interesting, but I'm a little
>> suspicious.  The author's explanations are difficult
>> for me to understand, he discusses variables that he
>> has not defined, and he gives equations where the
>> indices of various sequences are not integers.
>> How can an index value for a sequence have the value
>> of 1/2?
>>
>> I'll have to study his technique further before I'll
>> believe his claims.
>>
>> [-Rick-]
>
>Others here have mentioned flipping and doubling N in that manner but I
>think the objective was different.
>
>The author seems to confuse Gibbs phenomenon between time and frequency
>from the outset - it can occur both places.
>Anyway, I don't see how spectral spreading can be suppressed by this
>method because there is no mention of the resulting end points - only
>the middle point.
>Or did I miss something?
>
>Fred

Hi Fred,
Nope, I don't think you missed anything.
My current thoughts on that 'leakage reduction'
scheme are described at:

http://www.dsprelated.com/showarticle/166.php

See Ya',
[-Rick-]
```
```>Anyway, I don't see how spectral spreading can be suppressed by this
>method because there is no mention of the resulting end points - only
>the middle point.
>Or did I miss something?
>
>Fred
>

Hi Fred,
I think the point the author is making is that if you data-flip around the
centre point then the first and last points are now the same value.

For example if we have the data sequence [1 2 3] and perform an FFT, the
FFT will assume the signal is periodic and there is a sharp discontinuity
from 3 to 1.

If we perform the data-flipping first we now have [1 2 3 2 1] and when the
FFT assumes periodicity, there is no discontinuity.

I have not carried out the extensive research carried out by Rick, nor do I
have his level of understanding of DSP.  However I did carry out some
simulations in MATLAB and the technique worked for my purposes.  Clearly
Rick has found examples where it does not work, but for mine it did.

My example was to generate a cosine wave of 5 Hz, fs=512, N=512.  My time
vector ran from 1/fs to 0.9 seconds.

This results in a sharp discontinuity at the end of the data.

By using this data-flipping technique, the discontinuity is eliminated and
the new signal looks just like a regular cosine wave.

When you now compute the FFT, the spectral leakage is gone.

This example worked particularly well because the last sample in the input
data was effectively -1 so when the data-flipping was carried out, the new
signal looked just like a perfect regular cosine.

If the discontinuity is smaller, the technique is not as effective because
in the new (data-flipped) signal, you can see where the flipping occurred
(as per Rick's example).  This is easily achieved by allowing the time
vector to run to 0.85 seconds instead of 0.9.  In this example, in the
position where the flipping occurred.

As I said, I haven't done any detailed analysis of it, I just threw a
script together this morning and it seemed to serve OK in the first example
but I'm sticking with Rick's advice not to use it for anything more than
education for now.
```