fireflies
Newbie level 5
square wave c
Hi,
I am new to C++/Cprogramming
How do you generate a simple square wave using C++.
void Square(void)
{
float Amplitude_S, Frequency_S, S, Sq, t, sgn_z, z;
clrscr();
textbackground( fBLUE + fINTENSITY );
gotoxy( 5, 1 );
textbackground( fWHITE + fINTENSITY );
printf("Enter Amplitude: ");
fflush(stdin);
scanf("%f", &Amplitude_S);
textbackground( fBLUE + fINTENSITY );
gotoxy( 5, 2 );
printf("Frequency: ");
scanf("%f", &Frequency_S);
t = 1/Frequency_S;
z = sin(t);
sgn_z = z / abs(z);
S = sgn_z; //take initial phase as 0
//sgn = sign or signum function
Sq = Amplitude_S * S;
textbackground( fWHITE + fINTENSITY );
printf("Input Complete...");
fflush(stdin);
getch();
}//end
Thanks.
Hi,
I am new to C++/Cprogramming
How do you generate a simple square wave using C++.
void Square(void)
{
float Amplitude_S, Frequency_S, S, Sq, t, sgn_z, z;
clrscr();
textbackground( fBLUE + fINTENSITY );
gotoxy( 5, 1 );
textbackground( fWHITE + fINTENSITY );
printf("Enter Amplitude: ");
fflush(stdin);
scanf("%f", &Amplitude_S);
textbackground( fBLUE + fINTENSITY );
gotoxy( 5, 2 );
printf("Frequency: ");
scanf("%f", &Frequency_S);
t = 1/Frequency_S;
z = sin(t);
sgn_z = z / abs(z);
S = sgn_z; //take initial phase as 0
//sgn = sign or signum function
Sq = Amplitude_S * S;
textbackground( fWHITE + fINTENSITY );
printf("Input Complete...");
fflush(stdin);
getch();
}//end
Thanks.