#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0

    Sine wave plotted in file


    represent a sine
    wave with a period of 20ms.

    this has to be representet in numbers, plottet into a file, and it has to be in a function sine(), but most of all i need help how to generate the numbers for the sine signal? :P
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0
    very simplistically:

    Code:
    #vary parameters to get the amplitude/wavelength you want.
    import math
    plotend=2*math.pi
    l=[]
    x=0
    while x<plotend:
    	l.append(math.sin(x))
    	x+=0.01
    #print l to file
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by verstapp
    very simplistically:

    Code:
    #vary parameters to get the amplitude/wavelength you want.
    import math
    plotend=2*math.pi
    l=[]
    x=0
    while x<plotend:
    	l.append(math.sin(x))
    	x+=0.01
    #print l to file
    it somewhat helps, but i cant really figure out how to implement it, i want to be able to yield one number at the time and plot it into a file, where every line in the file is a ms in time
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,889
    Rep Power
    481
    You could replace
    l.append(math.sin(x))
    with
    print(math.sin(x))
    or even
    print('%g %g'%(x,math.sin(x)))


    then run python on the command line redirect stdout to a file. Yes, it ought to work in DOS.

    shell_prompt> python my_program.py > sinusoid.dat
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65
    Is there a relationship between x in sine(x) and time?
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

IMN logo majestic logo threadwatch logo seochat tools logo