Home > other >  How to generate a sine wave in python?
How to generate a sine wave in python?

Time:03-04

To generate a csv file where each column is a data of sine wave of frequency 1 Hz, 2 Hz, 3Hz, 4Hz, 5Hz, 6Hz and 7 Hz. The amplitude is one volt. There should be 100 points in one cycle and thus 700 points in seven waves.

CodePudding user response:

Here is how I will go about it:

import pandas as pd
import numpy as np

freqs = list(range(1, 9))
time = np.linspace(0, 2*np.pi, 100)
data = {f"{freq}Hz": np.sin(2 * np.pi * freq * time) for freq in freqs}

df = pd.DataFrame(data)
df.head()

    

enter image description here

  • Related