How can i get the fourier series of any given function
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Murloc50
am 25 Nov. 2021
Kommentiert: Friedel Hartmann
am 27 Nov. 2021
Since there is no direct way of finding/computing the fourier seris of a function, e.g. cos(x), how would I do this?
0 Kommentare
Akzeptierte Antwort
Friedel Hartmann
am 26 Nov. 2021
clear
syms x f(x) k fh(x) p(x) ph(x) % a0 = a0 Formel /2
iTerme = 8;
sco = zeros(1,iTerme);
cco = zeros(1,iTerme);
% T = 2*pi, omega = 1
f(x) = piecewise(x <= pi/4, -1/(2*pi) * x, pi/4 < x,-1/(2*pi) * x + 1); % Function
for k=1:iTerme
sco(k) = 1/pi * int(sin(k * x) * (f(x)),[0,2*pi]); % coefficients
cco(k) = 1/pi * int(cos(k * x) * (f(x)),[0,2*pi]);
end
cnum = 1:iTerme; % Table with coefficients
Tabelle.num = cnum';
Tabelle.scof = sco';
Tabelle.ccof = cco';
T = struct2table(Tabelle)
fplot(f(x),[0,2*pi]), title('Original'), yline(0);
figure
a0G = vpa(1/2 * 2/(2*pi) * int(f(x),[0,2*pi]),3)
fh(x) = 1/(2*pi) * int(f(x),[0,2*pi]); % 'Mittelwert' 1. Term ist a0
for k = 1:iTerme
fh(x) = fh(x) + sco(k) * sin(k * x) + cco(k) * cos(k * x);
end
fplot(fh(x),[0,2*pi]), title('Fourier series'), yline(0);
vpa(fh(0),3)
p(x) = x/(2*pi); % 2nd Function
for k=1:iTerme
sco(k) = 1/pi * int(sin(k * x) * (p(x)),[0,2*pi]);
cco(k) = 1/pi * int(cos(k * x) * (p(x)),[0,2*pi]);
end
cnum = 1:iTerme;
Tabelle.num = cnum';
Tabelle.scof = sco';
Tabelle.ccof = cco';
T = struct2table(Tabelle)
fplot(p(x),[0,2*pi]), title('Original'), yline(0);
figure
a0L = vpa(1/2 * 2/(2*pi) * int(p(x),[0,2*pi]),3)
ph(x) = 1/pi * int(p(x),[0,2*pi]) * 1/(2); % 'Mittelwert' 1. Term ist a0/2
for k = 1:iTerme
ph(x) = ph(x) + sco(k) * sin(k * x) + cco(k) * cos(k * x);
end
fplot(ph(x),[0,2*pi]), title('Fourier series'), yline(0);
1 Kommentar
Friedel Hartmann
am 27 Nov. 2021
The series starts with a constant term, the average value, called 'Mittelwert' The routine first calculates the average value, assigns this number to ph(x) and then begins the loop for k = 1:iTerme etc. and adds the following sin and cos functions.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!