Fourier series question, in regards to integration and plotting finite sums

4 visualizaciones (últimos 30 días)
f(t) = 1 : 0 <t<pi/2 and 0: -pi/2 <t <0, f(t+pi) = f(t)
  2 comentarios
Thomas
Thomas el 10 de Abr. de 2025
How I would use matlab to generate the A_n and B_n integrals and then plot the finite sums.

Iniciar sesión para comentar.

Respuestas (1)

Sam Chak
Sam Chak el 10 de Abr. de 2025
I also struggled with calculating the integrations (by hand) while learning Fourier series many years ago. A friend taught me this 'dirty and fast trick' to find the coefficients of the Fourier series using MATLAB. Please note that linear and constant functions, as well as discontinuities, cannot be perfectly expressed by the Fourier series in finite terms. The example below includes up to eight terms of both sines and cosines.
However, if you wish to calculate the Fourier integrals 'fair and square', please provide the formulas for the coefficients , , , and the angular frequency ω.
%% Set heaviside(0) to 1, because OP didn't specify whether f(0) is 1 or 0.
sympref('HeavisideAtOrigin', 1);
%% the signal
t = linspace(-pi, pi, 3601);
f = heaviside(sin(2*t));
plot(t/pi, f, 'linewidth', 1.5), grid on, ylim([-0.5, 1.5])
xlabel('t/\pi'), ylabel('f(t)'), title('The signal, f(t)')
%% the fourier series
[fc, gof] = fit(t', f', "fourier8")
fc =
General model Fourier8: fc(x) = a0 + a1*cos(x*w) + b1*sin(x*w) + a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w) + a4*cos(4*x*w) + b4*sin(4*x*w) + a5*cos(5*x*w) + b5*sin(5*x*w) + a6*cos(6*x*w) + b6*sin(6*x*w) + a7*cos(7*x*w) + b7*sin(7*x*w) + a8*cos(8*x*w) + b8*sin(8*x*w) Coefficients (with 95% confidence bounds): a0 = 0.5002 (0.4967, 0.5037) a1 = 0.0003409 (-0.004617, 0.005299) b1 = 0.6361 (0.6312, 0.641) a2 = 0.0003408 (-0.004617, 0.005299) b2 = -0.0002442 (-0.005136, 0.004648) a3 = 0.0003405 (-0.004617, 0.005298) b3 = 0.2106 (0.2057, 0.2155) a4 = 0.0003401 (-0.004616, 0.005297) b4 = -0.0004827 (-0.005389, 0.004423) a5 = 0.0003395 (-0.004616, 0.005295) b5 = 0.1247 (0.1197, 0.1296) a6 = 0.0003389 (-0.004615, 0.005293) b6 = -0.0007099 (-0.005651, 0.004231) a7 = 0.0003381 (-0.004614, 0.005291) b7 = 0.08723 (0.08225, 0.09221) a8 = 0.0003372 (-0.004614, 0.005288) b8 = -0.0009204 (-0.006035, 0.004194) w = 1.976 (1.973, 1.978)
gof = struct with fields:
sse: 40.5713 rsquare: 0.9549 dfe: 3583 adjrsquare: 0.9547 rmse: 0.1064
plot(fc, t, f), grid on, axis([-pi, pi, -0.5, 1.5])
xlabel('t'), ylabel('f(t)'), title('Eight-term Fourier Series Model')

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by