Verifying Fourier Series In MATLAB

In summary: Instead of fs=fs+... you could write fs = fs + a0/2 + an*cos(n*x)+bn*sin(n*x);In summary, we have a conversation discussing a code for calculating the sum of a series and a Fourier series. The code has some errors, which are pointed out and suggestions for improvement are given. The final code includes simplified calculations and a more efficient loop.
  • #1
Jovany_17
2
0
HI please help me this could someone verify it for me please find attachement

clc;
clear all;
k=0;
s=0;
N=inf;
for i=1:N
s=s+(1/(k^2+1));
k=k+1;
end

syms x n
a0=1/pi*int(cosh(x),-pi,pi);
an=1/pi*int(cosh(x)*cos(n*x),-pi,pi);
bn=1/pi*int(cosh(x)*sin(n*x),-pi,pi);

fs=0;

for l=0:100
fs=fs+(an*cos(l*x)+bn*sin(l*x))
end

fs-fs+a0/2;
 

Attachments

  • TD.jpg
    TD.jpg
    6.2 KB · Views: 555
Physics news on Phys.org
  • #2
Jovany_17 said:
HI please help me this could someone verify it for me please find attachement

clc;
clear all;
k=0;
s=0;
N=inf;
for i=1:N
s=s+(1/(k^2+1));
k=k+1;
end

syms x n
a0=1/pi*int(cosh(x),-pi,pi);
an=1/pi*int(cosh(x)*cos(n*x),-pi,pi);
bn=1/pi*int(cosh(x)*sin(n*x),-pi,pi);

fs=0;

for l=0:100
fs=fs+(an*cos(l*x)+bn*sin(l*x))
end

fs-fs+a0/2;
The calculation of s looks OK. It could have been done slightly easier.
N=inf;
s=1;
for k = 1:N
s=s+(1/(k^2+1));
end
The Fourier series sum has a couple of errors. I would do the following:
fs = a0/2;
N = inf;
for n = 1:N
fs=fs+(an*cos(n*x)+bn*sin(n*x));
end
 
  • #3
Thanks
 
  • #4
A further simplification: Except for a0, the values of an and bn can be calculated inside the loop, so they don't have to be stored in advance.
 
  • #5


The code provided appears to be verifying the Fourier series for the function cosh(x) in MATLAB. It calculates the coefficients a0, an, and bn using symbolic integration and then uses a for loop to calculate the series up to a certain number of terms (in this case, 100). Finally, it verifies the series by subtracting it from itself and adding the constant term a0/2. This code seems to be a valid way of verifying the Fourier series, but it would be helpful to include comments and a clear explanation of the code for better understanding. Additionally, it would be beneficial to include a plot of the original function and the Fourier series approximation for visual verification.
 

1. "What is a Fourier series and why is it important?"

A Fourier series is a mathematical representation of a periodic function as a sum of sine and cosine functions. It is important because it allows us to break down complex signals into simpler components, making it easier to analyze and manipulate them.

2. "How do I verify a Fourier series in MATLAB?"

To verify a Fourier series in MATLAB, you can use the "fft" function to compute the Fast Fourier Transform of the function and compare it to the series representation. You can also use the "fouriercoeff" function to calculate the coefficients of the Fourier series and plot the resulting series.

3. "What is the difference between a Fourier series and a Fourier transform?"

A Fourier series is used to represent a periodic function as a sum of sine and cosine functions, while a Fourier transform is used to represent a non-periodic function as a sum of sine and cosine functions with different frequencies. In other words, a Fourier transform is a generalization of a Fourier series for non-periodic functions.

4. "Can I use MATLAB to verify a Fourier series for a non-periodic function?"

No, you cannot use MATLAB to verify a Fourier series for a non-periodic function. However, you can use the "fft" function to compute the Fourier transform of the function and verify its representation in the frequency domain.

5. "What are some applications of Fourier series?"

Fourier series have many applications in various fields such as signal processing, image and sound compression, data analysis, and solving differential equations. They are also used in practical applications such as image recognition, speech recognition, and audio processing.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
895
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
568
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
214
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • Calculus and Beyond Homework Help
Replies
1
Views
341
  • Topology and Analysis
Replies
4
Views
272
  • Math POTW for University Students
Replies
3
Views
784
  • Calculus and Beyond Homework Help
Replies
16
Views
561
Back
Top