Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1275

Python • Using numpy to create a sine wave with complete cycles

$
0
0
I'm using numpy to create a sine wave sample. I would like to have the script truncated to the nearest full (or half) cycle. How would I calculate that, or otherwise trim the sample so that it ends at an amplitude of zero?

Code:

duration   = 0.11    # base in seconds                                          sampleRate = 44100   # integer sample rate, Hz                                  frequency  = 440.0   # float sine frequency, Hz                                 sample = (numpy.sin(    numpy.arange(sampleRate * duration) * frequency / sampleRate \    * numpy.pi * 2)).astype(numpy.float32)
It's been too long since I've done much of any trigonometry.

Statistics: Posted by tpyo kingg — Sat Feb 10, 2024 3:22 pm



Viewing all articles
Browse latest Browse all 1275

Trending Articles