Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am developing an application for an oscilloscope in c# .NET, I am drawing different kinds of waves (sine, square etc..) with the help of zedgraph control.
I get values from oscilloscope and stored in a buffer of size 1024(byte array) and have to calculate parameters like time period, Frequency, rise time, fall time etc at run time.
for this purpose i have to extract only a single cycle of whole signal.one more problem is that values are not always rise or fall continuously mean values are stored in buffer like this[0,0,0,1,1,2,3,4,5,5,6,6,6,5,5,4,3,2,1,1,0,0,0..........]. signals are continuously receive from machine.
it is not sure that waves are always oscillating around zero.
Thanks
Regards
Nilesh
Posted
Updated 5-Jun-21 7:19am

If you really need frequencies, it does not really matter if the waves are "oscillating around zero" or not (average signal shifted up or down).

All relevant algorithms can be found here:

http://en.wikipedia.org/wiki/Fourier_analysis[^],

http://en.wikipedia.org/wiki/Fourier_transform_spectroscopy[^],

http://en.wikipedia.org/wiki/Fast_Fourier_transform[^],

but not here: http://en.wikipedia.org/wiki/Fast_food_restaurant[^] or here: http://en.wikipedia.org/wiki/Fast_%26_Furious[^] :).
 
Share this answer
 
Comments
Espen Harlinn 22-Jan-11 8:22am    
Good links SAKryukov - there is also Wavelets, but I guess you know that quite well :) http://en.wikipedia.org/wiki/Wavelet
Sergey Alexandrovich Kryukov 22-Jan-11 14:41pm    
Espen, thank you very much for this extra reference.
No, I did not think about Wavelets.
--SA
First off, no oscilloscope I've ever used gave me integer samples, so I'll assume you are receiving real values and just used integers for a example. I'll also assume that the sample signal is known to be periodic, even though the period may not be known.

Select a sample set beginning at an arbitrary crossing point equal to the midpoint between the minimum and maximum values recorded, and ending at the next point where the signal again crosses that value. Count the number of samples in the set and divide by the sample rate. Take this to be the period of the signal, and 1/T = frequency. Calculate the RMS value of this sample set and divide by 2; this is the DC offset of the signal. Subtract the DC offset from each point in the sample to normalize the values to the 0 axis. Now cycle through the samples to find the maxima and minima, and locate the crossing points where the signal values cross the 90% (rising) and 10% (falling) values, relative to the peaks. Taking the total number of samples in the set as N, each step between samples represents T/N seconds. By checking the indices of the 10% and 90% samples, relative to the normalized zero crossings, you should easily be able to calculate the rise and fall times of the sampled signal.

FFTs are handy, but they're meant for frequency domain analyses, and you're asking for time domain results. Unless you know very accurately the initial and boundary conditions for each sample set, converting from the frequency domain to the time domain will yield arbitrary and inaccurate results. Sticking to time domain calculations is easier in this case, but make sure that you take your oscilloscope samples at an appropriate rate. I assume that you have control over the 'scope settings, as well as the ability to monitor results. If you are sampling at less than twice the fundamental frequency, you're losing information; if you sample at much more than that, you risk aliasing errors. Do the initial calculation as I've described, then adjust the sweep rate of the 'scope to collect samples at an appropriate rate.
 
Share this answer
 
Comments
NileshKRathod 22-Jan-11 2:22am    
thanks roger..
you are right oscilloscope isn't generate integer samples its double type i just give the example of my array values.
second thing is i get the average value of signal but i need the code of select a sample set of values.
my code is not working....
once again thanks for your help
Sergey Alexandrovich Kryukov 23-Jan-11 13:18pm    
Agreed - my 5. Excellent answer.
Thank you Roger,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900