📜 ⬆️ ⬇️

Designing window functions that sum up to a unit with a given level of overlap

There are a number of tasks in which the time-consuming signal is divided into segments, each of which is processed separately. In particular, this approach is used to analyze the signal using the window Fourier transform, or vice versa, during synthesis; as well as spectral processing such as noise removal, tempo changes, nonlinear filtering, audio data compression, and others.

The splitting process itself is mathematically represented by multiplying by some weight ( window ) function with offset. For the simplest window — rectangular — it might look like this:

Source signal:
')


Splits:







You can restore the original signal by simply summing them up.

Read more


However by For some reasons, a rectangular function is not the best window function. When spectral analysis through the (usually fast) discrete Fourier transform, the analyzed data block “loops”, as it were, which leads to rupture at the edges and distortion of the spectrum:



It is not suitable for reverse synthesis - since any change will also lead to discontinuities - for example, if we try to reverse one of the parts:



To eliminate these shortcomings, overlapping is used - when each next window captures part of the data from the previous one; and the weight window, respectively, smoothly falls to the edges.

50% overlap


The most common use for this is the Hanna window (also known as the “raised cosine”) with an overlap of 50%:








Due to the symmetry of the cosine function when added, they are summed to one:



Now, in the reverse synthesis, we will not get discontinuities - but only under the condition that the values ​​at the window borders will still go to zero. For example, when reversing one of the parts, the smoothness is not disturbed:



Processing double overlay windows


Let us consider in more detail the algorithm for signal processing using the fast Fourier transform (FFT):

  1. splitting the signal into segments with overlapping window;
  2. direct FFT;
  3. spectrum processing;
  4. reverse FFT;
  5. repeated overlapping of the window (since after the inverse FFT the boundaries will not necessarily be joined to zero without a break);
  6. summation of the resulting segments.

At the same time, if spectrum processing is not performed, the output signal must be identical to the input signal (only with the inevitable time delay).

When using the Hanna window, overlapping by 50% is no longer enough, since failures will occur:



Since double overlap is tantamount to squaring, the obvious solution would be to use the root from the Hanna window to compensate for squaring:



In this case, however, the window ceased to be smooth at the edges - a gap appeared in the first derivative.

Note
Interestingly, in this case, we got half the period of the sinusoid.

You can go the other way - to use the overlap of 75%, and then the windows will also be added to a constant - just not in 1 and in  frac32 :



In this case, we just got lucky. If we decompose a square into an amount, we can see that it is a composition of two Hanna windows, but at different scales, which allows us to fulfill the requirements we need:

 left( frac cos(2 pix)+12 right)2= frac cos(2 pix)+12+ frac cos(4 pix)18



With other window functions, such a focus will not work; Also, not all standard window functions can provide summation in a constant and at 50% overlap.

Idea


You can consider the Hanna window not as an independent function, but as the difference between two piecewise-continuous functions (a separate article was devoted to detailed consideration) with an offset. For example, using the following function

\ left \ {\ begin {array} {ll} -1 & x \ leqslant -1 \\ 1 & x \ geqslant 1 \\ \ sin \ left (\ frac {\ pi x} {2} \ right) & -1 <x <1 \\ \ end {array} \ right.

\ left \ {\ begin {array} {ll} -1 & x \ leqslant -1 \\ 1 & x \ geqslant 1 \\ \ sin \ left (\ frac {\ pi x} {2} \ right) & -1 <x <1 \\ \ end {array} \ right.



can write

f(x+1)f(x1)



Having considered the components of the sum of two such windows, their ability to add up to a constant will become more intuitive:



On the segment [0,2] we received mutual compensation when adding functions f(x1) and f((x+1)2) , insofar as f((x+1)2)=f(x1)

You can also select another offset, with a large overlap, for example:

f left(x+ frac12 right)f left(x frac12 right)



And then, when offset in increments  frac12 , they will also be added to a constant:



It can be seen that if you rearrange the components of the window function, you get all the same windows Hannah.

Thus, using various functions of restriction, it is possible to form windows of the necessary form.

Final formula


Now it only remains to set the scale so that the definition areas and values ​​do not depend on the amount of overlap. Defining a window on the interval [0,1] will get

 fracf left( frac2txt11 right)f left( frac2t(x1)t1+1 right)2


Where f - piecewise continuous form function

\ left \ {\ begin {array} {ll} -1 & x \ leqslant -1 \\ 1 & x \ geqslant 1 \\ g (x) & -1 <x <1 \\ \ end {array} \ right.

\ left \ {\ begin {array} {ll} -1 & x \ leqslant -1 \\ 1 & x \ geqslant 1 \\ g (x) & -1 <x <1 \\ \ end {array} \ right.


but g - some interpolating function between points (1,1) and (1,1) .

Parameter t determines the level of overlap - the divisor that determines the step to which each next window should be shifted, xn+1=xn+ frac1t , and must be greater than one, t>1 .

Overlap percentage p can be calculated by the formula

p= frac100(t1)t


and vice versa

t= frac100100p



Note
When working with real data, it may be necessary to recalculate the level of overlap depending on the specific FFT size. For example, with FFT at 2048 points and a level of overlap of 3, we get a step of 2048/3 = 682.666 ..., which in practice is naturally unrealizable. Therefore round it to the whole, and t recalculated as 2048/683 = 2.998535871156662 ...

Or you can do the opposite - use the window size, which is known to be divisible by 3 (say, 999), and the remainder up to the required size for the FFT should be filled with zeros (25th).

The final view of the window will depend on both the choice of the level of overlap and the choice of the limiting function.

Some interesting examples


Here we look at several ready-made solutions for which everything was started. For simplicity, we will consider just the interpolating function. g(x) without any other strapping.

Polynomial windows


They are the least computationally expensive. Using the previously derived formula

 frac2x Gamma left(n+ frac12 right)2F1 left( frac12,1n; frac32;x2 right) sqrt pi Gamma(n)


we obtain a polynomial with a given number of zeros on higher derivatives that provide the necessary smoothness of the window at the edges.

first 10 polynomials

 beginarraycx frac12x left(3x2 right) frac18x left(3x410x2+15 right) frac116x left(5x6+21x435x2+35 right) frac1128x left(35x8180x6+378x4420x2+315 right) frac1256x left(63x10+385x8990x6+1386x41155x2+693 right) fracx left(231x121638x10+5005x88580x6+9009x46006x2+3003 right)1024 fracx left(429x14+3465x1212285x10+25025x832175x6+27027x415015x2+6435 right)2048 fracx left(6435x1658344x14+235620x12556920x10+850850x8875160x6+612612x4291720x2+109395 right)32768 fracx left(12155x18+122265x16554268x14+1492260x122645370x10+3233230x82771340x6+1662804x4692835x2+230945 right)65536 endarray



With a 75% overlap, windows with different values ​​of n will look like this:



And in the case of root extraction, this is the case (using 75% overlap):



or so (when using 50% overlap):



Maximum smooth window


Function

 tanh left( frackx sqrt1x2 right)


It is interesting in that it is infinitely differentiable and all its derivatives at the edges are 0 (which can be proved by considering its derivatives based on the rules of differentiation - in each term there will be a multiplying factor). This allows building windows on its basis, all derivatives of which have no discontinuities:



Window "skirt"


The need for this type of window is caused by increasing the resolution of the FFT, but reducing the effect of the “time-frequency uncertainty” effect at high frequencies by increasing their concentration in the center.

First, we define the desired type of window function - for example, as follows:

 log left(k2x2+1 right)+ log left(k2+1 right) frack2 left(1x2 right)k2+1



Here, the first term determines the type of the function itself, the second one provides the intersection with the abscissa axis, the third (parabola) nullifies the derivative at the edges for a smooth docking; and the parameter k defines the "sharpness" of the top. In this form, it is not yet suitable for use - first, it is necessary to obtain the function of restriction from it through integration and scaling:

 frackx left(k2 left(x2+3 right)+6 right)+3 left(k2+1 right) left(kx left( log left(k2+1 right) log left(k2x2+1 right) right)2 tan1(kx) right)4k36 left(k2+1 right) tan1(k)+6k


For convenience, you can bind the parameter k overlap level t - for example, so that the 4th derivative in the center of the window was 0 - and then k will be counted as  sqrt3(t1) :



Here, for clarity, all windows are reduced to the same scale.

Window view "needle"


It is a more "aggressive" version of the previous window. As a basis, a hyperbola was chosen, from which, by successive transformations

 frac1x to frac1 sqrtx2 to frac1 sqrtx2+1 to frac1 sqrtk2x2+1 to frac left(1x2 right)2 sqrtk2x2+1


and using the same steps in the form of integration and scaling we got the formula

 frackx left(2k2 left(x24 right)3 right) sqrtk2x2+1+ left(8 left(k4+k2 right)+3 right) sinh1(kx) left(8 left(k4+k2 right)+3 right) sinh1(k)3k sqrtk2+1 left(2k2+1 right)


Here you can also bind the parameter k to the level of overlap. Directly solving the 4th derivative equation is too cumbersome, so we’ll just make the solution for the previous window in the same way as k as k(t1) thus ensuring the role of the parameter k as “fine tuning”. With k=2.22 windows will look like this:



Asymmetrical window


The window function does not necessarily have to be symmetrical. Suppose we need a window with a sharp attack and a smooth attenuation. We can get it according to the already familiar scheme - first determine the desired type of function, and then integrate to get the restriction function. Here, the task is slightly complicated due to the fact that, due to asymmetry, the center will no longer pass through the origin, therefore an additional calculation step is added. This also leads to the fact that the formulas as a result are quite cumbersome. For example, consider the simplest option - a parabola multiplied by a polynomial weight window:

(1x)2 left(1x10 right)2



Here, the degree at x in the weighted window (namely, 10) determines the “sharpness” of the attack. We used a specific value, rather than a character parameter, to simplify the formulas for clarity - if you wish, you can recalculate it later.

After integration, just scaling is no longer enough - you need to even out the edges:



To do this, we first move the function to the top to align the left edge, and then scale it to the right along the two and subtract one. Then we get the following formula:

 frac8775 left( fracx2727 frac2x2626+ fracx2525 frac2x1515+ frac4x1414 frac2x1313+ fracx33x2+x+ frac11759261425 right)98561


In order for the final window to have the desired appearance, it is also necessary to ensure a sufficiently large level of overlap:



Conclusion


Similarly, windows can be constructed from any other bell-shaped functions — for example, Gaussians; and it is also possible to modify those already considered in order to provide greater smoothness or change in the shape of the curve.

The spectral composition of such window functions has remained outside of consideration — separate studies should be devoted to this.

A slightly more advanced version of the article (with the ability to dynamically change the parameters in the windows under consideration and hidden formulas) as a Wolfram Mathematica document can be downloaded here .

Source: https://habr.com/ru/post/430536/


All Articles