フィルターのクリア

how to plot a periodic function?

31 ビュー (過去 30 日間)
Zafer Duyenli
Zafer Duyenli 2022 年 12 月 1 日
コメント済み: Zafer Duyenli 2022 年 12 月 2 日
Hey there,
I have to construct a periodic function of a signal according to the image shown in order to apply fourier series into it. I tried using piecewise command but I failed to get an appropriate output. What is the point that I'm missing? My code is shown below:
clc;
clear all;
a=3.2;
t1=5;
t2=7;
t3=12;
t4=17;
%constructing partial periodic function
syms a(x)
T=17;
i=-2;
interval=[0 -i*T];
pw=[];
while i<=diff(interval/(2*T))
a(x)=piecewise(i*T<=mod(x,17)<=t1+(i*T),3.2,t1+(i*T)<=mod(x,17)<=t2+(i*T),-1.6*(x-i*T)+11.2*4*i,t2+(i*T)<=mod(x,17)<=t3+(i*T),-0.64*(x-i*T)+4.48*4*i,t3+(i*T)<=mod(x,17)<=t4+(i*T),-3.2);
i=i+1;
pw=[pw a ];
end
pw
pw(x) = 
fplot(pw,interval)

採用された回答

Paul
Paul 2022 年 12 月 1 日
Hi Zafer,
To compute the Fourier series, you really only need to define one period of the function, because the defining integrals are only taken over one period. So you can use piecewise to define one period of the function.
a=3.2;
t1=5;
t2=7;
t3=12;
t4=17;
syms f(t)
f(t) = piecewise(t < t1,a, t1<=t<t2,-a/(t2-t1)*(t-t1)+a, t2<=t<t3, -a/(t3-t2)*(t-t2), t3<=t<t4,-a, 0);
fplot(f(t),[0 t4])
If you want to plot the periodic fucntion, then use mod as the argument into f, not in the definition of f
fplot(f(mod(t,t4)),[-50 50])
  1 件のコメント
Zafer Duyenli
Zafer Duyenli 2022 年 12 月 2 日
thank you, Paul! Appreciated for the answer!

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

その他の回答 (2 件)

Torsten
Torsten 2022 年 12 月 1 日
編集済み: Torsten 2022 年 12 月 1 日
a = 3.2;
t1 = 5;
t2 = 7;
t3 = 12;
t4 = 17;
fun = @(x) a*(x>=0 & x<=t1) + (-a/(t2-t1)*(x-t2)).*(x>t1 & x<=t2) + (-a/(t3-t2)*(x-t3)-a).*(x>t2 & x<=t3) + (-a)*(x>t3 & x <t4);
Fun = @(x) fun(mod(x,t4));
x = 0:0.01:17;
plot(x,Fun(x))
grid on

Walter Roberson
Walter Roberson 2022 年 12 月 1 日
編集済み: Walter Roberson 2022 年 12 月 1 日
You do not need any loop. You generate one cycle based upon t1 t2 t3 t4 and piecewise(). Then you substitute mod(Time,t4) to the piecewise, to end up with a piecewise that is cyclic every interval of t4.
Once you have the piecewise() then you can ask to rewrite(EXPRESSION, 'heaviside') to get an expression that, in theory, can be pass through fourier() . In practice the mod() is going to cause problems.
  1 件のコメント
Zafer Duyenli
Zafer Duyenli 2022 年 12 月 2 日
Thank you for the help! It really makes things easier for me!

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

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by