HI All
How can we generate a sine wave without using the sin() function.

Thanks
pretu

Recommended Answers

All 8 Replies

you can use the sine series for calculation upto a certain accuracy and then plot the curve

HI All
How can we generate a sine wave without using the sin() function.

Thanks
pretu

I'm assuming you don't want to use the cosine function either :) You could create a table of results and read the values off that instead of using the sine function. Alternatively you could use exponentials and imaginary numbers ...

Hi all
How use sine wave psoc programing in micro controller cy8c27443 code

HI All
How can we generate a sine wave without using the sin() function.

Thanks
pretu

You can try Taylor series also.

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
int main(void)
{

  int gdriver = DETECT, gmode;
  float x,w1,w,a,f,fs;
  cout<<"\n\tEnter amplitude:";
  cin>>a;
  cout<<"\n\tEnter freq.:";
  cin>>f;
  cout<<"\n\tEnter sampling points:";
  cin>>fs;
  w=2*3.14*f;

  initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  line(0, 0,0,500);
  line(0,200,800,200);
 // getch();

  for(int n=0;n<640;n++)
  {
	w1=w*n;
	x=a*sin(w1/fs);
	x=x+200;
	putpixel(n,x,25);
  }
  getch();
		closegraph();
   return 0;
}
commented: hijack + obsolete compiler + no code tags => EPIC FAIL -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.