how to plot a periodic function?
43 views (last 30 days)
Show older comments
Zafer Duyenli on 1 Dec 2022
Commented: Zafer Duyenli on 2 Dec 2022
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:
%constructing partial periodic function
pw=[pw a ];
Paul on 1 Dec 2022
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.
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);
If you want to plot the periodic fucntion, then use mod as the argument into f, not in the definition of f
More Answers (2)
Torsten on 1 Dec 2022
Edited: Torsten on 1 Dec 2022
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;
Walter Roberson on 1 Dec 2022
Edited: Walter Roberson on 1 Dec 2022
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.
Find more on Signal Operations 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!