LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Waveform Subtraction code examples

Is there any sample code anywhere that deals specifially with waveform subtraction in C and/or CVI?



Thanks
0 Kudos
Message 1 of 8
(4,285 Views)
What exactly are you wanting to do?
 
Subtracting one waveform array from another is trivial. Unless I am missing something here...
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 2 of 8
(4,276 Views)
Hi.

You could try the Sub1D() function from the Advanced Analysis Library. It operates on arrays of doubles. If necessary, first call ConvertArrayType() from Programmer's Toolbox.

Regards,
Colin.
0 Kudos
Message 3 of 8
(4,274 Views)
I'm really just trying to measure noise on a system.  I am using a digitizer with 2 channels and I would like to split a signal sending it directly to one channel and also through my system to the other channel.  Then I need to acquire 2 waveforms, one from each channel.  Then I just want to subtract the clean signal from the noisy one to measure the noise in the system. 

I think there is a Fetch function in the niScope driver that makes this possible but I have found very little documentation for the specific subtraction of one waveform from another. 



0 Kudos
Message 4 of 8
(4,272 Views)

Well... This is not as simple as it sounds.

In order for you to get a reasonable approximation of the system noise, your waveforms must be of the same amplitude, frequency and phase and your sample arrays must be of the same length.Since you are sending the source signal through the system and then trying to compare it, you are going to have to deal with system delay (which produces a phase shift that is going to be frequency dependent) and any possible distortion of the waveform through your system.

Doing a simple subtraction of the input waveform from the output is only going to be a gross approximation, not a precise measurement. The problem is that you are not going to be able to correct for any harmonic distortion that may be present on the output signal that may not be there on the input.

What you really want to do is measure the broadband output RMS voltage (or power) of the system output signal with no input signal applied and the input terminated in the characteristic impedance of the signal source. This will give you the noise floor for the system. You can then measure the RMS voltage (or power) of the output signal with the input signal applied and using the appropriate formula below, get the signal-to-noise ratio (SNR) of the system.

SNR = 10*Log(Signal Power / Noise Power) 

SNR = 20*Log(Signal Voltage, rms / Noise Voltage, rms)

Now be aware that this is still only an approximation because your measurement instrument and any signal-conditioning you do are also going to add some noise in the form of quantization noise in the ADC, thermal noise in any active and passive signal processing components and any crosstalk or pickup of external EMI sources. If the noise contribution of your measurement system is at least 10 dB below the noise floor of your system under test, you will get a reasonable approximation, if not, you will have to correct for the measurement system noise contribution.

You must also be cognizant of the fact that your ADC is only going to be able to measure noise from DC to the Nyquist frequency (sample rate/2). This may or may not be sufficient for your purposes, if the bandwidth of interest is included within those limits, you will get a reasonable measurement, if not, you may need to use a faster sample rate. There are other considerations as well that have to do with the data buffer depth and the frequency-domain bin size that are interelated and will have a bearing on the accuracy of your measurement.

To get a fully accurate picture of the noise and distortion of your system, you will also need to measure the THD+Noise performance of your system. You do this by injecting a clean, undistorted sine-wave into your system at the frequency of interest and then transform the time-domain sample buffer into a frequency-domain representation. From there, you can calculate the THD.

You can get good information on how to do that here:

http://en.wikipedia.org/wiki/Total_harmonic_distortion

and here:

http://www.dogstar.dantimax.dk/tubestuf/thdconv.htm

There is a very good discussion of what each of these terms mean in reference to ADC systems and the formulas for deriving them here:

http://www.analog.com/en/content/0,2886,760%255F788%255F91250,00.html

Noise is a very complex subject, the following page will get you started on understanding the various types of noise, their sources and their characteristics:

http://en.wikipedia.org/wiki/Noise_%28physics%29

Bottom line is that what you want to do isn't as simple as you may wish it to be. The pages referenced above will get you a good start on understanding the problem and how to calculate what you need.

Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
Message 5 of 8
(4,251 Views)
Hi Martin,

Thanks very much for taking the time to respond.  The details you have provided will be a great help. 

Very much appreciated.


Thanks again.
0 Kudos
Message 6 of 8
(4,243 Views)
Wow -- awesome response, Martin! Thank you so much for taking the time to contribute all of that information.
Charlie S.

Visit ni.com/gettingstarted for step-by-step help in setting up your system
0 Kudos
Message 7 of 8
(4,232 Views)

No problem, I spent many years in the RF and telecommunications fields and noise has always been something I have had to be cognizant of. I'm a bit rusty on a lot of it but I still retain enough to throw out a little help now and then.

I'm now working in the power electronics field and have to deal with other aspects of noise, particularly EMI and RFI emissions from switching power supplies.

 

Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 8 of 8
(4,221 Views)