# a console representation of a square wave

1 view

### laserbeak43

Aug 29, 2007, 8:22:08 PM8/29/07
to DSP Study Group
out of frustration, i made a square wave this moringing.
all it does it print the values -1 and 1 to the screen though :)

#include <iostream>

using namespace std;

int main()
{
float min = -1;
float max = 1;
float x = 0;
float xStepper = 0;//steps at .025*1000
float cursor = 0;

for(float i = 0; i < 1000; i++)//this is the time
{
if( xStepper == 0 )
{
for ( xStepper = 0; xStepper < 25; xStepper++)//hold at zero
crossing for 25 intervals
{

x = min;
cout << x << endl;
}
}
if( xStepper = 24)
{
for (xStepper = 24; xStepper < 49; xStepper++)
{
x = max;
cout << x << endl;
}
}
if( xStepper == 49)
{
xStepper = 0;
}
}
return 0;
}

### laserbeak43

Aug 29, 2007, 8:23:29 PM8/29/07
to DSP Study Group
nevermind the comments, theyre obsolete :)

### laserbeak43

Aug 29, 2007, 8:50:00 PM8/29/07
to DSP Study Group
here's a modified version of a triangle wave. or at least my
theoretical version :P

#include <iostream>

using namespace std;

int main()
{
float min = -1;
float max = 1;
float x = 0;
float xStepper = 0;

float xint = .08;

for(float i = 0; i < 1000; i++)//this is the time
{
if( xStepper == 0 )
{

x = min;

for ( xStepper = 0; xStepper < 25; xStepper++)

{
x += xint;

cout << x << endl;
}
}
if( xStepper = 24)
{

x = max;

for (xStepper = 24; xStepper < 49; xStepper++)
{

x -= xint;

### laserbeak43

Aug 29, 2007, 9:45:40 PM8/29/07
to DSP Study Group

Here's a saw

#include <iostream>

using namespace std;

int main()
{
float min = -1;
float max = 1;
float x = 0;
float xStepper = 0;

float xint = .04;

for(float i = 0; i < 1000; i++)//this is the time
{
if( xStepper == 0 )
{
x = min;

for ( xStepper = 0; xStepper < 50; xStepper++)

{
x += xint;
cout << x << endl;
}
}