Printing samples of a sinusoidal signal using C

Samples of a sinusoidal

Writing a program that prints samples of a sinusoidal signal at f0 sampled at fsample with peak amplitude A and phase P, for two periods (T0). Take A, f0, P, and fsample from command-line as arguments, as follows:
ProgramName A f_0 P_in_radians f_sample (i)
An example call for MS Windows environment for A = 2, f0 = 100Hz, P = 0, and fsample = 1kHz can be given as:
C:\> PrintValuesOfASine.exe 2 100 0 1000
Your program should print its usage, as shown in (i) above, in case arguments are not given – all of the arguments are mandatory. You should print the name of your program in place of “ProgramName” in (i), as shown for the MS Windows example:
C:\> PrintValuesOfASine.exe -> Program called without arguments
Usage: PrintValuesOfASine.exe A f_0 P_in_radians f_sample
The skeleton of the code that you should complete is given in PrintValuesOfASine.c
Hint: You should use argc for variable count checking and argv for getting values of the command line arguments, together with atof() function defined in stdlib.h header. The values of the command line arguments are given in argv array as string values, so you should use atof() to convert them into double.
Test: We will check your code’s output against text files given, which are produced by my code as follows:
C:\> PrintValuesOfASine.exe 2 100 0 1000 > values_2_100_0_1000.txt
C:\> PrintValuesOfASine.exe 2 100 0 10000 > values_2_100_0_10000.txt
C:\> PrintValuesOfASine.exe 4 1000 3,1415 100000 > values_4_1000_PI_100000.txt

 

Posted in CTagged

Leave a Reply

Your email address will not be published. Required fields are marked *