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

  • Tutorial
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:



Splitting:







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

Read more


However byFor 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 seems to be "looping", which leads to a break at the edges and distortion of the spectrum:



It is not suitable for reverse synthesis either - because any change will also lead to breaks - for example, We will 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


Most often, the Hanna window is used for this (also known as “raised cosine”) with an overlap of 50%:








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



Now, in the reverse synthesis, we will not get gaps - but only if on the borders of the window, the values ​​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 windows;
  2. direct FFT;
  3. spectrum processing;
  4. reverse FFT;
  5. repeated window overlap (since after the inverse FFT the boundaries will not necessarily be joined to zero without a break);
  6. summation of the resulting segments.

In this case, if the 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 dips will arise:



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



In this case, however, the window is no longer 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 - use the overlap of 75%, and then the windows will also be added to a constant - just not in $ 1 $and in $ \ frac {3} {2} $:



In this case, we just got lucky. If we decompose a square into an amount, then 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 \ pi x) +1} {2} \ right) ^ 2 = \ frac {\ cos (2 \ pi x) +1} {2} + \ frac {\ cos (4 \ pi x) -1} {8} $



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 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. $



can write

$ f (x + 1) -f (x-1) $



Having considered the components of the sum of two such windows, their ability to be summed into a constant will become more obvious:



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

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

$ f \ left (x + \ frac {1} {2} \ right) -f \ left (x- \ frac {1} {2} \ right) $



And then, when offset in increments $ \ frac {1} {2} $, they will also be summed up in a constant:



It is clear 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 remains to set the scale so that the definition areas and values ​​do not depend on the size of the overlap. Defining a window on the interval$ [0,1] $ will get

$ \ frac {f \ left (\ frac {2 tx} {t-1} -1 \ right) -f \ left (\ frac {2 t (x-1)} {t-1} +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. $


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, $ x_ {n + 1} = x_n + \ frac {1} {t} $, and must be greater than one, $ t> 1 $.

Overlap percentage$ p $ can be calculated by the formula

$ p = \ frac {100 (t-1)} {t} $


and vice versa

$ t = \ frac {100} {100-p} $



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 $we will recalculate as 2048/683 = 2.998535871156662 ...

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

The final view of the window will depend on the choice of the level of overlap, and on the choice of the bounding function.

Some interesting examples


Here we will 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

$ \ frac {2 x \ Gamma \ left (n + \ frac {1} {2} \ right) \, _2F_1 \ left (\ frac {1} {2}, 1-n; \ frac {3} {2} ; x ^ 2 \ 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

$ \ begin {array} {c} x \\ \ frac {1} {2} x \ left (3-x ^ 2 \ right) \\ \ frac {1} {8} x \ left (3 x ^ 4 -10 x ^ 2 + 15 \ right) \\ \ frac {1} {16} x \ left (-5 x ^ 6 + 21 x ^ 4-35 x ^ 2 + 35 \ right) \\ \ frac {1 } {128} x \ left (35 x ^ 8-180 x ^ 6 + 378 x ^ 4-420 x ^ 2 + 315 \ right) \\ \ frac {1} {256} x \ left (-63 x ^ {10} +385 x ^ 8-990 x ^ 6 + 1386 x ^ 4-1155 x ^ 2 + 693 \ right) \\ \ frac {x \ left (231 x ^ {12} -1638 x ^ {10} +5005 x ^ 8-8580 x ^ 6 + 9009 x ^ 4-6006 x ^ 2 + 3003 \ right)} {1024} \\ \ frac {x \ left (-429 x ^ {14} +3465 x ^ { 12} -12285 x ^ {10} +25025 x ^ 8-32175 x ^ 6 + 27027 x ^ 4-15015 x ^ 2 + 6435 \ right)} {2048} \\ frac {x \ left (6435 x ^ {16} -58344 x ^ {14} +235620 x ^ {12} -556920 x ^ {10} +850850 x ^ 8-875160 x ^ 6 + 612612 x ^ 4-291720 x ^ 2 + 109395 \ right)} {32768} \\ \ frac {x \ left (-12155 x ^ {18} +122265 x ^ {16} -554268 x ^ {14} +1492260 x ^ {12} -2645370 x ^ {10} +3233230 x ^ 8-2771340 x ^ 6 + 1662804 x ^ 4-692835 x ^ 2 + 230945 \ right)} {65536} \\ \ end {array} $



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



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



or this way (using 50% overlap):



Maximum smooth window


Function

$ \ tanh \ left (\ frac {kx} {\ sqrt {1-x ^ 2}} \ right) $


It is interesting because 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 (k ^ 2 x ^ 2 + 1 \ right) + \ log \ left (k ^ 2 + 1 \ right) - \ frac {k ^ 2 \ left (1-x ^ 2 \ right) } {k ^ 2 + 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) zeroes 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:

$ \ frac {kx \ left (k ^ 2 \ left (x ^ 2 + 3 \ right) + 6 \ right) +3 \ left (k ^ 2 + 1 \ right) \ left (kx \ left (\ log \ left (k ^ 2 + 1 \ right) - \ log \ left (k ^ 2 x ^ 2 + 1 \ right) \ right) -2 \ tan ^ {- 1} (kx) \ right)} {4 k ^ 3-6 \ left (k ^ 2 + 1 \ right) \ tan ^ {- 1} (k) +6 k} $


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$ \ sqrt {3} (t-1) $:



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

Needle View Window


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

$ \ frac {1} {x} \ to \ frac {1} {\ sqrt {x ^ 2}} \ to \ frac {1} {\ sqrt {x ^ 2 + 1}} \ to \ frac {1} {\ sqrt {k ^ 2 x ^ 2 + 1}} \ to \ frac {\ left (1-x ^ 2 \ right) ^ 2} {\ sqrt {k ^ 2 x ^ 2 + 1}} $


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

$ \ frac {kx \ left (2 k ^ 2 \ left (x ^ 2-4 \ right) -3 \ right) \ sqrt {k ^ 2 x ^ 2 + 1} + \ left (8 \ left (k ^ 4 + k ^ 2 \ right) +3 \ right) \ sinh ^ {- 1} (kx)} {\ left (8 \ left (k ^ 4 + k ^ 2 \ right) +3 \ right) \ sinh ^ {-1} (k) -3 k \ sqrt {k ^ 2 + 1} \ left (2 k ^ 2 + 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 (t-1) $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 obtain the function of restriction. 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:

$ (1-x) ^ 2 \ left (1-x ^ {10} \ 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 the integration, simply scaling is not enough - you need to even out the edges:



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

$ \ frac {8775 \ left (\ frac {x ^ {27}} {27} - \ frac {2 x ^ {26}} {26} + \ frac {x ^ {25}} {25} - \ frac {2 x ^ {15}} {15} + \ frac {4 x ^ {14}} {14} - \ frac {2 x ^ {13}} {13} + \ frac {x ^ 3} {3} -x ^ 2 + x + \ frac {117592} {61425} \ right)} {9856} -1 $


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, you can build windows 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 a 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) in the form of a Wolfram Mathematica document can be downloaded here .

Also popular now: