Always thought of making your own PC based signal generator?
Advantages of PC based signal generator: -
1. Low cost, no need to spend lot of money (costs about Indian Rs.30 = US$0.67 = costs almost nothing).
2. Can generate complex signals, like Sin(f1) + Sin(f2). Any function that you can write and understand its limits can be generated from PC.
3. Easier to operate, because, most people who finds signal generator useful are well versed in computer software + hardware.
4. If you use a output buffer amplifier, the chances of damaging your PC sound card is very small. In other words, it is safe.
5. Portable i.e only laptop is needed. Do not need to carry one more signal generator.
6. Use PC sound card, unless you listen to lot of music while working on electronics stuffs.
Disadvantages of PC based signal generator: -
1. Might damage your Sound card (and/ or) PC if you do not understand the limits and do not understand what are you doing.
2. Cannot generate frequencies higher than 20KHz (or slightly higher).
Simplest form of of PC based signal generator: -
I decided to go for the PC based function generator by generating the frequencies using the audacity software: -
http://audacity.sourceforge.net/
Once you install the software, it has a menu to generate a "tone". Just select the frequency you need and then PC generates the output (from the audio jack).
I observed the output from my PC by connecting the oscilloscope on the headphone output (audio jack). The output from my PC had good fidelity for frequency, but the output was centered around GND level (0V). That means, the output had both positive and negative half cycle. That was not a good news for me as most of my signals are interfaced to micro controllers, which accepts inputs from 0V and positive. In other words, I needed signal with DC offset added to it.
Searching the audacity menu, I could not find an option to add DC offset. Then I tried with MATLAB by writing a function to generate sine wave with DC offset, but still no help (read towards end of page to generate signals with MATLAB). Searching the internet, I found that it is actually a feature of sound card, by which it can eliminate any DC offset before the signal comes out. The main purpose is that audio signals with DC offset does not work good on speakers as they simply drive DC current without doing any vibration (which produces the sound). Moreover, DC offset reduces the dynamic range of a signal.
Observe the waveform below as how the sound card removes DC offset, when I tried generating a rectified sine wave (asb(sine()): -
In this picture, initially, the DC offset is present in the waveform. But as time progresses, the sound card removes the DC offset and signal becomes centered around the GND.
To add DC offset, I made a simple circuit which uses LM358 as non inverting summing amplifier. The circuit works good and is tested well with different frequencies. Moreover, this circuit (non inverting amplifier) acts as a buffer between the PC sound card and the external circuit. Hence it can supply the required current without loading the PC sound card.
INPUT_SIGNAL --> This signal appears from PC through a stereo jack.
DC_OFFSET --> This voltage source can be replaced by a pot which can be varied to generate different voltages.
OPAMP_GAIN --> Replace this fixed resistor with pot to get different amplifier gain.
330ohms + 2 diodes --> Used to clamp the output of amplifier between 0V and 5V (almost, ignoring the non rail to rail limitation and diode drops).
These are some pictures of my circuit: -
How to generate complex signals (using MATLAB) : -
If you have MATLAB on your PC, then you can use that to generate complex signals. Such complex signals cannot be generated by audacity software. The generation of complex signals is usually a feature of high end signal generator using DDS (direct digital synthesis). But using MATLAB and the circuit above, we can create a sophisticated DDS, where, the function is written on MATLAB and the same signal appears out of sound card, in physical form. Some codes for generating frequencies on MATLAB: -
---------------------------------------------------------------------------------------------------------
% code for generating sine wave of 1000Hz for 5 sec
t=linspace(0,4,50000);
y = sin(1000*2*pi*t);
sound(y, 10000);
% code for generating sine wave of 400Hz + 1000Hz for 4 sec
t=linspace(0,4,40000);
y1 = 0.5 * sin(400*2*pi*t);
y2 = 0.5 * sin(1000*2*pi*t);
y = y1 + y2;
sound(y, 10000);
% code for generating sine wave of 800Hz for 5 sec and half amplitude
t=linspace(0,4,50000);
y = 0.5 * sin(800*2*pi*t);
sound(y, 10000);
% code for generating full wave rectified sine wave of 1000Hz for 5 sec
t=linspace(0,4,50000);
y = abs(sin(1000*2*pi*t));
sound(y, 10000);
---------------------------------------------------------------------------------------------------------
As you can see, using MATLAB + PC sound card + circuit above, you can generate any signal you want. Only you need to imagine the signal, find its function and type into MATLAB.
The scope capture below shows the time domain and frequency domain analysis of complex signals generated: -
1000Hz Sine wave output: -
200Hz Sine wave output: -
15KHz Sine wave output: -
Complex waveform of 1000Hz + 400Hz Sine wave output (like DTMF waveform): -
Frequency domain spectrum of complex waveform of 1000Hz + 400Hz Sine wave : -
Note that the 2 frequencies are generated faithfully without any extra harmonics (within our band of interest).
Full wave rectified sine wave: -