MATLAB Fourier Series: Evaluate & Tabulate 1st 8 Terms

In summary, the conversation discusses using MATLAB to evaluate and tabulate Fourier series coefficients and then discretizing the function over a certain range. The participants also mention using ifft to get the coefficients and using a for loop to reconstruct the function. They also discuss an alternative method using numerical integration, but note that it may be time-consuming.
  • #1
morry
136
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
  • #2
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.
 
  • #3
Thanks anaemic.
 
  • #4
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:

FAQ: MATLAB Fourier Series: Evaluate & Tabulate 1st 8 Terms

What is a Fourier series?

A Fourier series is a way to represent a periodic function as a sum of sine and cosine functions. It is named after French mathematician Joseph Fourier and is commonly used in mathematical analysis, signal processing, and other fields.

How do I evaluate a Fourier series in MATLAB?

To evaluate a Fourier series in MATLAB, you can use the "fourier" function. It takes in the coefficients of the series and the range of values to evaluate it over, and returns the corresponding values of the function. You can also use the "plot" function to plot the Fourier series.

What does the "1st 8 terms" mean in the context of MATLAB Fourier series?

The "1st 8 terms" refers to the first 8 coefficients of the Fourier series, which are used to represent the function. These coefficients determine the amplitude and frequency of the sine and cosine functions in the series.

Can I use MATLAB to tabulate the values of a Fourier series?

Yes, you can use the "fourier" function in MATLAB to tabulate the values of a Fourier series. You can specify the range of values to evaluate the series over, and it will return a vector of corresponding values.

Why is it important to use the first 8 terms in a MATLAB Fourier series?

The first 8 terms of a Fourier series are important because they provide a good approximation of the original function. As the number of terms increases, the accuracy of the approximation also increases. However, using too many terms can lead to computational difficulties, so the first 8 terms are commonly used for practical purposes.

Similar threads

Replies
6
Views
7K
Replies
6
Views
2K
Replies
1
Views
6K
Replies
2
Views
1K
Replies
5
Views
2K
Replies
4
Views
26K
Replies
4
Views
3K
Replies
6
Views
940
Back
Top