Episode 3: Generating Signals

In this episode, you learn how to generate test signals with g.Pype.

We start with the same code from the previous episode. Note that the Generator constructor parameters channel_count, signal_frequency, signal_shape, signal_amplitude, and noise_amplitude are now explicitly set. We will explore their meaning in the following.

 1import gpype as gp
 2
 3if __name__ == "__main__":
 4
 5    app = gp.MainApp()
 6    p = gp.Pipeline()
 7
 8    source = gp.Generator(channel_count=8,
 9                          signal_frequency=10,
10                          signal_shape=gp.Generator.SHAPE_SINUSOID,
11                          signal_amplitude=25,
12                          noise_amplitude=0)
13
14    scope = gp.TimeSeriesScope()
15
16    p.connect(source, scope)
17
18    app.add_widget(scope)
19
20    p.start()
21    app.run()  # blocking until window is closed
22    p.stop()

But first, run the script and make sure it produces the same output as before.

S1E3 example screenshot

Figure 2: A minimal g.Pype application running with a signal generator and time series scope.

Now, let’s learn how to customize the signal generated by the Generator node.

Channel Count

The Generator can produce multiple channels in parallel. The default is eight channels. Change the channel count to 4 via channel_count=4 in the parameter list. Run the script again and observe that only four channels are shown.

S1E3 example screenshot

Figure 3: Reducing the channel count to 4.

Signal Frequency

You can set the frequency of the generated signal in Hertz (Hz). The default is 10 Hz. Change the signal frequency to 1 Hz via signal_frequency=1 in the parameter list. Run the script again and observe how slow the waves are now.

S1E3 example screenshot

Figure 4: Slowing down the sine waves to 1 Hz.

Signal Shape

The Generator provides three predefined signal shapes you can choose from:

  • Generator.SHAPE_SINUSOID – Sinusoidal waveform (default)

  • Generator.SHAPE_RECTANGULAR – Square wave

  • Generator.SHAPE_PULSE – Brief pulses at specified frequency

Set signal_shape=gp.Generator.SHAPE_RECTANGULAR in the parameter list and run the script again. Observe how the sine waves have turned into rectangular ones.

S1E3 example screenshot

Figure 5: Changing signal shape to rectangular waveforms.

Signal Amplitude

You can set the amplitude of the generated signal in µV. Change the amplitude via signal_amplitude=10 in the parameter list. Run the script again and observe how small the signals have become.

S1E3 example screenshot

Figure 6: Reducing signal amplitude to 10 µV.

Noise

It is also possible to add noise to the signal. By default, no noise is added. Set noise_amplitude=10 to add white Gaussian random noise with standard deviation of 10 µV to the signal. Run the script again and observe how much noise is there.

S1E3 example screenshot

Figure 7: Adding noise with 10 µV standard deviation to the signal.

You can also set signal_amplitude=0 while keeping the noise amplitude to generate pure noise. This can be useful for generating more complex signals, as we will see later in this training. Run the script again and observe that only noise remains.

S1E3 example screenshot

Figure 8: Generating pure noise by setting signal amplitude to 0.

Done! You are now familiar with the most important Generator settings to produce a variety mixtures of signals and noise.

Summary

In this episode, you learned how to adjust the Generator parameters to:

  • Change the number of channels

  • Adjust signal frequency and amplitude

  • Select different signal shapes

  • Add and control noise

All these parameters can be combined to create a wide variety of test signals for your experiments. Note that there are additional options available for advanced use cases. We will cover them in future episodes.

Proceed to the next episode to explore how TimeSeriesScope visualizes time series data in g.Pype.

File s1e3_generator.pyView file on GitHub

 1# --------------------------------------------------------------
 2# Example file s1e3_generator.py
 3# For details and usage, see g.Pype Training Season 1, Episode 3
 4# --------------------------------------------------------------
 5
 6import gpype as gp
 7
 8if __name__ == "__main__":
 9
10    # Create main app and pipeline
11    app = gp.MainApp()
12    p = gp.Pipeline()
13
14    # Create signal source
15    source = gp.Generator(channel_count=8,
16                          signal_frequency=10,
17                          signal_shape=gp.Generator.SHAPE_SINUSOID,
18                          signal_amplitude=25,
19                          noise_amplitude=0)
20
21    # Create scope
22    scope = gp.TimeSeriesScope()
23
24    # Connect nodes
25    p.connect(source, scope)
26
27    # Add widget to main app
28    app.add_widget(scope)
29
30    # Start pipeline and run application
31    p.start()
32    app.run()  # blocking until window is closed
33    p.stop()