#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
using namespace std;
#define PI 3.14159265
#define e 2.71828182
int main( )
{
double period;
double frequency;
double angularfrequency;
double amplitude;
double time = 0 ;
double samplingrate;
double endtime;
double starttime;
double result;
double phase;
double alpha;
double gradient;
/*periodic rectangular signal*/
cout << "enter the frequency of the signal" << endl;
cin >> frequency;
cout << "enter the amplitude of the signal" << endl;
cin >> amplitude;
cout << "enter the sampling rate of the signal" << endl;
cin >> samplingrate;
cout << "enter the start time of the signal" << endl;
cin >> starttime;
cout << "enter the end time of the signal" << endl;
cin >> endtime;
time = starttime;
period = 1 / frequency;
for ( time = starttime; time <= endtime; time + = ( 1 / samplingrate) )
{
if ( period <= time <= period/ 2 )
{
result = amplitude;
}
else
{
result = ( - 1 ) * amplitude;
}
cout << time << " " << result << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgUEkgMy4xNDE1OTI2NQojZGVmaW5lIGUgMi43MTgyODE4MgoKaW50IG1haW4oKQp7Cglkb3VibGUgcGVyaW9kOwoJZG91YmxlIGZyZXF1ZW5jeTsKCWRvdWJsZSBhbmd1bGFyZnJlcXVlbmN5OwoJZG91YmxlIGFtcGxpdHVkZTsKCWRvdWJsZSB0aW1lPTA7Cglkb3VibGUgc2FtcGxpbmdyYXRlOwoJZG91YmxlIGVuZHRpbWU7Cglkb3VibGUgc3RhcnR0aW1lOwoJZG91YmxlIHJlc3VsdDsKCWRvdWJsZSBwaGFzZTsKCWRvdWJsZSBhbHBoYTsKCWRvdWJsZSBncmFkaWVudDsKCgovKnBlcmlvZGljIHJlY3Rhbmd1bGFyIHNpZ25hbCovCgoJY291dCA8PCAiZW50ZXIgdGhlIGZyZXF1ZW5jeSBvZiB0aGUgc2lnbmFsIiA8PCBl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