Skip to content

YlmzCmlttn

Cemalettin Yılmaz Blog

Menu
  • Home
  • About Me
  • Projects
    • Iot-AR
    • Magnifi-AR
    • Smarthome-IOS
    • Others
  • Categories
    • Articles
    • Augmented Reality
    • Capture The Flag
      • Google CTF
        • 2018
    • Embedded Systems
    • IoT
    • Logisim
    • My Essays
    • Nvidia Jetson
      • Jetson TX1
    • Operating Systems
      • Kali
      • Raspbian
      • Ubuntu
    • Personal
    • Programming
      • Arduino
      • C
      • C#
      • Css
      • Html
      • Js
      • Matlab
      • Node.js
      • Python
      • Swift
      • VHDL
    • Projects
      • Embedded Systems
      • Electric
      • IoT
      • IoT-AR
      • Logisim
      • Magnifi-AR
      • Pose Estimation
    • Raspberry Pi
    • Xilinx
    • Others
Menu

Printing samples of a sinusoidal signal using C

Posted on January 24, 2018March 24, 2018 by Yılmaz Cemalettin

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

Samples of a sinusoidal signal
C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(int argc, const char * argv[]) {
    double t;
    double P, A, f0, fSmp;
double A1=2.0,f01=100,P1=0.0,fSmp1=1000;
    double T0;
    
int myvariable;
if (argc != 5)
{
printf ("Your input is not enough number of inputs must be 4 your number of input(s) are %i\n",argc-1);
printf ("Executed progrem with this inputs \nAmplitude:2.0 \nf0:100 \nPI:3.1416 \nFSAMPLE:1000 \n Phase (P):0 \n");
goto notgiveninputs;
}
P = atof(argv[3]);
A = atof(argv[1]);
f0 = atof(argv[2]);
fSmp = atof(argv[4]);
T0 = 1/f0;
    printf("#Time(sec.)\tSample\n");
    for (t=0.0; t<=2*T0; t=t+1.0/fSmp) {
        printf("%2.5f\t\t%2.2f\n",t,A*sin(2*M_PI*f0*t+P));
    }
goto exit;
notgiveninputs:
T0 = 1/f01;
    printf("#Time(sec.)\tSample\n");
    for (t=0.0; t<=2*T0; t=t+1.0/fSmp1) {
        printf("%2.5f\t\t%2.2f\n",t,A1*sin(2*M_PI*f01*t+P1));
    }
exit:
    return 0;
}

 

Leave a Reply Cancel reply

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

My Motto

“Learn to share, Share to learn”

LinkedIn Badge

Cemalettin Yılmaz

Ads

Archives

Categories

  • Articles (1)
  • Augmented Reality (3)
  • Capture The Flag (23)
    • Google CTF (22)
      • 2018 (13)
      • 2019 (9)
    • PicoCTF (1)
      • 2019 (1)
  • Embedded Systems (3)
  • IoT (3)
  • Logisim (1)
  • My Essays (3)
  • Nvidia Jetson (5)
    • Xavier (5)
  • Operating Systems (24)
    • Kali (3)
    • Raspbian (2)
    • Ubuntu (21)
  • Others (1)
  • Personal (1)
  • Programming (44)
    • Arduino (4)
    • C (10)
    • C# (4)
    • C++ (5)
    • Css (1)
    • CUDA (6)
    • Html (1)
    • Js (2)
    • Libraries (5)
      • OpenCV (3)
      • OpenGL (2)
    • Matlab (14)
    • Node.js (5)
    • Python (6)
    • Swift (3)
  • Programs (4)
    • Tools (4)
  • Projects (21)
    • Books Solutions (8)
    • Electric (2)
    • Embedded Systems (2)
    • Energy Harvesting (1)
    • IoT (2)
    • IoT-AR (1)
    • Logisim (1)
    • Magnifi-AR (3)
    • Pose Estimation (3)
    • Smarthome-Ios (1)
  • Raspberry Pi (3)
  • Uncategorized (2)
  • YZlib (1)

Recent Posts

  • atof stof stod problems with local floating point separator in C/C++
  • Pico CTF 2019 Answers
  • YZlib: Personal C++ Library
  • Drive to target | Google CTF 2019
  • FriendSpaceBookPlusAllAccessRedPremium | Google CTF 2019

Recent Comments

  • AbaShelha on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Peter on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on 16-Bit CPU on Logisim
  • Jenny on 16-Bit CPU on Logisim
  • MOON on 16-Bit CPU on Logisim
  • anti on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • hunkerjr on STOP GAN | Google CTF 2019
  • Shaq on 16-Bit CPU on Logisim
  • NURUL AFIQAH MOHD HASBULLAH on 16-Bit CPU on Logisim

Linkedln

© 2022 YlmzCmlttn | Powered by Superbs Personal Blog theme