Fourier Series/ MatLab syntax

In summary: Your Name]In summary, the conversation discusses how to determine the first 10 non-zero elements in the Fourier series representation of a function using Matlab. It is noted that the function has even symmetry, so the bn coefficients do not need to be computed. The use of the "Heaviside" function in Matlab is suggested to define the given function, and an example is provided on how to multiply it by cosine and integrate. The conversation also mentions using a loop to compute the coefficients for multiple frequencies and plotting the results.
  • #1
cambone69
1
0

Homework Statement


(a) For each function determine the first 10 non zero elements in the Fourier series representation. Use Matlab to compute the coefficients, and graph the result.

Untitled.jpg


Homework Equations


N/A

The Attempt at a Solution


I noted the even symmetry of the function, and thus I do not have to compute the "bn" (sine) coefficients. Also the fact that I can compute the cosine coefficients by integrating over half of the period, ie 0--->T/2. I know how to compute the coefficients by hand, however I am required to use Matlab.

In MatLab how would I define the function f (which appears to be a unit step function on half the period) in MatLab, with which I could multiply by cosine and then integrate appropriately?

This is a simple problem, however Matlab has become the biggest roadblock here.

Any help would be greatly appreciated.

Cam
 
Physics news on Phys.org
  • #2
ille

Hello Camille,

To define the function in Matlab, you can use the "Heaviside" function, which represents the unit step function. For example, if your function is f(x) = 1 for x between 0 and T/2, and f(x) = 0 for x between T/2 and T, you can define it as follows:

f = @(x) 1*(x>=0 & x<=T/2) + 0*(x>T/2 & x<=T)

This creates a function handle for your function, which you can then use in your calculations. For example, to multiply it by cosine and integrate, you can do the following:

cos_coeff = integral(@(x) f(x).*cos(k*x),0,T/2)

Where k is the frequency of the cosine term in the Fourier series. You can then use a loop to compute the coefficients for k = 1 to 10, and plot the results using the "plot" function.

I hope this helps. Let me know if you have any further questions.


 
  • #3


Thank you for your question and for providing all the necessary information. I understand the importance of using technology to assist in our calculations and analysis. In this case, we can use MatLab to easily compute the Fourier series coefficients and graph the result.

To define the function in MatLab, we can use the "heaviside" function which represents the unit step function. We can define the function f as follows:

f = heaviside(t)

where t is the variable representing time.

To compute the cosine coefficients, we can use the "integral" function in MatLab. For example, if we want to compute the first coefficient a0, we can use the following code:

a0 = 2*integral(@(t) f*cos(0*t),0,T/2)

This integrates the product of f and cos(0*t) over the interval 0 to T/2, where T is the period of the function.

Similarly, we can use the "plot" function to graph the Fourier series representation of the function. For example, if we want to graph the first 10 nonzero elements, we can use the following code:

t = linspace(0,T,100); %creates a vector of 100 equally spaced points between 0 and T
f_series = a0/2; %initializes the series with the a0 coefficient
for n = 1:10
f_series = f_series + an*cos(n*t) + bn*sin(n*t); %adds the cosine and sine terms to the series
end
plot(t,f_series) %plots the series
xlabel('Time') %adds a label to the x-axis
ylabel('f(t)') %adds a label to the y-axis
title('Fourier Series Representation') %adds a title to the graph

I hope this helps you with your homework problem. If you need further assistance with using MatLab, I recommend consulting the MatLab documentation or seeking help from a tutor or classmate. Remember, using technology to assist in our calculations and analysis is a valuable tool for scientists, but it is important to also understand the underlying concepts and methods.
 

1. What is a Fourier Series and how is it used?

A Fourier Series is a mathematical representation of a periodic function as a sum of sinusoidal functions. It is used to analyze and approximate periodic functions in various fields such as signal processing, engineering, and physics.

2. How do I compute a Fourier Series using MatLab?

To compute a Fourier Series using MatLab, you can use the built-in function "fft". This function takes a discrete time-domain signal and returns the corresponding discrete Fourier coefficients.

3. What is the syntax for creating a Fourier Series plot in MatLab?

The syntax for creating a Fourier Series plot in MatLab is:plot(x, y) xlabel('Frequency (Hz)')ylabel('Amplitude')title('Fourier Series Plot')

4. Can I use MatLab to find the coefficients of a Fourier Series?

Yes, you can use MatLab to find the coefficients of a Fourier Series. The "fft" function returns the discrete Fourier coefficients, and you can use the "ifft" function to compute the inverse Fourier coefficients.

5. Is it possible to analyze non-periodic functions using Fourier Series in MatLab?

No, Fourier Series can only be applied to periodic functions. If you want to analyze non-periodic functions, you can use the Fourier Transform function in MatLab, which works for both periodic and non-periodic functions.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
288
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Calculus and Beyond Homework Help
Replies
1
Views
252
  • Engineering and Comp Sci Homework Help
Replies
3
Views
3K
Replies
139
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
367
  • Engineering and Comp Sci Homework Help
Replies
17
Views
5K
Back
Top