Forums > MaxMSP

Chaotic Sygnal Generation using Gen~ and codebox

November 6, 2011 | 9:40 pm

Hey all,

I’m trying to make a Gen~ patch that will evaluate the Lorenz equations at signal speed for the purpose of generating chaotic signals. It’s my first time using Gen~ and codebox and I can’t make anything work. Just wondering if anyone could give me a hint in the right direction.

{
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 0
}
,
"rect" : [ 62.0, 69.0, 640.0, 480.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 0,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 0,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"boxanimatetime" : 200,
"imprint" : 0,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"boxes" : [ {
"box" : {
"id" : "obj-6",
"maxclass" : "ezdac~",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 158.0, 214.0, 45.0, 45.0 ]
}

}
, {
"box" : {
"id" : "obj-5",
"maxclass" : "scope~",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 413.0, 317.0, 130.0, 130.0 ],
"presentation_rect" : [ 408.0, 321.0, 0.0, 0.0 ]
}

}
, {
"box" : {
"id" : "obj-4",
"maxclass" : "scope~",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 276.0, 317.0, 130.0, 130.0 ],
"presentation_rect" : [ 279.0, 317.0, 0.0, 0.0 ]
}

}
, {
"box" : {
"id" : "obj-3",
"maxclass" : "scope~",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 146.0, 317.0, 130.0, 130.0 ]
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-2",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 3,
"outlettype" : [ "signal", "signal", "signal" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 0
}
,
"rect" : [ 88.0, 116.0, 750.0, 520.0 ],
"bgcolor" : [ 0.9, 0.9, 0.9, 0.9 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 0,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 0,
"statusbarvisible" : 0,
"toolbarvisible" : 1,
"boxanimatetime" : 200,
"imprint" : 0,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"title" : "untitled",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-13",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 277.0, 404.0, 37.0, 20.0 ],
"text" : "out 3"
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-12",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 194.0, 404.0, 37.0, 20.0 ],
"text" : "out 2"
}

}
, {
"box" : {
"code" : "// Set values for constantsrnpr = 10;rnb = 2.66667;rnr = 18;rndt = .01;rnrn//set initial values for variablestrnx = 0;rny = 2.3;rnz = -4.4;rnrn//set output expressions (ie Lorenz Equations)rnxn = x +(pr*(y – x))*dt;rnyn = y + (-x*z + r*x – y)*dt; rnzn = z + (x*y – b*z)*dt;rnx = xn;rny = yn;rnz = zn;rnrnout1 = x;rnout2 = y;rnout3 = z;rn",
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-5",
"maxclass" : "codebox",
"numinlets" : 1,
"numoutlets" : 3,
"outlettype" : [ "", "", "" ],
"patching_rect" : [ 114.0, 112.0, 499.0, 213.0 ]
}

}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-4",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 98.0, 404.0, 37.0, 20.0 ],
"text" : "out 1"
}

}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-12", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-5", 1 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-13", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-5", 2 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-4", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-5", 0 ]
}

}
],
"dependency_cache" : [ {
"name" : "codebox.mxo",
"type" : "iLaX"
}
]
}
,
"patching_rect" : [ 307.0, 231.0, 236.0, 20.0 ],
"text" : "gen~"
}

}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-2", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-4", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-2", 1 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-5", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-2", 2 ]
}

}
],
"dependency_cache" : [ ]
}

}

Attachments:
  1. Lorenz2.maxpat

November 6, 2011 | 9:59 pm

The problem is with how you’re expecting feedback to work. In your code you have:

x = xn;
y = yn;
z = zn;

These are supposed to be around for the next sample, but in gen~, they’re not unless you use something like the history operator. Have a look at the gen~.lorenz example in examples/gen.

Also, if you post patches to the forum, it’s much more convenient for everyone if you to Edit > Copy Compressed and paste that in so there isn’t a giant post full of JSON.


November 6, 2011 | 10:32 pm

You definitely don’t need a codebox for that. Hang a couple of objects off of the gen~-chaos patch in the examples folders to give you limits for mapping the output signal and you’re off to the races in about a minute and a half. I usually let these things run for a few hours and then hard-code the upper and lower limits inside the gen~ using the scale operator. YMMV.

– Pasted Max Patch, click to expand. –

November 6, 2011 | 11:53 pm

Oh jeez, feel like a moron. The example patch was really helpful thank you very much. Ditto regarding the post full of JSON.


Viewing 4 posts - 1 through 4 (of 4 total)