943,946 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 14870
  • C RSS
Jun 4th, 2007
0

Generating sine wave

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

Thanks
pretu
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pretu is offline Offline
3 posts
since Jun 2007
Jun 4th, 2007
0

Re: Generating sine wave

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

Click to Expand / Collapse  Quote originally posted by pretu ...
HI All
How can we generate a sine wave without using the sin() function.

Thanks
pretu
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Jun 4th, 2007
0

Re: Generating sine wave

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 ...
Reputation Points: 453
Solved Threads: 57
Posting Virtuoso
twomers is offline Offline
1,873 posts
since May 2007
Jun 4th, 2007
0

Re: Generating sine wave

Take a look at the code snippet at:
http://www.daniweb.com/code/snippet66.html
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Jun 4th, 2007
0

Re: Generating sine wave

What's with all the "how to do x without using the obvious x" questions?
http://www.daniweb.com/techtalkforums/thread80025.html
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 21st, 2010
-1
Re: Generating sine wave
Hi all
How use sine wave psoc programing in micro controller cy8c27443 code
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vinai05 is offline Offline
1 posts
since Jun 2010
Jun 22nd, 2010
0
Re: Generating sine wave
Try the sine series.
Reputation Points: 57
Solved Threads: 58
Posting Pro in Training
nbaztec is offline Offline
468 posts
since May 2010
Jun 22nd, 2010
0
Re: Generating sine wave
Click to Expand / Collapse  Quote originally posted by pretu ...
HI All
How can we generate a sine wave without using the sin() function.

Thanks
pretu
You can try Taylor series also.
Reputation Points: 51
Solved Threads: 9
Junior Poster
0x69 is offline Offline
130 posts
since Apr 2010
Jul 25th, 2011
-1
Re: Generating sine wave
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<math.h>
  4. #include<graphics.h>
  5. int main(void)
  6. {
  7.  
  8. int gdriver = DETECT, gmode;
  9. float x,w1,w,a,f,fs;
  10. cout<<"\n\tEnter amplitude:";
  11. cin>>a;
  12. cout<<"\n\tEnter freq.:";
  13. cin>>f;
  14. cout<<"\n\tEnter sampling points:";
  15. cin>>fs;
  16. w=2*3.14*f;
  17.  
  18. initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  19. line(0, 0,0,500);
  20. line(0,200,800,200);
  21. // getch();
  22.  
  23. for(int n=0;n<640;n++)
  24. {
  25. w1=w*n;
  26. x=a*sin(w1/fs);
  27. x=x+200;
  28. putpixel(n,x,25);
  29. }
  30. getch();
  31. closegraph();
  32. return 0;
  33. }
Last edited by Nick Evan; Jul 25th, 2011 at 4:18 am. Reason: Added CODE-tags....
Reputation Points: 6
Solved Threads: 0
Newbie Poster
jayeshkamble143 is offline Offline
1 posts
since Jul 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: C pass array to a function
Next Thread in C Forum Timeline: Why are ints printed as "%d"?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC