YTread Logo
YTread Logo

Wavelets: a mathematical microscope

May 03, 2024
The real world is full of signals that are inherently noisy and irregular but at the same time have a certain structure. There is an entire field of signal processing dedicated to analyzing them. For example, take a look at this signal here which is a recording of electrical signals. Mouse brain activity clearly has an interesting structure, if you cloud your vision you can see that there are three episodes of oscillation whose amplitude first increases and then decreases and if we zoom in on one of those episodes it becomes evident that the image is even more interesting. because the peaks of the wave have a faster oscillation above them, but how are these phenomena characterized

mathematical

ly?
wavelets a mathematical microscope
Because if you're a scientist and your job is to analyze data like this and describe it, you can do it. I just look at it and say, "Well, this piece seems a little wavy because it's not objective, it requires an enormous amount of effort, and most of the time the structure of the data is hidden behind noise. Instead, we need a precise

mathematical

operation that looks at the data through the noise and quantify the structure present in the signal, something that could blur vision and zoom in and out of the signal to extract the patterns like a kind of mathematical

microscope

.
wavelets a mathematical microscope

More Interesting Facts About,

wavelets a mathematical microscope...

In this video. We will see how to build exactly this type of tool called wavelet transform, a very recent invention that has revolutionized the field of signal processing. Before we begin, let's introduce a fundamental concept of time-frequency duality. Let's imagine that you want to communicate to your friend a list. of two numbers x1 and x2. One and the most obvious way is to send the values ​​of the two numbers directly. Alternatively, you can construct two completely new numbers y1 and y2 that are defined as the sum and difference of x1 and x2 respectively. Note that if you know the values ​​of y1 and y2 you can uniquely reconstruct the numbers themselves, so that the messages x1, x2, and y1 y2 carry essentially the same information because knowing one pair automatically gives you another;
wavelets a mathematical microscope
In other words, they are two alternative representations of the same data; in fact, this is trivial. In the case of duality between the time and frequency domains, that is, if we consider that x1 and x2 are two points of this signal, then we can think of y1 as the low frequency component. Notice that it is equal to twice the average, it is the part of the data that does not. t changes with time in the same way y2 is a high frequency component because it reflects the rapid difference when we go from x1 to x2 if we try to get away from just two numbers and take x as this signal with a bunch of points or even a mathematical function abstract with infinite resolution it may not be clear how to define the differences to obtain a meaningful alternative frequency representation something similar was probably going on in the mind of a great French mathematician jazza fourier when he was wondering if it is possible to decompose a function into a sum of sines and cosines for example, take a look at this function here, how do you think what combination of sines with varying frequencies when added would give us this graph?
wavelets a mathematical microscope
Well, it's certainly impossible to tell by the naked eye, but fortunately there is a mathematical operation called a Fourier transform that does just that and this was essentially Jazza Fourier's big idea that we can take any function and decompose it into a wavelet sum. pure with different frequencies, then the frequency domain will tell us the relative contributions of each. frequency to understand the function and the inverse Fourier transform allows us to go from the frequency domain to our original function. You can see that there are these two alternative representations of this same function, each function has an alter ego in the frequency domain and depending on what you are trying to achieve it may be easier to work in the time domain or in the frequency domain. frequently because you can always switch between the two.
The main limitation of the Fourier transform is that, although we gain knowledge about the frequencies present in the signal, we lose. all the information about the Fourier transform in time essentially squashes the signal in time to find the frequency components. A Fourier transform is a function only of frequency, but we don't know when certain frequencies start and when they end, for example, think about the signal emitted by a traffic. The light at first will be red for a while, which corresponds to an electromagnetic wave with a certain frequency in the visible spectrum, then for a few seconds it will glow yellow, which has a slightly higher frequency and finally for a while it will be green, which is a wave with an even higher frequency obtaining a Fourier transform of this signal will give us three peaks just indicating what frequencies are present, in fact we can see that the signal is made up of three colors red, yellow and green.
Now suppose the traffic light breaks and the order of colors gets messed up, for example it is yellow for 2 seconds, then green for 8 seconds, then yellow again for 1 second and then red for 9 seconds. If you look at the Fourier transform, you'll see pretty much the same image with the same three. The spikes corresponding to the color frequencies now mean that our traffic light is malfunctioning and all three colors light up at the same time and persist shining together, which would be a disaster for the road; however, the Fourier transform will continue to show the same three peaks due to the resulting waveform. is a sum of three colors, the frequency components are exactly the same as before, red, yellow and green.
So, hypothetically, if you receive hundreds of traffic light signals from all over the city and your job is to detect faults, the Fourier transform may not be a good choice. fits because it is completely time-blind and therefore may need other approaches to solve the problem. It's worth saying that the reason the Fourier transform sacrifices information about time is not because José Fujia wasn't smart enough to invent a better tool. blame the guy, it is actually fundamentally impossible to have perfect resolution of time and frequency simultaneously, there is always an exchange of information between the two, this is a manifestation of the Heisenberg uncertainty principle.
Time and frequency domains are two extremes of this uncertainty, you may know. exactly what value a function is at each moment, but at the cost of completely ignoring what frequencies are developing at that moment at the other end of the spectrum in the frequency domain, we know exactly what frequencies are present in the signal, but we don't know. We have idea about the temporal dynamics of them, but is there something in between? Any magic tool that would be a compromise between the two? What if we could sacrifice a little bit of time resolution and a little bit of frequency resolution to know something about? both and what is the optimal way to find that balance.
This is where

wavelets

come into play when we do the Fourier transform, we decompose a function into a sum of sines and cosines. These are called analysis functions because they form the basis for the frequency representation we are looking for. to our sign through trigonometric glosses, so to speak, to see everything as a sum of signs, but this is the thing about the sine function: it is more or less the same everywhere, no matter where you look, it It extends to infinity periodically and regularly, which makes it uncomfortable for time series analysis as we saw before, but what happens if we modify it a little?
We still need to oscillate up and down because this is the basis of frequency representation, but can we somehow constrain it in time and is this exactly the idea behind what is called a wavelet? transform is a mathematical tool that uses specialized functions called

wavelets

to analyze the signal. The key characteristic of wavelet is that it is a wave-like oscillation of short duration that is localized in time. In fact, only the term wavelet comes from French and literally means little. Hello, I think it's an incredibly cute name for a mathematical concept, but what is a wavelet mathematically speaking?
A wavelet is not just a function, it is a whole family of functions that satisfy certain requirements that we will discuss in a moment, there is a whole zoo of wavelets, each one is tuned for specific applications and can even design their own wavelengths tailored for purposes. specifics, so when two people talk about waylet analysis, they may not be talking about the same wavelets, generally speaking they are considered a proper wavelet, a psi function of t has to satisfy two main constraints, first First, it must have a mean of zero, this means that if you take the integral or the area under the curve where the function exceeds zero with a plus sign and the areas of the curve where it falls below zero with a firm minus sign and add them , should get zero, this is known as the admissibility condition and more formally it is worded that the raided function must not have a zero frequency component, but this zero frequency component is essentially the average value of a function.
Note that a familiar sign function also passes the admissibility condition because the combined area of ​​the positive peaks is equal to the area of ​​the negative valleys, so the average value of a sign is zero. This is where the second condition comes into play: the wavelet function must have finite energy and if you're wondering what the heck the energy of a function even is, don't worry, it's not as scary as it sounds. Basically this condition says that if you square the function and calculate the area under the curve everywhere from minus infinity to plus infinity it should be a finite number and this is exactly what makes the function localized in time , the sign squared is this infinite pattern that is above zero everywhere, so the energy of the sine wave is infinite, in contrast to our psi wavelet of t, which is localized in time when squared covers a finite area I should mention that the form I have been using for the proofs so far is called wavelet molet and is widely used for time series analysis;
It is defined as taking the cosine wave of a certain frequency and damping it by multiplying it by a Gaussian bell curve or at least this is the real component of the Morelet wavelet because the wavelet itself is a complex function, but we will get to the complex numbers and the imaginary component a little bit later in the video, for now you can think of this wet cosine as almost more. as a cool wavelet, so we have defined our little wavelet, but we can't really do anything with it, so let's see what the wavelet transform is all about when we calculate the Fourier transform, we convert our representation into the time domain and t, which is one-dimensional, a a representation in the frequency domain and hat of f which is also one-dimensional essentially there is only one knob that we can turn, so to speak, and that is the frequency of the sine wave f sub k y at each value of f sub k the resulting wavelet contribution of this frequency is calculated and that value is represented as y of f sub k The key difference from the wavelet transform is that our same one-dimensional function would now be represented as a two-dimensional surface where one axis represents the frequency just like in the Fourier case and the other axis represents time, therefore the value of our new two-dimensional function at a point t, the comma f represents the contribution of the frequency component f at time t, but does How do we get it right this time? two knobs, one for frequency and one for time, turning each of them will modify our initial wavelet function psi of t, which we call the mother wavelet to obtain new slightly modified versions of the mother wavelet called data wavelets, that is That is, by turning the time knob we translate o Move the mother wave along the time axis back and forth, so that when the value of the time knob is equal to b, the dashed wave is just psi of t minus b.
Turning the frequency knob allows us to shrink or stretch the mother wave along the time axes. It is usually convenient to think in terms of scales rather than frequencies, but they can easily be converted to each other if the scale is equal to a, then the dashed wavelet is just psi of t over a, for example if you stretch the wavelet in a factor of 2 its frequency will be 2 times lower because the number of cycles per second is now twice lower and, in the same way, reducing the wavelet increases its frequency. Now we can combine two modifications of the mother wavelet.
Let's define the scaled and translated wavelet like this and then the value. of our wavelet transform at a particular scale a and time b would be equal to the contribution of that scaled and translated wavelet to our signal, but what do we mean by contribution? Let's break that down a little bit essentially. You can think of this contribution as the Goodness of fit measures how well our modified wavelet matcheswith the signal at that time. Here are two examples. You can see visually that when the wavelet and the signal have similar frequencies, they alternately match when the frequencies of the wavelet and the frequencies of this signal are different the wavelet does not align very well with the signal mathematically we can describe this as follows, first Let's find where our signal and the wavelet coincide in signs, that is, we are going to use the color green to represent areas of the wavelet where it has the same sign as the signal, or both are greater than 0 or both less than 0 and the color red will represent where the signal and the wavelet have opposite signs.
Now let's multiply the wavelet function by the signal. Notice that all the red areas will now become downward facing peaks due to the sine difference and the green regions will all be facing up because when you multiply two positive numbers or two negative numbers you get something that is greater than zero, this way The shape of the wavelet is distorted and the heights of the green and red areas are scaled according to the signal value. As a final step, after multiplication, we find the total allocated area of ​​the product. This means that the area of ​​the green regions will be considered positive and the area of ​​the red regions will be considered negative and the total area of ​​green minus red is the answer to the question of how much a dura wavelet contributes to the signal because the Green shaded areas reflect good local similarity between the two, while red reflects where the wavelet does not. actually matches the signal, by the way, notice that what we did here was multiply two functions and calculate the integral of the product, while the integral is essentially the sum of infinitely many narrow rectangles with a height equal to the result of the multiplication in that In That time, do you recognize this operation of doing a bunch of pairwise multiplications and then adding everything?
Let's step away from functions for now and consider a pair of two-dimensional vectors. Each vector is essentially a list of two numbers x and y that specify your coordinates. You may remember from high school that for two vectors we can calculate what is known as their scalar product, it is a number that is equal to the product of the length of the vectors and the cosine of the angle between them. Intuitively, the dot product can be considered as a measure. of similarity between the vectors if we give personalities to our vectors, then the dot product is related to their relationship, roughly how close they are when they point in approximately the same direction, the angle is small and the cosine is close to one, which makes the dot product large and positive. this means that the vectors are similar and therefore quite close when they are orthogonal cosine of 90 degrees is zero and therefore the dot product is also zero.
This means that the vectors are independent and have nothing in common, they do not even recognize the existence of each other. when they point in more or less opposite directions the angle is greater than 90 degrees the cosine is negative therefore the dot product is also negative this means the vectors are somewhat anticorrelated and more importantly , opposed to the dot product, which again is just a number. can be calculated from coordinates, the formula for such a quantity is surprisingly simple: simply multiply the corresponding coordinates of the two vectors and add everything, so for a pair of two-dimensional vectors you multiply the x's, multiply the y's, and add the two numbers of the vectors in three. dimensions, you would need to add a z-coordinate product to the sum.
Increasing the number of dimensions surely makes it difficult to visualize what the angle between the vectors would be, but the intuitive meaning is the degree of similarity and the formula would remain the same. The same in the most extreme case, a mathematical function that has an infinite number of points can be considered a vector in an infinite number of dimensions, so if we replace the sum with an integral, which is the limiting case of the sum, we can defining a dot product between the two functions as the integral of their multiplication, that definition alone can certainly seem strange and intimidating, but when you realize that it is essentially exactly the same as the dot product between the vectors, it makes the formula is much less daunting and more intuitive, so what we calculated back then is exactly the dot product between the signal and the wavelet and remembering the geometric intuition of a dot product it makes perfect sense how this quantity reflects the similarity between the signal and the wavelet how well they match each other so far we have only calculated the contribution of a particular wavelet configuration with fixed parameters a and b, in other words we have successfully found a value of our two-dimensional function, let's keep the frequency fixed and gradually turn the knob of time to vary the parameter b, as you can see from this guy. of slides the wavelet through the signal for each value of b let's repeat the described procedure of calculating the dot product let's see what happens here I am taking the signal as the sine wave with increasing frequency at the beginning when the signal has a much higher frequency lower than the wavelet, you can see that the weight of the positive and negative contributions is more or less equal and the dot product stays close to zero, but as we slide the wavelet to the right, the signal frequency increases and approaches the intrinsic frequency of the wavelet when This happens, the functions begin to resonate and we get significant overall positive contributions when they are in phase and significant negative overall contributions when they are out of phase.
That's why the dot product at that time wobbles around zero and the amplitude of this is highest when the frequencies of the wavelet and signal match exactly, but as we move the wavelet further to the right it gets out of sync with the signal because the frequencies are again different, so the dot product also remains close to zero in the operation we did here. this slide in the dot product actually has a name, it is known as convolution, it is used very often and you may have seen it in image processing, for example, when you blur the image, now we can repeat the convolution procedure for other values ​​of parameter a to extract other frequency components and this is the essence of wavelet transform by varying the scale and translation parameters, we can scan our signal by analyzing wavelets of different scales to see which frequencies are most prominent around that point of time.
We have already seen that the result of convolution on a fixed frequency is in the form of a short duration oscillation because when there is a good frequency match there is a tug of war between the green and red shaded regions as we slide the wavelet at the beginning I told you that we want our two-dimensional function to reflect the contribution of a particular frequency at each moment in time, but right now this function doesn't really show that directly because if the value of the convolution at a given moment is zero , can mean that there is no such frequency in the signal at that timestamp, which is what we expect, but it can also be equal to zero when we are exactly in the middle between the peaks and valleys of the resulting oscillation of the values ​​of convolution, it does not mean that the frequency component right there is zero quite the opposite, since we want to measure the contribution of a frequency as a function of time to track when this frequency component begins, when it reaches its peak and when it ends, the intuition is take something like the envelope of the resulting oscillation.
Let's see, the only reason we got this wave oscillation as a result of convolution is because we used only the real component of the most directed wavelet. Now it's time to get rid of the almost and see what the waylet molet is really supposed to do. so let's talk briefly about complex numbers which are actually not as complex as they seem. You can think of complex numbers as the extension of a real number line. We are expanding the numbers to allow them to lie not only on a one-dimensional line but on a two-dimensional plane. This extension is done by introducing a special type of number called an imaginary unit or i, which is equal to the square root of -1.
Complex numbers consist of two parts, they have a real component and an imaginary component that we write. Since z is equal to a plus b multiplied by i, if we use the x axis to show the value of the real component and the y axis to show the imaginary component, we can think of any number as a point on the plane, you might ask, why what not just use? the vector or a list of two numbers x and y for this purpose you certainly can, but the great advantage of using complex numbers is that it makes certain operations with this plane easier to describe for our topic, we will focus on rotations.
Note that multiplying any number by i is exactly the same as rotating the plane 90 degrees around the origin once times i equals i i squared equals -1 by definition and so on and if you want to rotate the plane by an angle arbitrary we can use a convenient notation of complex exponentials, that is, when we write e to the power of i theta, this refers to the point on the unit circle at angle theta measured in radians counterclockwise and multiplying by e to the power of i by theta just means rotating the plane by the angle theta in In fact, the complex exponent is defined like this: this is Euler's famous formula.
You can see how convenient it is to use complex notation to describe circular motion. Simply raise the point e to the power of i multiplied by t and let t vary from 0 to 2 pi. this will result in a point that rotates in a circle, taking the real component of this complex variable you get a cosine curve with a set frequency and the imaginary component gives you the sine curve like this, the more that wavelet is essentially a complex exponent that rotates the circle with a certain constant frequency and whose amplitude is modulated by the Gaussian bell curve here is how it looks in three dimensions together with the two projections corresponding to the real and imaginary components, you can see that our familiar form of the damped cosine we use As a mother wavelet is in fact the real component of the complex molet wavelet and the imaginary component looks like the damped sine curve which is slightly shifted with respect to the cosine, the key idea is to calculate the convolution of the signal with real and imaginary parts, then our convolution function for a fixed wavelet scale will assign a real number, the translation parameter b, to the point on the complex plane where the real component is the convolution value at that time point with the part real part of the wavelet and the imaginary component is the value of convolution with the imaginary part of the wavelet the power of a frequency the intensity of its contribution at each point in time is given by the distance from the resulting point to the origin, which It is also known as the absolute value of the complex number as you can see, take the two-dimensional function as the absolute value of the convolution with the complex daughter wavelet, that is exactly what we said, it measures the power of a particular frequency component as a function of time and, as before, varying the parameter a allows us to analyze the signal at different scales, something like a photocopier scans the paper row by row, the resulting function is the complex function whose absolute value represents the contribution of a frequency particular around a certain point of time, we can represent it with color obtaining what is known as a wave scalogram, for example, let's see the result of the wave transform for a sine curve with increasing frequency from 0 to 30 hertz.
Plotting the resulting wave surface instantly tells us the expected dynamics: there is a gradual increase in frequency as time passes and the amplitude is practically constant and remember the example with malfunctioning traffic lights. By considering the temporal dynamics of the frequency components, something that was missing in the Fourier transform, we can detect anomalies by instantly returning to our brain signal, we can see how the wavelet transform can help us discover. In its structure there are three distinct episodes of low frequency rhythm with a gradual decrease in frequency and we can easily quantify the duration and frequency of each of those patterns, in addition, each of them is associated with several episodes of higher frequency rhythm and its frequency follows the bell.
So again we can objectively quantify all kinds of parameters, such as their frequency values, durations, the rise and fall of frequency modulation, etc., the possibilities are endless, there is one important thing left to do, remember we talked about balance inherent between time. and the frequency resolution that cannot both be known perfectly, the wavelet transform does not violate the principle ofuncertainty. If you look closely at the wavelet kilogram, you will see that even for a signal consisting of a pure wave, the resulting image does not look like an infinitely narrow bar as it would for a Fourier transform, instead, it looks a bit blurred because we will lose resolution both in time and frequency.
To know something about both, we can represent this compensation as what is known as Heisenberg boxes named after a famous physicist who formulated the uncertainty principle in the time-frequency plane. We will draw boxes whose side lengths will be proportional to the dispersion of values ​​or our degree of uncertainty about time or frequency, for example, in the case of raw time series, we have infinite resolution in the time domain, but we completely ignore the frequency, so the uncertainty tables would be practically vertical bars, the very narrow and tall Fourier transform, on the other hand, has perfect frequency resolution but contains no information about time and uncertainty boxes will be seen.
Like horizontal bars, the wavelet transform, on the other hand, offers an optimal compromise between extremes. It is designed in such a way that, for low frequencies, the uncertainty boxes are very wide and short; However, for higher frequencies, Heisenberg boxes are tall and narrow, if you think about it. It makes a lot of sense because generally low frequencies like 1 hertz tend to last a long time, so high temporal resolution is not important, but the value of the frequency, whether 1 hertz or 2 hertz, can make a big difference. Alternatively, the higher frequencies are usually very brief and localized. in time, so we need high time resolution, while we can commit to knowing the exact frequency value, whether it is 100 hertz or 105 hertz.
This is the intuitive explanation of how weed transformation solves the time-frequency trade-off. Let's recap in this video we have. I have seen how to build a type of mathematical

microscope

. The wavelet transform. This is a tool that allows us to interrogate a signal at different scales and discover its structure considering the frequency and time components. The wavelet transform has proven to be an invaluable tool for time series. analysis in many fields, including fluid dynamics, engineering, neuroscience, medicine, and astronomy. Hopefully the next time you see an image like this somewhere it will be less mysterious if you liked the video, share it with your friends, subscribe to the channel if you haven't already and hit the like button stay tuned for more interesting things that are coming, goodbye and thank you for the interesting knowledge you

If you have any copyright issue, please Contact