Hola,
Un ejemplo sobre la visualización del Filtro Teager en Processing de
acuerdo a la charla de Carlos Roman (muchas gracias). El truco es
escoger los X de las condiciones iniciales. Perdón por las 300 lineas
que se diviertan! --* Juan
/************************************************************************
*
* Teager's Filter rendition as control to motion in Processing
* as per Carlos Roman paper STIVA-95
*
* 12/07/07
*
* juanig_at_CCRMA.Stanford.EDU
*
*************************************************************************
*/
//
// Global declarations
//
int select = 0; // select button
int toggle = 0; // toggle buttons
int outSideBnd = 0; // OutSide MousePressed Area ?
///
/// Initial boundary conditions for Teager's
//
float x=-1.0236;
float oldx = 1.000, newx =0.00;
int normTeagerx =0;
///
/// Initialize Colors
///
color l_oranged=color(245,137,36);
color l_green=color(149,220,18);
color l_yellow=color(255,249,81);
color l_blue=color(128,214,245);
color l_forest=color(6,142,67);
color l_red=color(189,57,74);
color l_white=color(255,255,255);
// {switches background}
color c_sw1=l_green;
color c_sw2=l_green;
color c_sw3=l_green;
color c_sw4=l_green;
color c_sw5=l_white;
///
/// setup
///
void setup(){
size(256,256);
noStroke();
background(255);
frameRate(4);
smooth();
}
///
/// draw function as MAINS
///
void draw()
{
drawButtons();
selectButton();
TeagerFL();
normTeagerx=NormVal(x);
if (outSideBnd == 1) {
sightWarn ();
} else {
ellipsoid(normTeagerx);
}
//
//println (normTeagerx);
//println("X coordinate: "+ mouseX + " Y cordinate: " + mouseY);
//
}
//
// When mouse pressed do
//
void mousePressed () {
redraw();
switch(select)
{
case 1:
outSideBnd=0;
changeColor1();
initTeagerVal();
x=2.9235;
break;
case 2:
outSideBnd=0;
changeColor2();
initTeagerVal();
x=-1.0236;
break;
case 3:
outSideBnd=0;
changeColor3();
initTeagerVal();
x=-1.250;
break;
case 4:
outSideBnd=0;
changeColor4();
initTeagerVal();
x=-0.936;
break;
default:
outSideBnd=1;
changeColor5();
initTeagerVal();
//x=-0.008971;
}
}
/*************************************************************
*
* Normalize Teager values as per:
*
* Y = floor [ ( (X+8) / 10.5) * 200 ]
*
*
*************************************************************
*/
int NormVal (float input)
{
int output;
output = floor ((input / 50) * 204) + 50;
if (output > 256) { output = 255; }
if (output < 0) { output = 0; }
return output;
}
/*************************************************************
* Teager's Filter:
*
* Functions (a.k.a as Methods)
*
* TEAGERFN: x[n+1] = x[n](x[n]-1)/x[n-1]
* and
* y[n] = x[n]
*
* Where y[n] is the current output and x[n] is the
* current input.
*
* y(n) = x(n)^2 -(x(n-1) * x(n+1))
*
*************************************************************
*/
void TeagerFL () {
float alpha = 1.00;
newx = alpha * x * (x - 1) / oldx;
oldx = x;
x = newx;
}
///
/// Initialize Teager's values again!
/// one'mo round!
///
void initTeagerVal () {
background(255);
newx =0.00;
oldx= 1.00;
}
///
/// draw all four buttons
///
void drawButtons ()
{
fill(c_sw1);
button1();
fill(c_sw2);
button2();
fill(c_sw3);
button3();
fill(c_sw4);
button4();
}
///
/// Select where-is the Mouse
///
void selectButton () {
if ( ((mouseX > 20) && (mouseX < 60)) && ((mouseY > 10) && (mouseY <
50))){
select=1; }
if ( ((mouseX > 75) && (mouseX < 105)) && ((mouseY > 10) && (mouseY
< 50))){
select=2; }
if ( ((mouseX > 120) && (mouseX < 150)) && ((mouseY > 10) && (mouseY
< 50))){
select=3; }
if ( ((mouseX > 165) && (mouseX < 195)) && ((mouseY > 10) && (mouseY
< 50))){
select=4; }
if (mouseY > 49) {
select=99; }
}
///
/// Toggle Colors and Teager's coefficient values
///
void changeColor1 () {
if(toggle == 0) {
c_sw1=l_oranged;
toggle = 1;
} else {
c_sw1=l_green;
toggle = 0;
}
}
void changeColor2 () {
if(toggle == 0) {
c_sw2=l_yellow;
toggle = 1;
} else {
c_sw2=l_green;
toggle = 0;
}
}
void changeColor3 () {
if(toggle == 0) {
c_sw3=l_blue;
toggle = 1;
} else {
c_sw3=l_green;
toggle = 0;
}
}
void changeColor4 () {
if(toggle == 0) {
c_sw4=l_forest;
toggle = 1;
} else {
c_sw4=l_green;
toggle = 0;
}
}
void changeColor5 () {
if(toggle == 0) {
c_sw5=l_red;
toggle = 1;
} else {
c_sw5=l_white;
toggle = 0;
}
}
///
/// Draw ellipsoid for Teager's Visualization
///
void ellipsoid (int w){
color cl = color((204-w), 153, 0);
fill(cl);
ellipse(128, 156, w, (200 -w));
}
///
/// Stop sign and warning for pressing buttons
//
void sightWarn () {
fill(c_sw5);
rect(75,120,80,80);
}
///
/// To draw buttons
///
void button1 () {
ellipse(45, 25, 30, 30);
}
void button2 () {
ellipse(90, 25, 30, 30);
}
void button3 () {
ellipse(135, 25, 30, 30);
}
void button4 () {
ellipse(180, 25, 30, 30);
}
/************************************************************************
*
* T H E E N D
*
*************************************************************************
*/
_______________________________________________
____ ____ ___ ____ _ _ ___
|__| |__/ / |___ \/ |__]
| | | \ /__ |___ _/\_ |
arzexp mailing list
[email protected]
http://lists.slow.tk/listinfo.cgi/arzexp-slow.tk