The Mathematics of Signal Processing | The z-transform, discrete signals, and more

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video was sponsored by dashlane what you see here is an audio signal of my voice which is something I'll say later on and this here is a high-pitched pure tone that's much louder than my voice we'll analyze these closely in a few minutes but for now realize combining these two signals into one isn't hard mathematically we just add the signals together where you'll see the resulting audio is dominated by the pure tone which when zoomed out like this just looks like a blue wolf the hard part mathematically though is taking this and getting my original audio back no you can't subtract because we'll assume we don't know how strong that tone originally was but there is a way to extract the noise or tone in this case and get the original audio back the math behind what just happened is where we're headed this is also going to introduce a field of study that I think I'm safe to say most people have never heard of before which also includes some math that most people will never learn even though isn't a stem-related major but to begin all we're gonna do is simply plot a parabola in a way that's different from usual and then from there it's going to get much more technical now so stay with me if we have the equation X plus 1 times X minus 2 it will of course be a parabola facing up with zeros at 2 and negative 1 but think about it like this instead first on our plot I'm going to label the zeros with 2 circles then for any arbitrary X this first term is really just the distance from x equals negative 1 that I'll label d1 so if X were 3 then this term would output 4 to see this graphically we can put a dot at x equals 3 and see that the distance from negative 1 is 4 then the second term in the equation is just the distance some arbitrary x-value is from 2 and that gets multiplied by d1 so on the graph for some X like we see here we find the distance from negative 1 or 4 and the distance from 2 or 1 we then multiply the results and this tells us our y-value for that given point which would be 4c that's all any y-value really is just the product of the distances from the zeros when we slide that coordinate over and one of those distances becomes zero then the product does as well which is another way to see why this point has a y-coordinate of 0 afterwards d2 is considered negative so we get negative y-values and from there we just sweep out the entire function taking the products at any X and mapping to the corresponding Y which of course makes a parabola but now let's turn this into a rational function by dividing the same equation by X for example giving us this plot in order to graph this like we just saw we still for any x coordinate have to find the distance from x equals to x the distance from x equals negative 1 but now this is all divided by the distance from x equals 0 and that will output our y coordinate so on our graph 2 and negative 1 are the zeros again and 0 would be the asymptote but instead I'm gonna call it a pull and label it with an X for x equals 3 we have two of those same distances 4 and 1 but the Y value isn't 4 because we still divide by the distance from the origin or 3 and this is why the y coordinate is 4/3 at that point then since the closest thing to our point is a 0 as we slide towards it that will quote win that shrinking distance here makes the entire output go to 0 due to the multiplication after that we slide closer to the pole and that will quote win remember we're dividing by this distance and when it shrinks to 0 we're dividing by a smaller and smaller number sending the output to negative infinity in this case aka an asymptote okay so you guys good with that pulls and 0 is just referred to asymptotes and well zeros then the distance from those tells us the Y coordinates now slight transition here but we'll get back to that in the real-world signals often come with a lot of noise or like when dealing with stock market prices the variations can make it look very noisy so one thing need to get a more general trend is to take a moving average where you take some number of data points and find the average of consecutive ones then just keep sweeping through the points keeping track of the average as you go with stocks for example this can smooth things out and remove brief drops or gains that aren't as meaningful when it comes to long-term changes so let's actually do this for a cosine curve to do so I'm going to take samples of the signal at equal intervals I can do this in many ways though like I could sample for points at a time find the average for those y-coordinates and plot that value then slide one over take the average of these four and keep sweeping through the function I could also do this for five points at a time or three and so on then another thing I could change is the frequency that I sample at but to keep it simple we're going to sample every pi over 3 radians that's how spaced each interval will be this makes math easy because these would then be the Y values of each point will be averaging two samples at a time for simplicity as well but here's what's important to remember a virgin two samples can be written as the output of some arbitrary sample plus the previous all over two like it N equals two this is saying take the second sample plus the first and divide by two and then when N equals three we averaged the second and third sample and so on I know it's kind of weird to say that X of n refers to the Y values but I do need to keep it like this because Y of n is going to refer to the average itself that will calculate this equation will show up again so just keep it in mind okay so finally to get to it the average of the first two samples is 0.75 and I'm going to plot these averages on a graph below then the second and third sample of plus and minus 1/2 average to 0 of course and I'll just plot a few more values where we get minus 0.75 minus 0.75 0 and 0.75 this pattern would continue forever so we get a periodic discrete function from here we can connect the dots to get a sinusoidal function back one with an amplitude of rad 3 over 2 and it's got the same frequency as the function above now I want to emphasize this here we can connect these dots with several functions whether it be a sinusoid a square wave or something weirder but the rule here is that the output must have at most the same number of sinusoids as the input as then we only have one sign you saw it here which means we got to have one here as well for those that know what the Fourier series is you know for example a square wave is made up of infinitely many sinusoids so that can't be the output since infinity is well more than 1 and you'll note that this function is as simple as it gets if I change the amplitude then we won't cross all the points and the same thing happens if I lower the frequency now if I increase the frequency we do eventually cross all the points again but the output frequency must match the input so we just stick with this the most important thing to remember is that when doing a moving average sampled every PI over 3 radians the output samples lie on another sinusoid with an amplitude of rad 3 over 2 these two numbers are the most important so much so that I'm going to keep them on the screen now I'm going to lower the sample frequency of the top graph to every PI over 2 radians and if we average every 2 samples again what you'll find is the outputs will go back and forth between 0.5 and minus 0.5 the simplest curve that connects these is also one sinusoid with an amplitude of RAD 2 over 2 this will also keep track of lastly I'm going to lower the sample frequency again to every pi radians and now the average of any two neighboring samples is zero even if we offset the samples the averages remain zero the sine you put that connects these obviously as an amplitude also of zero and the sampling of pi radians leading to that amplitude is the last thing I'll keep on the screen because now things are going to start to come together and we're going to use the unit circle to see how first we're gonna put these angles where they belong on the circle so like PI over 3 goes here PI over 2 at the top and then pi radians is on the left so the angle is essentially our input and those amplitudes are the corresponding outputs which means pi would be the 0 since its output is 0 and thus I'll represent it with a circle just before now remember from the parabola of the distances from the zeros we're used to find the output well on our circle here the distance from the point at PI over three let's say to the zero is the square root of three twice the output at that point and the distance from the point a PI over two to the zero is a square root of two also twice the output at that point this will in fact always be the case for any point on the circle where the angle represents the sampling interval of our cosine curve the distance from that point to the zero divided by two yields the output of the reconstructed signal for a moving average done two samples at a time now keep track of just these first two averages as we sweep the Blue Dot around the circle this increases that angle and thus the sampling interval but it also decreases the distance from the zero which means the output amplitude will decrease more and more as we move around the unit circle until we eventually reach the zero now before we saw that the distance to a zero can simply be written as X minus that zero well here we're going to do the same thing except we're not moving along the x axis so instead I'll call some arbitrary point Z instead of X and the distance to the zero at negative one would just be Z minus negative one or Z plus one pretty much just think of Z as a vector because now the vector Z plus the vector 1 comma zero gives us an output whose magnitude matches that distance so this does work but remember it's half that distance which gives us our output amplitude that I'll just call Y of Z then also like before and let's see what happens when we add a pull at the origin or simply put a Z in the denominator the new outputs will now just be the same things divided by the distance from the origin but that distance is 1 and always will be as we sweep the circle so adding a pole for our purposes doesn't change anything the last thing I need to mention is that the input I was sampling this whole time always had an amplitude of one but had I changed it to like two then the output would have doubled as well so really this equation gives us the ratio of the output amplitude to the input amplitude they'll write as X of Z when that amplitude is one then we don't need to include it but in general it does need to be there so now check this out I'm gonna write that same expression up here and rearrange some terms first I can divide both the top terms by Z giving us one half times one plus Z to the minus one and then I'm gonna multiply both sides by X of Z giving us this but I'll distribute the X of Z inside the parenthesis now anywhere I see X of Z or Y of Z alone I'm going to change it to X of N or Y of n respectively then just go with me here but by a certain mathematical transform I'll mention in a sec anywhere there's a Z to the minus 1 X of Z that will become X of n minus 1 the minus 1 is there because that's what the exponent was on the Z those must match and the 1/2 can be written on the bottom like this so hopefully you recognize this it's what I said would show up later this is the actual arithmetic of the moving average summing two samples and dividing by two so the arithmetic we perform on the samples shown on the right and the equation that told us the distance from the zeros and poles here on the left along with the corresponding plot are directly linked by something called the Z transform for those that know what the Laplace transform is this is the discrete version now we can more quickly see what other kinds of sampling we'll do like if I want to do a moving average with four samples at a time then the arithmetic would be this here summing for neighboring samples and dividing by four now doing the same thing backwards will change the x and y of n to x and y of Z when there's a minus one the Z transform makes it Z to the minus One X of Z then negative two and negative three do the same thing with those corresponding exponents then since there's an X of Z in every term I can divide that out and lastly I'm just going to remove the negative exponents by multiplying by Z cubed to the top and bottom this is the function that tells us everything we need to know the zeros are negative 1 I and negative I those will make the numerator 0 and the poles are only at Z equals 0 the origin so I'll put those on our unit circle plot from before the plus or minus I do go on the y axis as that's really the imaginary axis when dealing with pole 0 plots then for any sampling interval denoted by the angle if I multiply all the distances from the zeros then divide by the distances from any poles and also divide by 4 because it was there in the denominator that will tell me the output amplitude of the reconstructed signal for a 4 sample moving average the 0 here at PI over 2 means as we slide towards that the output amplitude also goes to 0 which we can see here since the average of any four neighboring samples now is 0 now I've been using one sine you sway this entire time of one specific frequency but that's really all we need in order to analyze any signal because look at what happens when we add two sinusoids together to get a more complex function and sampled that at some arbitrary rate if I do a two point moving average the outputs oscillate between 0.5 and minus 0.5 as shown the simplest sinus way that goes through these is one with an amplitude of RAD 2 over 2 and a frequency that matches the first graph the second function has been completely filtered out and that's because sampling the third function is like sampling the two that make it up at the same rate than adding the results for the first one the average of any two samples is 0.5 or negative 0.5 which is exactly the same as our graph on the bottom so that yields the rad 2 over 2 curve in any two neighboring samples on the second plot output 0 which is why that was filtered out add those up and we get the final output now time for a huge correction I need to make this entire video I've been using a really convenient sinusoid to make things work while I change the sampling interval but had I used basically any other input frequency everything would have fallen apart however one small change will fix that instead of this dot and the angle representing the sampling interval consider those fixed I'll just say at this rate meaning they can't get any closer so moving the dot around the unit circle now corresponds to changing the frequency of the input sinusoid as shown now once we get to PI over two we still see essentially the same thing we have four samples per cycle and any to average to 0.5 or minus 0.5 yielding an amplitude of RAD 2 over 2 that hasn't changed instead we just changed the input frequency to line up with the samples and as a result the output frequency changes as well but the output amplitude behaves the same as before and as we keep going around the circle we approach the 0 where again we see two samples per cycle which always average to zero this point will actually always correspond to your input doing one cycle for every two samples whereas the top is one cycle for four samples and these are known as normalized frequencies anyways you'll notice that the higher frequency signals relative to the sampling get reduced a lot or completely removed whereas lowering the input frequency causes the input to not get affected as much that's why a two point moving average is also considered a low-pass filter we can put in some function but instead analyze the sinusoids that make it up and how those will be affected you'll see the lower frequencies on the top get reduced a little or are allowed to pass while higher frequencies on the bottom get reduced much more then we just sum those up and get the output of the moving average in fact I'll undo the filtering real quick and you can see the higher frequency oscillations here get removed as we apply the filtering transformation and no matter what a signal looks like it can be broken up into sine and cosine functions which we can analyze individually the spectrum of those frequencies is known as the frequency spectrum which is way more useful for complicated functions and one example of a complicated function would be an audio signal of someone talking like you can see here if we zoom in it looks sinusoidal like but it's also very chaotic however even this can be made up of sine and cosine functions of just different amplitudes and frequencies see if we have a single sinusoid this consists of just one frequency in terms of the audio it corresponds to a single tone so if we made a plot of which frequencies are present we just see a spike at 500 Hertz in this case the frequency of our signal this would be the frequency spectrum for two sinusoids the function and time looks more complex but the frequency spectrum would just be two spikes for the two frequencies that audio signal would sound like well two tones my audio signal on the other hand is made up of infinitely many frequencies an entire spectrum which the program I use audacity has the option to plot as you can see most of the tones that make up my voice are in this region between about 120 Hertz and a thousand Hertz if my voice was deeper those would be shifted to the left towards those lower frequencies or pitches the peak spike here is around 460 Hertz but there are in flee many tones in my voice as you can see like even some random number such as two hundred and twelve point eight seven Hertz that tone is in here it's a very tiny portion technically infinitely small but it's still there so no we don't speak in tones however anything that we say can be constructed by stacking implementing tones on top of one another and adding them up but now what I'm gonna do is combine my audio signal with a pure tone of a specific frequency that's much louder than my voice as you can see if i zoom in on the tone it just looks like a sinusoid whose frequency in this case is a thousand Hertz so when I combine them we get this where that obnoxious tone is very apparent and okay you get the idea something to notice though is that if i zoom in on the section in the beginning before I start talking we just see the tone as expected but if I scroll to the right a bit we start to see these little variations those are caused by the signal of my voice which was much lower and amplitude but either way my audio is still there making those changes if I select the portion where I'm talking and we observe the frequency spectrum we should see just about the same thing as before but now there should be this higher peak right at 1000 Hertz indicating something of that frequency is dominating our signal as we know that it is see the frequency spectrum is much more useful than looking at the signal in time and that's because the frequency spectrum allows us to do this kind of forensic analysis on the audio signal to see what really makes it up but now what I want to do is remove that pure tone so we can get back the original audio so we have this messy signal that is made up of my audio which we want to keep and a pure tone we want to get rid of does this remind you of anything we've seen already where a complex looking function made up of other frequencies ended up having one of those removed by some kind of filtering well yes the idea is if we sample a signal and do some manipulation with those samples like a moving average we can alter or in this case remove certain frequencies that make up the function but not others if the sampling has seemed kind of random this whole video I've got some news the signals I've been showing are really sampled signals sampled at a constant rate this is a discrete signal and it's used because computers can't represent continuous signals that have infinite information after analysis with these is complete then continuous signals are reconstructed but when it comes to applying this discrete signal manipulation audacity makes it easy as they include filters where I can just remove or amplify the frequencies that I want what this will do is significantly reduce frequencies at and slightly around 1000 Hertz but do nothing to the rest and when we apply a filter we see the selected region has revealed the original signal while the tone seems to be gone on the other hand I didn't highlight these sections which is why the tone is still there but now let's listen to our newly filtered signal one example the complicated function would be an audio signal of someone talking like you can see here hey that sucked I mean my audio signal was easier to hear but it was really distorted and just wasn't good so what's going on here well for one in the original audio signal which we saw a spectrum of there were tones at a thousand Hertz and around it so when we applied that filter which remove frequencies around a thousand Hertz that removed some of the original audio which would cause Distortion then the other thing to note is that digital filters are never perfect they don't do exactly what you want them to do I mean there are other reasons why the program wouldn't do what we wanted but in general you can't make an ideal filter in engineering there's always trade-off where you get more of this one thing but less of another in fact let's try to build the filter we just saw using the pull and 0 plots from before because this is where it gets more fun if there's a specific frequency I want to remove I just need to put a zero at or near that point on the unit circle and I'll put a pull along the same line but slightly closer to the origin also these all come and conjugate pairs by the way so I got to include those down here as well the reason for these locations is now for most frequencies the distance from the zeros divided by the distance from the poles is roughly one which I'll plot the output amplitude wouldn't really change now since all the points along the unit circle corresponds to a specific frequency I'll let that be my x-axis and as I sweep around tracking those distances we get what the output amplitude would be it's mostly one but at this frequency here and around it it's closest to a zero and that will as I said before when sending the output close to zero then afterwards it goes back to about one this should look familiar and it's known as a notch filter then from the locations of the zeros real and imaginary I can construct the numerator of the z-transform equation where the solutions to this the zeros would match what we saw then from the location of the poles I can create the denominator whose solutions would be those values hopefully this shows why those came in conjugate pairs by the way it's because we need real coefficients in this equation from here we can apply the reverse transform and convert all the X of Z's to X of ends and all that we saw earlier which finally tells us the arithmetic to actually perform on the samples that will accomplish the filtering we want so now let me just put this all together to give you the big picture real-world signals which for the most part continuous often need to be altered in some way whether it be filtered amplified reduced or whatever and this is often done digitally based on what we want to do we can create a pole 0 plot where distances at different points on the unit circle tell us how different frequency inputs will be affected the locations of those zeros and poles which are usually complex will be the solutions to the numerator and denominator respectively of our transfer function which is needed cuz with some Z transform math we can then get the difference equation that tells us what to actually do to the samples in order to accomplish what we want like you would program the computer to take a sample and multiply by 0.9 subtract 1.0 2 times the previous sample and so on even previous outputs are used to create the next output it seems random to do this but after the original continuous signal is sampled and we sweep through those applying that seemingly random arithmetic outcomes new samples which when reconstructed yield a new signal that has been filtered as expected by the frequency response in this case with one frequency or the pure tone being reduced nearly to zero and this is where the design comes in because now we can move the poles and zeros around and see exactly how the frequency response will change as a result having the poles closer to the unit circle than the zeros makes us that only range of frequencies don't get reduced here's pretty much the moving average filter we saw before which allowed lower frequencies to pass and we can make much more advanced low-pass filters bandpass filters and so on little tweaks can have big effects on the response but overall changing pole-zero locations will change your Z transform equation and from there you just do everything we went over to get your new desired output in analog systems changing a filter may come down to turning a knob to increase resistance or swapping out physical components but all we have to do here to change the filter is maybe change a number in our code that is the power of digital signal processing an entire field you could get into or a job title you could have beyond what I've said here this applies to image processing radar and sonar speech recognition music financial data cell phone transmissions and much more basically anywhere digital signals are used you can apply this for all the young or soon-to-be electrical engineers out there if you look at your course catalog you'll see something like discrete-time signals and systems or digital signal processing where the z-transform digital filter design sampling and more are covered at my school only the electrical engineers were required to take this however the computer engineers had to take the prerequisites called continuous-time signals and systems and then some of them did take digital signal processing but that was as an elective at other schools that one surprised me if other majors were required to take at least one class on discrete signals but at my school is just the EDS overall the combination of math and programming like you saw here interests you then this would definitely be something to look into but lastly I want to thank the sponsor of this video - Lane a company dedicated to protecting your digital information - leah is a password manager that actually does several things when it'll safely store all your passwords all in one place and sync them between devices so you never have to deal with resetting all those passwords you made months or years ago that you can't remember with this - lean will also autofill usernames and passwords for any site you have stored in there making it just a little easier to navigate the internet something more important than remembering passwords though is having secure passwords and being safe from hackers which dashlane takes care of we're totally shouldn't store the same password for different sites since being hacked in one place makes you vulnerable elsewhere and dashlane that is solved as you have the option to have them auto-generate very secure passwords to be stored and used across all your devices you will have one single master password that you create when you sign up for dashlane and that is used to encrypt all others so even if someone were to gain access to internal servers they would just see gibberish you on the other hand can feel safe knowing you have different and very secure passwords for each site yet all you have to do is remember one single password plus your add security they'll notify you if any of your data has been compromised to give you a complete peace of mind as you browse the Internet pricing is already really cheap but if you sign up at the link below or to go to - link home slash major prep you'll get 10% off your premium subscription plus there's a 30-day free trial so no risk and just giving it a try again links are below and with that I'm gonna end that video there you guys enjoyed be sure to LIKE and subscribe don't forget to follow me on Twitter hit the bell if you're not being notified and I'll see you all in the next video
Info
Channel: Zach Star
Views: 417,921
Rating: undefined out of 5
Keywords: majorprep, major prep, digital mathematics, discrete mathematics, discrete signals, discrete signal analysis, the z transform, what is the z transform, applications of the z transform, signal analysis, fourier, fourier analysis, laplace transform, applied mathematics, signals, communications, digital signal processing, dsp
Id: hewTwm5P0Gg
Channel Id: undefined
Length: 29min 47sec (1787 seconds)
Published: Thu Oct 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.