Windows of Opportunity

Some­times sig­nals can be stub­born­ly non-peri­od­ic. This can make dig­i­tal sig­nal pro­cess­ing so much more annoy­ing. The sup­pos­ed­ly sim­ple act of plot­ting the spec­trum ends up being a game of tri­al-and-error, or requires mak­ing a deci­sion that involves pri­or knowl­edge of what one would actu­al­ly like to know in the first place. We’ll have a look at why this is so and what to do about it.

About leakage and dynamic range

Basi­cal­ly, leak­age is a con­se­quence of look­ing at only a finite seg­ment of a sig­nal instead of the whole sig­nal extend­ing over all time, from neg­a­tive to pos­i­tive infin­i­ty. In the most sim­ple case, the sig­nal seg­ment $s^{\prime}(t)$ is iso­lat­ed by mul­ti­ply­ing a sig­nal $s(t)$ with a box func­tion such that

$$s^{\prime}(t) = s(t) \cdot w_\mathrm{rect}(t) \quad\text{with} \quad w_\mathrm{rect}(t) = \begin{cases} 1 & -\frac{T}{2} \le t \lt \frac{T}{2} \\ 0 & \vphantom{\frac{T}{2}}\mathrm{else} \end{cases}\tag{1}$$

This mul­ti­pli­ca­tion in the time domain cor­re­sponds to a con­vo­lu­tion in the fre­quen­cy domain, i.e. each fre­quen­cy com­po­nent con­tained in $s(t)$ is con­volved with the Fouri­er trans­form of the box func­tion, which is

$$\tilde w_\mathrm{rect}(f) = T \,\, \mathrm{sinc} \bigl(f \, T\bigr) \quad\text{with}\quad \mathrm{sinc}\,x = \frac{\sin \pi x}{\pi x} \tag{2}$$

where the tilde denotes a Fouri­er-trans­formed quan­ti­ty. Part of the ener­gy con­tained in that fre­quen­cy com­po­nent is dis­trib­uted over the entire fre­quen­cy domain. This is referred to as leak­age. One dis­ad­van­tage of such strong leak­age is that small sig­nals in the vicin­i­ty of strong sig­nals can be com­plete­ly masked if the leak­age ener­gy at some fre­quen­cy is larg­er than the sig­nal ener­gy at that fre­quen­cy. This great­ly reduces the dynam­ic range of the spec­tral analy­sis. The box win­dow has a very low dynam­ic range.


As long as the seg­ment $s^{\prime}(t)$ is to be of finite dura­tion, leak­age can­not be pre­vent­ed. How­ev­er, by using func­tions oth­er than the box, the dis­tri­b­u­tion of leak­age ener­gy in the spec­trum can be shaped, since that is described by the Fouri­er trans­form of the win­dow. To make things a bit sim­pler, we will nor­mal­ize win­dow func­tions so that $T=1$. We will also fol­low Eric Weis­stein and call their Fouri­er trans­forms instru­ment func­tions [1]. Fig­ures 1 through 3 illus­trate $w_\mathrm{rect}(t)$ and its instru­ment func­tion, as well as the Hann and flat-top win­dows, two often used win­dows. The ener­gy spec­tral den­si­ty (ESD), shown in the fig­ures, is defined as the squared mag­ni­tude of the instru­ment func­tion.
The Hann win­dow is defined as

$$w_\mathrm{hann}(t) = \begin{cases} \cos^2 \bigl(\pi t \bigr) & -\frac{1}{2} \le t \lt \frac{1}{2} \\ 0 & \vphantom{\frac{1}{2}}\mathrm{else} \end{cases} \tag{3}$$

which is actu­al­ly the prod­uct of a raised cosine func­tion with the box win­dow $w_\mathrm{rect}(t)$. No mat­ter the func­tion that describes the shape of the win­dow, it must always be bound­ed in time by mul­ti­pli­ca­tion with the box – that is also the rea­son why there is always leak­age: the instru­ment func­tion of $w_\mathrm{hann}(t)$ is the con­vo­lu­tion of the infi­nite­ly extend­ed $\tilde w_\mathrm{rect}(f)$ with anoth­er func­tion (most often it’s a num­ber of Dirac delta peaks result­ing from a sum of cosines). The flat-top win­dow is often defined as

w_\mathrm{flat}(t) = \begin{cases} \sum_{n=0}^4 a_{n} \cos \bigl(2 n \pi t \bigr) & -\frac{1}{2} \le t \lt \frac{1}{2} \\ 0 & \vphantom{\frac{1}{2}}\mathrm{else} \end{cases} \tag{4}\\
\text{with} \vphantom{\frac{1}{2}} \quad a_0 = 0.21557895 \quad a_1 = 0.41663158 \quad a_2 = 0.277263158\\
\quad a_3 = 0.083578947 \quad a_4 = 0.006947368

The side­lobes of both, the Hann win­dow and the flat-top win­dow, are sig­nif­i­cant­ly low­er than those of the rec­tan­gu­lar win­dow, increas­ing the dynam­ic range in the vicin­i­ty of a strong peak. In the case of the Hann win­dow they also fall off much more rapid­ly, their slope is steep­er. The flat-top falls off more slow­ly, but it has a very large dynam­ic range over a broad spec­tral range.

I have com­piled an overview of a much larg­er num­ber of com­mon win­dow func­tions on a sep­a­rate page, Win­dow Func­tion Ref­er­ence.

Fig­ure 1: Some prop­er­ties of the box win­dow and its instru­ment func­tion. The win­dow func­tion (top left) is nor­mal­ized to T = 1; graph also shows the win­dow ener­gy rel­a­tive to the box win­dow. Instru­ment func­tion (top right) is shown for the spec­tral region cov­er­ing the first 10 DFT bins. Close-up (bot­tom) shows max­i­mum scal­lop­ing loss (see below), rel­a­tive height of first side­lobe, and frac­tion of ener­gy con­tained in main lobe, E0, to total ener­gy E.

Fig­ure 2: Some prop­er­ties of the Hann win­dow and its instru­ment func­tion. The win­dow func­tion (top left) is nor­mal­ized to T = 1; graph also shows the win­dow ener­gy rel­a­tive to the box win­dow. Instru­ment func­tion (top right) is shown for the spec­tral region cov­er­ing the first 10 DFT bins. Close-up (bot­tom) shows main lobe height, max­i­mum scal­lop­ing loss (see below), rel­a­tive height of first side­lobe, and frac­tion of ener­gy con­tained in main lobe, E0, to total ener­gy E.

Fig­ure 3: Some prop­er­ties of the flat-top win­dow and its instru­ment func­tion. The win­dow func­tion (top left) is nor­mal­ized to T = 1; graph also shows the win­dow ener­gy rel­a­tive to the box win­dow. Instru­ment func­tion (top right) is shown for the spec­tral region cov­er­ing the first 10 DFT bins. Close-up (bot­tom) shows main lobe height, max­i­mum scal­lop­ing loss (see below), rel­a­tive height of first side­lobe, and frac­tion of ener­gy con­tained in main lobe, E0, to total ener­gy E.


Com­par­ing the three win­dows, we also notice that their main lobe width dif­fers sig­nif­i­cant­ly. Main lobe width can be defined either as the 3dB (half-)width or the width to the first spec­tral zero. With­in the main lobe the dynam­ic range is very low – if two spec­tral com­po­nents of a sig­nal are sep­a­rat­ed by less than their main lobe (3dB) width, they are vir­tu­al­ly indis­tin­guish­able. The min­i­mum sep­a­ra­tion for detectabil­i­ty deter­mines the res­o­lu­tion of the win­dow.$^1$ The box win­dow has the high­est pos­si­ble res­o­lu­tion (at the expense of low dynam­ic range). The Hann win­dow is a mid­dle-ground trade-off between res­o­lu­tion and dynam­ic range. The flat-top win­dow has very low res­o­lu­tion owing to its sig­nif­i­cant main lobe width. Oth­er win­dows usu­al­ly weight res­o­lu­tion and dynam­ic range some­where between the box and the flat-top.

Discrete Signals

Spec­tral leak­age occurs for con­tin­u­ous and dis­crete sig­nals alike, as long as they are not of infi­nite dura­tion. How­ev­er, there are some inter­est­ing pecu­liar­i­ties when work­ing with dis­crete sig­nals (such as the appar­ent absence of leak­age in some sig­nals), for which rea­son we’ll look at these a bit more in detail.

The dis­crete Fouri­er trans­form (DFT) takes a dis­crete sam­ple sequence and trans­forms it into anoth­er dis­crete sam­ple sequence. If the first sequence is inter­pret­ed as con­sec­u­tive sam­ples of a time sig­nal (seg­ment), the sec­ond sequence cor­re­sponds to the sam­pled Fouri­er spec­trum of the time sig­nal, with some caveats.$^2$ When there are $N$ time sam­ples with­in the peri­od $T$, the sam­ple dura­tion is

$$\Delta t = \frac{T}{N}$$

The result­ing fre­quen­cy range spanned by the dis­crete spec­trum and spac­ing between fre­quen­cy sam­ples (or “bins”) are

$$F = \frac{1}{\Delta t} = \frac{N}{T} \quad \text{and} \quad \Delta f = \frac{1}{T}$$

respec­tive­ly. See also my DFT cheat sheet [2] for illus­trat­ed rela­tions between the var­i­ous time and fre­quen­cy quan­ti­ties.

Look­ing at the instru­ment func­tion (2) of the box win­dow, we see that it has zeros at all non-zero inte­ger mul­ti­ples of $1/T = \Delta f$ – which is the same spac­ing as between the sam­ples of the DFT fre­quen­cy spec­trum. This means that if a spec­tral com­po­nent of $s(t)$ cor­re­sponds exact­ly to one of the fre­quen­cies sam­pled by the DFT spec­trum, all oth­er fre­quen­cy sam­ples coin­cide with zeros of the box win­dow instru­ment func­tion, and thus it appears as if there is no leak­age at all! How­ev­er, this is real­ly just an arti­fact of the sam­pled nature of the DFT spec­trum. The par­tic­u­lar fre­quen­cy com­po­nents for which this occurs (those at inte­ger mul­ti­ples of $\Delta f$) are those cor­re­spond­ing to an inte­ger num­ber of full oscil­la­tions with­in $T$. Hence, any sig­nal seg­ment for which all fre­quen­cy com­po­nents (and thus the seg­ment itself) are peri­od­i­cal­ly exten­si­ble with­out jumps (for all its fre­quen­cy com­po­nents) is trans­formed leak­age-free and thus exact.

With real-world sig­nals, the seg­ment $s’(t)$ will be prop­er­ly peri­od­ic only in the rarest of cas­es, and almost always we will have to deal with leak­age.


Anoth­er effect pecu­liar to dis­crete spec­tra is called scal­lop­ing. If a fre­quen­cy com­po­nent of $s(t)$ falls out­side any fre­quen­cy that is sam­pled by the DFT spec­trum, then its con­vo­lu­tion with the instru­ment func­tion is not sam­pled at the (known) max­i­mum of the result­ing curve but slight­ly off­set. The max­i­mum pos­si­ble off­set is half the sep­a­ra­tion between two DFT sam­ples, or $\Delta f / 2$. The max­i­mum pos­si­ble scal­lop­ing is thus the instru­ment func­tion dif­fer­ence between $f=0$ and $f=\Delta f/2$. When scal­lop­ing is large then the obtained ener­gy read­ing of a fre­quen­cy com­po­nent depends on the fre­quen­cy of that spec­tral com­po­nent rel­a­tive to the DFT sam­pling points. This scal­lop­ing is largest for the box win­dow – its instru­ment func­tion falls off rapid­ly, which also results in its excel­lent res­o­lu­tion. The flat-top win­dow – hence the name – falls off very slow­ly, and scal­lop­ing is usu­al­ly not an issue, though it results in poor res­o­lu­tion.

Since by means of scal­lop­ing the ener­gy in a fre­quen­cy com­po­nent is dis­trib­uted into sev­er­al DFT bins, it can be used to approx­i­mate the exact fre­quen­cy of that com­po­nent even if it does not coin­cide with a DFT bin, if the instru­ment func­tion is known. When mul­ti­ple fre­quen­cy com­po­nents are super­posed in a sig­nal, this is gen­er­al­ly not pos­si­ble, how­ev­er, since their over­lap­ping con­tri­bu­tions to the DFT spec­trum can­not be sep­a­rat­ed.

Fig­ure 4 shows the rel­a­tive ener­gy detect­ed in neigh­bor­ing DFT bins (and hence the scal­lop­ing) when the fre­quen­cy of a sin­gle spec­tral com­po­nent is swept between the bin fre­quen­cies for the box, Hann, and flat-top win­dows. The 3dB half-width of the main lobe is also shown.



Fig­ure 4: Com­par­i­son of the box win­dow (top), Hann win­dow (mid­dle), and flat-top win­dow (bot­tom) with respect to scal­lop­ing. Shown is the ener­gy detect­ed in the neigh­bor­ing DFT bins when the true fre­quen­cy of the sig­nal lies some­where in between. Max­i­mum scal­lop­ing occurs at a fre­quen­cy off­set of 0.5 bins (there­after the fre­quen­cy is clos­er to the next bin). Also shown is the 3dB half-width of the main lobe.

Equivalent Noise Bandwidth

The ENBW has its very own post here.

Agony of choice

So which win­dow is the best one – box, Hann, flat-top, or any of the oth­er win­dows pro­filed on the overview page or some­where else? The answer is: that depends. It depends on the kind of sig­nal we want to mea­sure.

If the exact ener­gy of the fre­quen­cy com­po­nents in the sig­nal is impor­tant, win­dows with very lit­tle scal­lop­ing such as the flat-top are usu­al­ly the best choice. How­ev­er, when mul­ti­ple fre­quen­cy com­po­nents can occur close to each oth­er, the low res­o­lu­tion of these win­dows will blur them into a sin­gle peak with­out usable infor­ma­tion about the ener­gy con­tent of the sin­gle com­po­nents.

If res­o­lu­tion is impor­tant, we usu­al­ly need to sac­ri­fice dynam­ic range near strong peaks, and vice ver­sa. The box win­dow offers the high­est res­o­lu­tion, but has very low dynam­ic range. The flat-top has a high dynam­ic range, but poor res­o­lu­tion. The Hann win­dow bal­ances res­o­lu­tion and dynam­ic range and is often a good start­ing point for spec­tral analy­sis.

Fig­ure 5 illus­trates the advan­tages and dis­ad­van­tages of our three win­dow types. A time sig­nal is com­posed of var­i­ous fre­quen­cy com­po­nents (grey peaks in each graph) and ana­lyzed used each win­dow. The ener­gy spec­tral den­si­ty val­ues were nor­mal­ized so that $\tilde w(0)$ (the main lobe height) cor­re­sponds to one. This is nec­es­sary to obtain the cor­rect ener­gy infor­ma­tion since each win­dow has a deter­min­is­tic cor­rec­tion fac­tor that depends on the ener­gy of the win­dow func­tion itself (win­dow func­tions $w(t)$ that have small val­ues most of the time reduce the ener­gy in the win­dowed sig­nal) and the leak­age prop­er­ties (the por­tion of the instru­ment func­tion ener­gy that is con­tained in the main lobe and the width of the main lobe deter­mine its height).



Fig­ure 5: Com­par­i­son of the box win­dow (top), Hann win­dow (mid­dle), and flat-top win­dow (bot­tom) with respect to sig­nal detec­tion abil­i­ty. Grey arrows denote the fre­quen­cy com­po­nents in the time sig­nal, blue dots denote the obtained DFT spec­trum, and green lines illus­trate the con­tin­u­ous shape of the spec­trum of the win­dowed sig­nal.

The rec­tan­gu­lar box win­dow clear­ly sep­a­rates the close­ly spaced fre­quen­cy com­po­nents, even though one of them is severe­ly affect­ed by scal­lop­ing. The three weak­er sig­nal are not detect­ed at all due to strong leak­age. The Hann win­dow can still sep­a­rate the two strong sig­nals, but not as clear­ly; also scal­lop­ing is reduced. With it, the strongest of the weak sig­nals is also detectable, and due to the steep slope of its side­lobes the weak­est sig­nal, well sep­a­rat­ed from the strong peaks, is also detectable. Only one sig­nal is masked by leak­age. The flat-top win­dow can­not prop­er­ly sep­a­rate both strong sig­nals due to its poor res­o­lu­tion, but can detect the two strongest of the weak sig­nal, both with cor­rect ampli­tude owing to the absence of scal­lop­ing. The weak­est sig­nal is not prop­er­ly detectable, since the side­lobe slope of the flat-top win­dow is rather flat.

Since the choice of the best win­dow depends to a large extent on the spec­tral prop­er­ties of the sig­nal, and the lat­ter is usu­al­ly the prop­er­ty we’d like to know, it is nor­mal­ly a good idea to try dif­fer­ent win­dow func­tions and to look for weak sig­nals, sig­nals in close prox­im­i­ty, etc. with the prop­er win­dow. The Hann win­dow is usu­al­ly a good start­ing point because of its dynam­ic range vs. res­o­lu­tion bal­ance, but it is not the right win­dow for every job.

Notes on signal processing

Maybe I should empha­size an issue with the DFT here, since that wasn’t real­ly clear to me (in the prop­er way) until recent­ly: Using the DFT for sig­nal pro­cess­ing is usu­al­ly not a very good idea, unless one is deal­ing with sig­nals that are most­ly peri­od­ic (except for noise and/or oth­er weak spec­tral com­po­nents of no inter­est). These are usu­al­ly gen­er­at­ed by an inverse DFT (like the sym­bols in OFDM com­mu­ni­ca­tion or sig­nals in opti­cal com­mu­ni­ca­tion sim­u­la­tors).

Using a win­dow when doing com­pu­ta­tions on a sig­nal in the fre­quen­cy domain is usu­al­ly also not a good idea, since win­dow­ing sig­nif­i­cant­ly changes the time-domain sig­nal and the oper­a­tions in the fre­quen­cy domain do not only affect the sig­nal itself, but also the win­dow func­tion, so that a sim­ple mul­ti­pli­ca­tion with the inverse of the win­dow after trans­for­ma­tion back into the time domain will not yield the cor­rect result.

With the right kind of sig­nal, the DFT can be used very effec­tiv­ly e.g. in the cal­cu­la­tion of sig­nal prop­a­ga­tion in opti­cal fibers DFT algo­rithms can be used to cal­cu­late the effects of chro­mat­ic dis­per­sion in the fre­quen­cy domain very quick­ly. How­ev­er, with seg­ments of real-world sig­nals, leak­age will intro­duce dis­tor­tions at the seg­ment bound­aries that may be prob­lem­at­ic – in those cas­es it would be pru­dent to use FIR fil­ter imple­men­ta­tions.

1 Res­o­lu­tion in this con­text seems to be a poor­ly defined term. In optics, there is the Rayleigh cri­te­ri­on that defines if some opti­cal instru­ment is able to resolve two dis­tinct sources or not. I have not found any­thing sim­i­lar in a (brief) search on the top­ic.

2 The sam­pling in the fre­quen­cy domain cor­re­sponds to a peri­od­ic exten­sion of the time sig­nal, hence it’s actu­al­ly the trans­form of the peri­od­i­cal­ly extend­ed sig­nal seg­ment. Also, the sam­pled time sig­nal cor­re­sponds to a peri­od­ic exten­sion of the sig­nal spec­trum. If the spec­trum is wider than the rep­e­ti­tion peri­od (which is called under­sam­pling), the repeat­ed spec­tra will over­lap – this over­lap can­not be undone. See the Nyquist the­o­rem.

[1] Instru­ment Func­tion [Math­World]
[2] DFT Cheat Sheet [Nerd Rage]
[3] Win­dow Func­tion Ref­er­ence [Nerd Rage]

last posts in signal processing:

One Comment

Post a Comment

Your email is never shared.