Fourier coefficients of a function
Show older comments

given this function with this interval is there any way to calculate the Fourier coefficients (ak, a0, bk) of this fuction in matlab?
Accepted Answer
More Answers (1)
syms x omega n
f = 0.5*(sin(x)+abs(sin(x)));
F(omega) = int(f*exp(1i*omega*x),x,-pi,pi)
n = 10;
g = real(F(0))/(2*pi) + sum(real(F(1:n))/pi.*cos((1:n)*x)+imag(F(1:n))/pi.*sin((1:n)*x))
g = matlabFunction(g);
x = linspace(-pi,pi,100)
plot(x,g(x))
hold on
f = matlabFunction(f);
plot(x,f(x))
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!