Fourier coefficients of a function

30 ビュー (過去 30 日間)
SSBGH
SSBGH 2022 年 5 月 6 日
コメント済み: SSBGH 2022 年 5 月 6 日
given this function with this interval is there any way to calculate the Fourier coefficients (ak, a0, bk) of this fuction in matlab?

採用された回答

Paul
Paul 2022 年 5 月 6 日
Hi SSBGH
If you want a closed form solution, use the symbolic toolbox to define f(x)
syms x
f(x) = ....
Once you have that you can use the symbolic toolbox to compute a0, ak, and bk in terms of their defining integrals using the int function
syms k integer positive
a0 = int(...)
ak = int(...)
bk = int(...)
The defining integrals should be in your notes or text book, or can be found here.
If you want to numerically compute a0, ak, and bk for given values of k, first define f(x) as an anonymous function
f = @(x) ....
Then use the integral function to compute a0, or ak, or bk for a specific value of k
Your're more likely to get more help if you post your code and explain where you think it might be having problems.
  1 件のコメント
SSBGH
SSBGH 2022 年 5 月 6 日
thanks alot man

サインインしてコメントする。

その他の回答 (1 件)

Torsten
Torsten 2022 年 5 月 6 日
編集済み: Torsten 2022 年 5 月 6 日
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))
  2 件のコメント
SSBGH
SSBGH 2022 年 5 月 6 日
after writing your code im getting bunch of errors do you know why?
Torsten
Torsten 2022 年 5 月 6 日
I don't know. Maybe MATLAB cannot evaluate F(1).
Try
g = real(F(0))/(2*pi) + 0.5*sin(x) + sum(real(F(2:n))/pi.*cos((2:n)*x)+imag(F(2:n))/pi.*sin((2:n)*x))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by