Thursday, April 11, 2013

Sine Wave Generation in C Program

/*
 * SineWave.c
 *
 *  Created on: Apr 11, 2013
 *      Author: Karthik
 */

#include
<stdio.h>
#include<conio.h>
#include<math.h>
#include <windows.h>


#define pi 3.142
int main()
{
    FILE *fp;
    fp = fopen("Sinewave.xls","w");

    if(fp == NULL)
    {
        MessageBox(0,"Error","File Creation",16);
        exit(0);

    }
 int nfreq,nTime,nAmplitude=0;
 double dSample, dCycle=0;
 double dStopTime=0;
 printf("enter the desired frequency of the signal:\n");
 scanf("%d",&nfreq);
 printf("enter the desired sampling Time:\n");
 scanf("%d",&nTime);
 printf("enter the amplitude of the signal:\n");
 scanf("%d",&nAmplitude);
 printf("Enter the Stop time:\n");
 scanf("%lf",&dStopTime);

for (;dCycle <= dStopTime; )
{
    dSample = nAmplitude * sin(2*pi*nfreq*dCycle);

    fprintf(fp,"%lf\n",dSample);

    dCycle = dCycle + ((double)nTime/100);
}

    fclose(fp);
    getch();
    return 0;
 }

No comments:

Post a Comment