1
$\begingroup$

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?

$\endgroup$
0

1 Answer 1

9
$\begingroup$

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}] 

Mathematica graphics

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}] 

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Great! It works, thank you. $\endgroup$ Commented Sep 29, 2015 at 11:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.