Introduction

The Simple Signal Generator is a C# class designed to generate four simple periodic waveforms including sine, square, triangle, and sawtooth. The class is provided for testing software and hardware components during the development of measurement applications. A generated signal varies across time domains, and by default, is normalized by the amplitude A € [-1,1] and period T € [0,1]. It is possible to set an arbitrary amplitude, frequency, DC-offset, and phase shift, and to invert the signal.

Background Display

There are a couple of articles on The Code Project that describe in detail about developing different user defined components for dynamically changing single values or signal shapes such as bars, graphs, charts, gauges, and a diversity of other instruments.

For testing those components, functions like y=F(x) are very often used. These functions are typically periodical, mostly sine, and their variable x will be modified in a loop with constant steps across an interval [x0,xn].

Hardware developers use a totally different technique. For analyzing and troubleshooting electronic systems, they use an additional external device called signal or function or waveform generator. The signal generator is an important piece of electronic test equipment, and should not be missed in any electronics laboratory.

On the device, we can select a built-in periodical function like y=F(t); the variable t represents real time, and we can change some parameters like frequency, amplitude, and the DC-offset. Typically, there are four basic signal types.

After customization, the desired output signal can be wired on to the input of the component that should be tested, and we monitor their response function in the time domain using an oscilloscope.

Displayed here is a typical low-cost signal generator that has on its front panel, a radio-button with four positions to choose signal types and three potentiometers to adjust frequency, amplitude, and DC-offset. It is no big problem for hardware dudes to make something such as this, especially with tips from the book [1].

Of course, there are much better and more expensive devices on the market with more functions, more parameters to choose, better range and a finer scale for these parameters, integrated display to show selected settings, user-defined functions, on-board memory, better stability, and two or more independent channels.

Note that, there are two very significant differences between the hardware and the software approach. Hardware developers use an external device, and a test signal is in the time domain, which implies that the test signal varies totally independent from the assembly that will be tested.

The class presented offers a software equivalent for the above described real, simple signal generator device.

This should be used publicly only for DEBUG purposes, eventually during tests by adding new signal types!

All signals have a normalized period T € [0,1] in cycles, and not the usual T € [0,2Pi] in radian. In this case, a value 1 corresponds to a full cycle. The basis for this is an easier deal with normalized values, for example, for scaling operations by fitting in a window.

The signal generator is given as a class, but it is quite easy to transform it to a non-visual, or yet to a visual component, or maybe to a form like a front panel.

For generating all the given signals, very simple functions are used, but they are not the simplest. Some functions can be made simpler, but a development goal of this project was to generate signals exactly like the following example on Wikipedia:

The first example uses a compiled Simple Performance Chart, a component from eclipse2k1. It is a piece of homework to select one of four different signal types. Here, we can see how the selected signal can be adjusted and what trouble can occur with signals in real time. You should try out what happens with higher frequencies and lower sampling rates, and how to find an optimal refresh rate.

For the second example, a light modified Sliding Scale Gauge, a component from Tefik Becirovic, is used. Here, five instances of the signal generator class are defined. All these generate sine waves with the same (default!) parameter settings. The generated signals have a small phase shift. A prize question is how to synchronize all the five signals.

Conclusion

Any suggestions/comments/feedback is welcome and highly appreciated.

If you like it, please vote, and if you use it commercially, describe your success story in the discussion board below.

Comments and Discussions

According to the description, this class is intended to be used in testing software and hardware. However, I think for hardware is useless, since it generates aliased signals, which are not ideal to measure any device. I would suggest to add anti-aliased versions for each one by just adding sinusoids up to a certain sampling rate. You can check their amplitudes in Wikipedia. Also, there are more advanced techniques as explained here: http://www.music.mcgill.ca/~gary/307/week5/bandlimited.html[^]

Theoretically, you have right in all points, but this program is not made or used for signal synteshis. It is written and used in a real environment [LINK] as a replacement for a simple signal generator (physical device).

By taking measurements of a signal at regular intervals, a discrete signal results. Each measurement is called a sample. A signal generator can be considered as a function: sample = F(time), for given frequency, amplitude, phase and offset.

You must be able to calculate exact sample in any point of time for a given function F and set of parameters f, a, p and o.

If there is a diference between expected and given results or an error in the calculation occured, please tell me, and I am ready to correct this.

On the other side, while using this program, you must take attention about following points:

A sampled signal thus needs at least two sample points per cycle. Put another way, the signal's frequency must not be above half the sampling frequency. This limit is called the Nyquist limit of a given sampling frequency.

If a sine wave higher than the Nyquist frequency is sampled, a sine wave of lower frequency results. This effect is called aliasing.