Plotting Fourier Series (first 5, 15, 25 partial sums, (3 Plots))
Mostra commenti meno recenti
Hi there. I am a very new inexperienced user of MAtlab and have been asked to plot the first 5, 15, 25 partial sums across 3 plots for my fourier series.
Fourier series values shared below - any help with simple anotated breakdown would be appreciated.
- a0 = 1.5
- aN odd and even = 0
- bN odd=

- bN even = 0
Risposte (2)
Hassaan
il 2 Gen 2024
Assuming you get the formula for bN (odd), here's one of the approach you can use in MATLAB:
% Define the basic parameters
a0 = 1.5;
T = 2*pi; % Period of the Fourier series, change according to your function
t = linspace(0, 2*T, 1000); % Time variable from 0 to 2*T with 1000 points
% Function to calculate bN for odd N, replace this with the actual formula
function bN = calculate_bN(N)
% Your formula for bN when N is odd goes here
% For example, a common form might be: bN = (-1)^(someFunction(N))/N;
bN = 1/N; % Placeholder, replace with actual formula
end
% Function to calculate the partial sum of the Fourier series
function F = fourierPartialSum(t, N)
F = a0 / 2; % Start with a0/2
for n = 1:N
if mod(n,2) == 1 % If n is odd
bN = calculate_bN(n);
F = F + bN*sin(n*t); % Update the sum with the nth term
end
% Since aN and bN for even are 0, those terms are skipped
end
end
% Calculate and plot the first 5, 15, and 25 partial sums
figure;
subplot(3,1,1);
plot(t, fourierPartialSum(t, 5));
title('First 5 Partial Sums');
subplot(3,1,2);
plot(t, fourierPartialSum(t, 15));
title('First 15 Partial Sums');
subplot(3,1,3);
plot(t, fourierPartialSum(t, 25));
title('First 25 Partial Sums');
- Formula for bN: You need to provide the actual formula for bN when N is odd. Replace the placeholder function calculate_bN(N) with your specific formula.
- Time Domain and Period: Adjust the time variable t and the period T according to the specific function you're analyzing.
- Resolution: The number of points in the linspace function determines the resolution of the plot. Increase the number of points for a smoother curve.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems
- Electrical and Electronics Engineering
You should be able to add the missing plots.
x = 0:0.01:2*pi;
n = 25;
Fn = fourier(n,x);
plot(x,Fn)
function Fn = fourier(n,x)
x = x(:);
a0 = 1.5;
a = zeros(1,n);
b = zeros(1,n);
for i = 1:2:n
b(i) = -3/(pi*i)*(cos(pi*i)-cos(0));
end
Fn = a0/2 + sum(a.*cos((1:n).*x)+b.*sin((1:n).*x),2);
end
5 Commenti
AB29
il 3 Gen 2024
Just change the b values in the loop.
Your picture says
for i = 1:n
b(i) = -3/(pi*i)*cos(pi*i*1.5/2.5)-1;
end
your code line says
for i = 1:n
b(i) = -3/(pi*i)*(cos(pi*i*1.5/2.5)-1);
end
Decide yourself which one is correct.
AB29
il 3 Gen 2024
The code I gave you is for a 2*pi periodic function (P = 2*pi). Its Fourier expansion is described by (eq.2) and (eq.5) under
If you have a different period P, the Fourier series and its coefficients are computed differently (again see (eq.2) and (eq.5)).
By the way:
b(i) = -3/(pi*i)*(cos(pi*i*1.5/2.5))-1;
cannot be the sin Fourier coefficients of a function - they must converge to 0 as i -> Inf. Yours converge to -1.
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






