WEBVTT 00:00:00.000 --> 00:00:04.842 And then you just have to keep in mind, when you use that fft you'd better know 00:00:04.842 --> 00:00:09.377 that the fft is doing the shifting. And you could ask, well, why not, why the, why 00:00:09.377 --> 00:00:14.342 make it, why not shift it back? Why, why make me shift it back?" Cuz a lot of times 00:00:14.342 --> 00:00:19.430 when you're doing computation, you're not gonna necessarily go look at the spectrum 00:00:19.430 --> 00:00:23.965 all the time. You, the reason it stays shifted is because, remember, speed is 00:00:23.965 --> 00:00:29.635 everything. Speed is everything in terms of the computing. You want, if you got, if 00:00:29.635 --> 00:00:35.033 you got n log n speed, you wanna add you know, stuff on top of it. You can do that 00:00:35.033 --> 00:00:40.229 on your own time. With this computing, keep it at n log n, fast. Okay? In my last 00:00:40.229 --> 00:00:45.627 class, I talked in my last course, 581. I always tell people you may get the right 00:00:45.627 --> 00:00:51.859 answer. But it's wrong if you did it the slow way. Okay? Part of computing now is 00:00:51.859 --> 00:00:56.925 not just about oh, I can compute and I got this really, I got this method that can 00:00:56.925 --> 00:01:01.865 compute it right. It's not about that anymore, it's about not only can I compute 00:01:01.865 --> 00:01:10.877 it right, I can compute it faster than you. Okay. It's not that, it's not that I 00:01:10.877 --> 00:01:16.222 guess you know, competitive. But, but actually, you know it kind of is. If 00:01:16.222 --> 00:01:20.546 you're trying to write a paper in this area, that's what you're trying to say 00:01:20.546 --> 00:01:25.318 actually all the time. It's like oh, I can compute this faster than you can. And here 00:01:24.925 --> 00:01:29.698 is why. Okay? That's, that's how you write a paper in scientific computing. You tell 00:01:29.698 --> 00:01:33.853 people how much awesomer you are. Okay? Alright. But, see, the nice thing with 00:01:33.853 --> 00:01:38.064 your data analysis skills, you might be working, I don't know, in atmospheric 00:01:38.064 --> 00:01:42.331 sciences or geology geologoy or something. With your skills you'll be able to say how 00:01:42.331 --> 00:01:46.947 much better you are also. See, then I'll, then we'll all have won. Okay? Alright. So 00:01:46.947 --> 00:01:52.459 there you go. that's the simple implementation. Now I'm gonna use it to do 00:01:52.459 --> 00:02:00.542 a trick. Okay? Yes? So, the actual coefficients are positive and negative 00:02:00.542 --> 00:02:04.327 alternating. This is. Yeah. This is the absolute value. If it's complex you know, 00:02:04.807 --> 00:02:09.373 most people, by the way, when you get a complex spectrum, what you normally do 00:02:09.373 --> 00:02:13.878 what people call the power spectrum. I don't know if you've heard this. Okay? 00:02:13.878 --> 00:02:18.864 Well that's an aggressive word just like the competition. It's all, it's all like 00:02:18.864 --> 00:02:23.790 smackdown for comp, computing. So the power spectrum is always the absolute 00:02:23.790 --> 00:02:28.535 value of the spectral content, cuz that's what you want to know is how much 00:02:28.535 --> 00:02:34.313 frequency content, not necessarily what phase it's in. Okay? Alright. So, there's 00:02:34.313 --> 00:02:42.284 that. And now, for my next trick, I will differentiate a function, computation. Are 00:02:42.284 --> 00:02:46.054 you ready? I, I don't know if you guys are ready. Let's, can I have the lights on 00:02:46.054 --> 00:02:53.055 real quick, upfront? There's this very nice relationship, that's actually worked 00:02:53.055 --> 00:03:07.968 out in the notes, which says the following. It says the following, the hat 00:03:07.968 --> 00:03:13.520 represent Fourier transform by the way, and this represents the nth derivative. If 00:03:13.520 --> 00:03:19.521 I take the nth derivative of a function and I wanna find what that is, the Fourier 00:03:19.521 --> 00:03:24.290 transform of the nth derivative is the same as taking the function itself, and 00:03:24.290 --> 00:03:29.662 Fourier transforming it, and multiplying by ik to the nth power. Okay? So if I want 00:03:29.662 --> 00:03:34.318 to compute the third derivative, all I gotta do is take the function, Fourier 00:03:34.318 --> 00:03:39.981 transform it, multiply this by k^3 inverse Fourier transform it. That's it. By the 00:03:39.981 --> 00:03:43.742 way, this is one of the most, if, if your boundary conditions work for you, like 00:03:43.742 --> 00:03:47.797 here the boundaries go to zero, right? And there's supposed to be a periodic 00:03:47.797 --> 00:03:51.264 function, but here the boundaries are pretty much going to zero. This is 00:03:51.264 --> 00:03:55.123 probably one of the most accurate ways you can compute a derivative, spectrally 00:03:55.123 --> 00:03:58.738 accurate. Okay? So let's compute a derivative, and here's the thing I'm gonna 00:03:58.738 --> 00:04:04.212 compute. oh actually, we can go back with the lights down. Okay. So I'm gonna take 00:04:04.212 --> 00:04:10.754 this function u here. and I'm gonna do the dollowing function. Here is my favorite 00:04:10.754 --> 00:04:16.031 function, hyperbolic secant x. I don't know if you have a favorite function yet. 00:04:16.031 --> 00:04:20.543 It's just a little bit of time before you graduate to pick one out. This one's taken 00:04:20.543 --> 00:04:27.060 by the way, don't even try. and by the way. its derivative, it's called ud is 00:04:30.420 --> 00:04:35.758 sech * tanh. Now what I'm going to do is try to compute t hat derivative 00:04:35.758 --> 00:04:41.173 accurately. And by the way, second derivative, let's call it ud2 for the 00:04:41.173 --> 00:04:47.564 second derivative will be sech x - two * sech x^3. something like that, pretty 00:04:47.564 --> 00:04:54.987 close. I think I actually have it in the notes here. sorry, give me just a second 00:04:54.987 --> 00:05:02.590 here. yeah, actually yeah, that's right. Okay. and what I'm gonna do is, now, 00:05:02.590 --> 00:05:07.833 compute these derivatives using my Fourier transform. So let me write at the top. 00:05:07.833 --> 00:05:13.197 There is u, second or first derivative. And first of all, if I wanna calculate the 00:05:13.197 --> 00:05:18.256 derivatives, first I have to have Fourier transform of the function. There it is and 00:05:18.256 --> 00:05:23.288 I'm gonna calculate now the first derivative. Okay? So, to calculate the 00:05:23.288 --> 00:05:31.200 first derivative, remember, what I gotta do is take i * k and multiply it by 00:05:33.360 --> 00:05:39.114 Fourier transform. There it is. And then, what I gotta do with this is inverse 00:05:39.114 --> 00:05:44.793 Fourier transform it. Right?'Cuz Cuz what this is, is the derivative of the it's the 00:05:44.793 --> 00:05:50.926 Fourier transform of the first derivative. So what I can do is just say, okay, if I 00:05:50.926 --> 00:05:57.362 want the first derivative, let's call it my ud s for spectral approximations, first 00:05:57.362 --> 00:06:03.495 derivative is spectral is ifft. By the way that's how you invert a Fourier transform, 00:06:03.495 --> 00:06:12.405 ifft and fft are the pairs. Okay? And by the way, the second derivative, let's call 00:06:12.405 --> 00:06:21.620 it ud2s is equal to ifft of i times k. That being squared now, times ut. There 00:06:20.920 --> 00:06:29.817 you go. I, I want to call this u, right? So I'm kind of done. So, let's make some 00:06:29.817 --> 00:06:38.401 plots. I'm going to plot here the function and for short here I'm going to say, call 00:06:38.401 --> 00:06:46.600 it ks for k shift will be the fftshift(k) and so that way I can make this be just, 00:06:47.540 --> 00:06:52.575 first I'm gonna plot the function. And then I'll plot, in addition to the 00:06:52.575 --> 00:06:58.587 function, I'm gonna plot the derivative of the function, so x versus ud. And my 00:06:58.587 --> 00:07:03.923 approximation, let's plot that in a red line and then I'm gonna plot my 00:07:03.923 --> 00:07:16.098 approximation to the derivative uds, and I'll plot that with magenta circles. what 00:07:16.098 --> 00:07:20.857 I'm plotting is here is the exact answer, right there, x, ud, that's the exact 00:07:20.857 --> 00:07:27.262 answer and I'm plotting my approximation to the exact answer. Oh, that's just the 00:07:27.262 --> 00:07:30.978 original function. We don't have to have that in there. Would you like to take it 00:07:30.978 --> 00:07:36.301 away? We can just do that. What's that? Oh that was the fft, yeah we don't want the 00:07:36.301 --> 00:07:41.323 fft of the original function. We just want the function. Oh, by the way. There you 00:07:41.323 --> 00:07:45.732 go, look at that. The red line is exact, the magenta line is my approximation. Who 00:07:45.732 --> 00:07:49.805 likes that approximation? Give it up you all. Okay. So listen, I know it's the 00:07:49.805 --> 00:07:54.440 first day of class, we're just warming up. We'll have a dance party about midway. We 00:07:54.440 --> 00:07:59.051 can get disco balls and you know, we can shine that light on there. It's pretty 00:07:59.051 --> 00:08:03.433 sweet. Okay. Alright so there is my approximation. By the way, let's zoom in a 00:08:03.433 --> 00:08:07.816 little bit. Let's just see how well we really did. Let's see how long it takes 00:08:07.816 --> 00:08:12.255 for that magenta ball to fall off. Oh, oh, oh, oh, come on, fall off. I'm zooming in, 00:08:12.255 --> 00:08:16.695 I'm zooming in, I'm zooming in. Look, it's pretty dang accurate. Look at that. Oh, 00:08:16.695 --> 00:08:21.248 it's finally coming off there. I know it, I can sense it. Oh, look at that. But look 00:08:21.248 --> 00:08:25.708 over here on the left, it's like down to ten minus five or negative six. Pretty 00:08:25.708 --> 00:08:30.190 amazing accuracy. Now, you can screw up. Let me just show you one other thing. 00:08:30.190 --> 00:08:37.507 Suppose I take a smaller domain. Oh, not quite hold on a little smaller just real 00:08:37.507 --> 00:08:45.004 quick. Just give me two seconds for the final. Oh, crap. Okay. Come on. Let's do 00:08:45.004 --> 00:08:50.177 four. wanna, I wanna, I wanna show you what happens when you kind of start to 00:08:50.177 --> 00:08:55.338 violate, yeah, there you go, you start seeing it. Now, notice what happens here? 00:08:55.338 --> 00:09:00.143 Here, remember it's supposed to be a two pie periodic function. Right? This is 00:09:00.143 --> 00:09:04.884 clearly not periodic. Before they both went to zero, you could say kinda looks 00:09:04.884 --> 00:09:10.006 periodic. Here, it's up here above point two here. It's below negative point two. 00:09:10.006 --> 00:09:15.123 There's a jump and any time you have a jump in a Fourier transform, when you try 00:09:15.123 --> 00:09:19.255 to represent, you get what's called a Gibbs' phenomenon, which is oscillations 00:09:19.255 --> 00:09:23.911 near the jump and this is what you see over here. So it does amazingly well here 00:09:23.911 --> 00:09:28.450 and over here it starts to oscillate, not so well. Okay. We're gonna use this on 00:09:28.450 --> 00:09:34.876 Friday to do radar problems. Okay. Ha ve a good Wednesday. See you guys soon.