Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
cs190c:lab4_09 [2009/02/06 12:11]
tang sdg
cs190c:lab4_09 [2009/02/11 10:00] (current)
seh
Line 70: Line 70:
 ===== In-Lab Problem ===== ===== In-Lab Problem =====
 Write the required <​html><​code>​sin_sample</​code></​html>​ function for the [[cs190c:​project1|project]]. Work in pairs, but turn in your own code on Blackboard (don't have just your partner turn it in). The only file you need to submit is primitives.py. Write the required <​html><​code>​sin_sample</​code></​html>​ function for the [[cs190c:​project1|project]]. Work in pairs, but turn in your own code on Blackboard (don't have just your partner turn it in). The only file you need to submit is primitives.py.
 +
 +<code python>
 +def sin_sample(freq,​ amp, dur):
 +    """​
 +    sin_sample(freq,​ amp, dur)
 +    ​
 +    This function returns a sine wave with frequencey freq, amplitude amp,
 +    and duration dur (in seconds). The smplitude should be specified
 +    with a range of 0 to 1 where 1 represents the maximal amplitude.
 +
 +    To obtain the actual amplitude in the sample use the WAVE_MAX value
 +    to scale it to an appropriate value.
 +    """​
 +    output = empty(int(dur*SAMPLE_FREQUENCY),​ dtype=numpy.int16)
 +    factor = WAVE_MAX*amp
 +
 +    for t in xrange(0,​len(output)):​
 +        output[t] = factor*math.sin(2*math.pi/​SAMPLE_FREQUENCY*freq*t)
 +
 +    return output
 +</​code>​
  
  
 
cs190c/lab4_09.txt ยท Last modified: 2009/02/11 10:00 by seh
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki