MATLAB Fourier Series: Evaluate & Tabulate 1st 8 Terms

Click For Summary
SUMMARY

The discussion focuses on using MATLAB to evaluate and tabulate the first 8 terms of a Fourier series. Users are advised to discretize their function over a range of more than 4000 points and utilize the ifft function to obtain coefficients. A specific example is provided for reconstructing the function using a for loop in MATLAB. Additionally, the discussion highlights the challenges of numerical integration when discretization is not performed, leading to dimension mismatch errors.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of Fourier series and coefficients
  • Knowledge of the ifft function in MATLAB
  • Basic concepts of numerical integration
NEXT STEPS
  • Learn how to use MATLAB's ifft function for Fourier series analysis
  • Research techniques for discretizing functions in MATLAB
  • Explore numerical integration methods in MATLAB, such as quad
  • Investigate optimization strategies for improving MATLAB code performance
USEFUL FOR

Students and professionals in engineering, applied mathematics, and data analysis who are working with Fourier series in MATLAB and seeking to optimize their computational methods.

morry
Messages
136
Reaction score
0
hey guys, I've got to do some Fourier series work using matlab, but I have no idea what to do.

Ive found the coefficients by hand, but now I need to use MATLAB to evaluate and tabulate the first 8 terms.

I then have to evaluate the series at 1000 points over a certain range.

Does someone know how to go about this?
 
Physics news on Phys.org
Discretize your function over the range to more than 4000 points (say) and store it in a vector.
Then use ifft(vector). You'll get the coefficients (if you want 1000, get the first 1000).

Suppose you have a cosine transform.

f=f0+2*f1*cos*(w*x)+2*f2*cos(2*w*x)+2*f3*cos(3*w*x)+...

ifft will give you these coefficients f0, f1, f2...

If you want to reconstruct the function by yourself in matlab, you'll have to code a for loop.

start with f=f0.

then a variable for from 2:(the number of components you want)
add to f
end;

I hope this is clear. You should do the same thing with the 8 modes you calculated by hand.
 
Thanks anaemic.
 
If I don't discretize my function, then, I have to find the coefficient by numerical integration.

quad(f,-1,1)

where my f depends on n (the index of coefficient). And Matlab just says something like "dimension mismatch". Do you guys know how to deal with it?


I can actually do it like this:

for n=-N:N
fexp=@(x) (x+2).*exp(i*pi*n*x);
c(n+N+1)=quad(fexp,-0.5,0.5);
end

but I don't like to do it like this because this method seems to take a lot of computer time.
 
Last edited:

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
27K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K