Inspired after seeing a cool Youtube video of Fourier series... How do I implement a Fourier series for an irregular non periodic curve?
8 次查看(过去 30 天)
显示 更早的评论
Firstly, this is the Youtube video What is a Fourier Series? (Explained by drawing circles) - Smarter Every Day 205 from channel SmarterEveryDay.
I could understand the model for creating the square wave. I think it is easy too because we have a function to implement the code.
![fourier series.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199844/fourier%20series.png)
But, How can one implement a model for a curve which is non periodic which does not have a function?
For example, At the end of the video, it shows a fourier series for a curve like in the picture below, He is definetly using 2 Dimensional fourier transform.
![Screenshot (55).png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199845/Screenshot%20(55).png)
So, I took time trying to implement the Idea and this is how far I have come.
>>>>>>I took the picture of my profile and traced the edges into 3 ranges and concatenated them into a vector. So, when I create a functon, It can start to trace like shown in the picture below.
![ADDY final.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199846/ADDY%20final.png)
>>>>>>I thought 2D Fourier transform would be difficult, so I went for 1D first. I tried for implementing the idea for the 3 ranges separately. I used the curve fitting toolbox to approximate the curves.
![Range 1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199847/Range%201.png)
![Range 2.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199848/Range%202.png)
![Range 3.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199849/Range%203.png)
>>>>> I used 8 order fourier terms to get the fits as shown on the picture above. 8 was the maximum I could get.
>>>>> For Range 3 the fit was perfect. but for complicated shapes like Range 1, the maximum fit of 8 terms wasn't sufficient.
>>>>> From the picture from youtube, you can see that he goes for more than 40 terms. Then he gets more perfect fit for orders 200 or so..
Finally, how can I get to higher orders inspite of curve fitting tool allows only 8?
Is there any other way that I can approach this problem?
If i could slove this, I have ideas to implement this algorithm scientifically for various other purposes.
Kindly help me regarding this problem.
3 个评论
Rik
2018-12-28
I'll try to get you going, but the code below shows what I mean by splitting it into two functions
x=Ranges_Concatenated(:,2);
y=Ranges_Concatenated(:,1);
t=1:numel(x);
figure(1),clf(1)
plot(t,x,'b','DisplayName','x-coordinate')
hold on
plot(t,y,'r','DisplayName','y-coordinate')
legend
I usually use fminsearch, but that tends to have trouble to find a good solution if your initial guess is too far off. Of course you could use fft directly to solve this, but that would be cheating. ;)
采纳的回答
Rik
2018-12-28
First I misunderstood it a bit: I just let Matlab figure out the desired wavelenght as well, but that turns out to be quite tricky, and it doesn't work well either. The plots shown below were made with the attached code. The two left plots are only for the x component, but I'm sure the y will show something similar.
![result.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/199860/result.png)
4 个评论
Rik
2018-12-28
You are very welcome.
I wanted to take a shot at it when I saw the video come out, but I never came round to it, so thank you for giving me the final push to try it out (and handing me a usable trace to work with).
The next part should be fun as well: how to animate the circles? If you take a shot at that as well, let me know in a comment here so it shows up in my activity feed.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!