# How to define a periodic function from an interval to Play (monotonic) sound [duplicate]

I would like to define a function on an interval and then duplicate it on other intervals of the same length in order to define a (generally discontinuous) periodic function, from which I could get a (monotonic) sound through Play.

How could I get that?

You can define a periodic function by this simple idiom

T = 1;
g[x_ /; 0 <= x <= T] := x^2;
g[x_] := g[Mod[x, T]]


Here, T is the length of the period. What happens is that you restrict your function g to a certain interval and when your argument x falls outside this interval, you just shift it back (using Mod here). With this, you can use g anywhere and it just repeats the interval [0,T]:

Plot[g[x], {x, 0, 10}]


This can now be used for your sound to repeat a small piece:

f[t_ /; 0 <= t <= Pi] := Sin[t]*(Sin[880 Pi t] + Sin[1100 Pi t] + Sin[1320 Pi t]);
f[t_] := f[Mod[t, Pi]]

Play[Sin[t]*(Sin[880 Pi t] + Sin[1100 Pi t] + Sin[1320 Pi t]), {t, 0, 10}]


• Great! It works, thank you. – marfi Sep 29 '15 at 11:05