How to use multi-part function to find Fourier series coefficients with this program?

조회 수: 3 (최근 30일)
Hi I am writing a script to find Fourier series coefficients. Code is given below. In the code, I have function f=x*x defined on interval -L to L. However if I have some function defined, say
f(x) = -1 -L<=x<0
= 1 0<=x<=L
then, how I can use such function to find Fourier series coefficients? Any ideas?
close all;
clc;
syms x k L n
evalin(symengine,'assume(k,Type::Integer)'); %k is treated as integer
f=x*x; %f is the function to find Fourier series
a = int(f*cos(k*pi*x/L)/L,x,-L,L); %Fourier series coefficient a_n
b = int(f*sin(k*pi*x/L)/L,x,-L,L); %Fourier series coefficient b_n
afun=@(f,x,k,L) int(f*cos(k*pi*x/L)/L,x,-L,L);
bfun = @(f,x,k,L) int(f*sin(k*pi*x/L)/L,x,-L,L);
fs = vpa(afun(f,x,0,L)/2 + symsum(afun(f,x,k,L)*cos(k*pi*x/L) + ... bfun(f,x,k,L)*sin(k*pi*x/L),k,1,3),5); %Partial sum of Fourier series coefficients
fs=subs(fs,L,1); %making L=1
fs1=symfun(fs,x); %defining symbolic function fs1 for plotting
% disp(a);
% disp(b);
% disp(fs);
figure();
ezplot(fs1,[-5*pi,5*pi]);

답변 (1개)

Star Strider
Star Strider 2014년 7월 13일
편집: Star Strider 2014년 7월 13일
You are not defining the integral limits correctly.
For example:
syms a b k L w0 x
krnl = symfun(a*cos(-j*k*w0*x) + j*b*sin(-j*k*w0*x), x) % Transform kernel
F1 = int(-1*krnl, x, -L, 0); % -L -> 0
F2 = int(+1*krnl, x, 0, L); % 0 -> +L
FT = F1 + F2; % Add integrals
FT = subs(FT, L, 1) % L = 1
FT = simplify(collect(FT))
produces (in R2014a):
FT =
(4*b*sinh((k*w0)/2)^2)/(k*w0)
MATLAB (correctly) substituted sinh for the sin of an imaginary argument, so this is equivalent to:
FT =
(4*b*sin((j*k*w0)/2)^2)/(k*w0)
The individual ‘b’ coefficients are functions of k. The ‘a’ coefficients are identically zero.
The frequency argument, w0, is the fundamental frequency of the sampled signal. I refer you to the Wikipedia article on Fourier series for the details.
  댓글 수: 1
Christopher Creutzig
Christopher Creutzig 2014년 9월 1일
If you would like to get rid of the sinh (to get a more standard representation), try rewrite(FT,'sin').

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by