How to create a periodic function?
64 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
huazai2020
le 25 Nov 2020
Réponse apportée : Setsuna Yuuki.
le 25 Nov 2020
The function at [0,2] is y=x for [0,1] and y=2-x for [1,2], I want the above function repeated at [2,10], so I need a periodic funtion in the whole [0,10], who can help me code it ,thank you.
0 commentaires
Réponse acceptée
James Tursa
le 25 Nov 2020
Not sure what you mean by "repeated at [2,10]". Maybe this:
y = mod(x,2);
ix = y > 1;
y(ix) = 2 - y(ix);
9 commentaires
James Tursa
le 25 Nov 2020
Generic code could be:
% Periodic triangle wave
amplitude = whatever;
period = whatever;
y = mod(x,period);
ix = y > period/2;
y(ix) = period - y(ix);
y = (amplitude * 2 / period) * y;
Plus de réponses (2)
David Hill
le 25 Nov 2020
y=zeros(size(x));
for k=1:5
y(x>=(k-1)*2&x<(k-1)*2+1)=x(x>=(k-1)*2&x<(k-1)*2+1);
y(x>=2*(k-1)+1&x<2*k)=2-x(x>=2*(k-1)+1&x<2*k);
end
4 commentaires
Image Analyst
le 25 Nov 2020
Then just use the code that you used to create the figure. It's what you want isn't it?
Setsuna Yuuki.
le 25 Nov 2020
You can use this function: https://es.mathworks.com/matlabcentral/fileexchange/83058-continuous-piecewise-function-linear-funcion-por-partes
x = [0:3:36];
y = [0 1 0 1 0 1 0 1 0 1 0 1 0];
sig = pwfun(x,y);
and create the waveform only with the intersection points.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/427373/image.jpeg)
0 commentaires
Voir également
Catégories
En savoir plus sur Signal Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!