Constructing an approximate periodical function x(t) giving its Fourier series coefficient?

1 回表示 (過去 30 日間)
MIRK
MIRK 2014 年 12 月 28 日
編集済み: Shoaibur Rahman 2014 年 12 月 28 日
I want to Constructing a code for periodical function x(t) for example from -5 to 5 and then plot it
Fourier series coefficient is a piece wise function
and the time increment is 0.01 from 0 up to 8
for me I am not expert in cooding and matlab I write this code
syms result t
for t =0 : 0.01 : 8
for N = -5 : 1 : 5
if( N == 0)
result = (0.5* exp(- j*2*pi * N * 0.5 * t));
else
result = ((j/2*pi*N)*exp(- j*2*pi * N * 0.5 * t));
end
end
end
ezplot(result,0,1)
The problem is the plot. it does not make sense its just a line increasing !!! for those who know matlab well. where is the problem in the code thank you
  1 件のコメント
MIRK
MIRK 2014 年 12 月 28 日
i forgot to type +result in the above code
syms result t
for t =0 : 0.01 : 8
for N = -5 : 1 : 5
if( N == 0)
result =result + (0.5* exp(- j*2*pi * N * 0.5 * t));
else
result = result + ((j/2*pi*N)*exp(- j*2*pi * N * 0.5 * t));
end
end
end
ezplot(result,0,1)

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

回答 (1 件)

Shoaibur Rahman
Shoaibur Rahman 2014 年 12 月 28 日
編集済み: Shoaibur Rahman 2014 年 12 月 28 日
You can use a vectorized code to get the periodic signal:
f0 = 1; % set the frequency of desired signal
t = 0:0.01:8;
n = -5:5; % change as required
Xn = 1j./(2*pi*n);
Xn(n==0) = 1/2;
x = Xn * exp(-(1j*2*pi*n'*f0*t)); % n' in exp automatically does the sum!
plot(t,abs(x))

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by