Python Forum

Full Version: Creating Data Set for Changing Oscillation Motion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I need to create a set of data points that are essentially x and y values for a graph of position vs time. the x values range from 0 to 40 in seconds and the y values correspond to changing oscillatory motion. For example from 0 to 5 seconds I want a wave function with a frequency of 0.5 Hz then from 5 to 10 seconds I want to increase the frequency to 1.0 Hz. My position is what is changing to mimic sinusoidal waveform similar to a mass on a spring starting from a position of zero.

I'm not as concerned with the amplitude i.e. it could be 1 to -1. I thought I could do this using interpolation but i'm not sure how.

This is how it was done for a more simple motion in the past:
def synth_sledge():
    seconds = np.arange(0, 15, 1/1000)
    #evenly spaced values within a given interval
    e = 0.00000001
    points = np.array([
        [0, 0],
        [0+e, 0],
        [5, 0],
        [5+e, 0],
        [15, 6],
        [15+e, 6],
        ])
    pos = scipy.interpolate.interp1d(points[:,0],points[:,1], kind='quadratic')(seconds)
    return seconds, pos

t, x = synth_sledge()
x=scipy.ndimage.gaussian_filter(x, 50)
I'm new to python so anything helps!