Discrete Vs Analog I/O Signals Vs Digital Signal

         The first step of digitization is to sample the analog signal. Output of this process is a discrete time signal. At this point, there is no constraint on amplitude of the output signal. Figure below shows both the signals.

                           

        The next step of the digitization process is quantization. It involves approximating the sampled analog values using a finite set of values. After this step, the output signal is discrete in both time and amplitude. Amplitude of the signal takes 1 of the M possible values.


        The third step of digitization is to encode these quantized values into bits. Each amplitude level can be represented as a binary sequence. The output of this process is a digital signal that is a physical signal. It is continuous in time and amplitude of this signal is either 1 or 0.

        Digital signal can also refer to a signal that switches between discrete number of voltage levels.

What are Static Variables and functions in C ?

  • In C, functions are global by default. The “static” keyword before a function name makes it static.
  • Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static.
  •  Another reason for making functions static can be reuse of the same function name in other files.
  • For example, below function fun() is static.

static int fun(void)

{

  printf("I am a static function ");

}


Source : GeeksforGeeks & GeeksforGeeks

Difference between float and double in C/C+

  • Double has 2x more precision then float.
  • float is a 32 bit IEEE 754 single precision Floating Point Number1 bit for the sign, (8 bits for the exponent, and 23* for the value), i.e. float has 7 decimal digits of precision.
  • Double is a 64 bit IEEE 754 double precision Floating Point Number (1 bit for the sign, 11 bits for the exponent, and 52* bits for the value), i.e. double has 15 decimal digits of precision.

Let’s take a example(example taken from here) :

For a quadratic equation x2 – 4.0000000 x + 3.9999999 = 0, the exact roots to 10 significant digits are, r1 = 2.000316228 and r2 = 1.999683772

// C program to demonstrate 

// double and float precision values

#include <stdio.h>

#include <math.h>

// utility function which calculate roots of 

// quadratic equation using double values

void double_solve(double a, double b, double c)

{

    double d = b*b - 4.0*a*c;

    double sd = sqrt(d);

    double r1 = (-b + sd) / (2.0*a);

    double r2 = (-b - sd) / (2.0*a);

    printf("%.5f\t%.5f\n", r1, r2);

}

// utility function which calculate roots of 

// quadratic equation using float values

void float_solve(float a, float b, float c)

{

   float d = b*b - 4.0f*a*c;

    float sd = sqrtf(d);

    float r1 = (-b + sd) / (2.0f*a);

    float r2 = (-b - sd) / (2.0f*a);

    printf("%.5f\t%.5f\n", r1, r2);

}   

// driver program

int main()

{

    float fa = 1.0f;

    float fb = -4.0000000f;

    float fc = 3.9999999f;

    double da = 1.0;

    double db = -4.0000000;

    double dc = 3.9999999;

  

    printf("roots of equation x2 - 4.0000000 x + 3.9999999 = 0 are : \n");

    printf("for float values: \n");

    float_solve(fa, fb, fc);

  

    printf("for double values: \n");

    double_solve(da, db, dc);

    return 0;

}  

Output:

roots of equation x2 - 4.0000000 x + 3.9999999 = 0 are : 

for float values: 

2.00000    2.00000

for double values: 

2.00032    1.99968