Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

I am a power systems engineer and am doing preliminary leg-work for detection of a specific anomaly in power systems that cause the observed waveform to be distorted. False positives are somewhat acceptable here, as missing the said event can be catastrophic. This is what the signal looks like: Waveform-1000 Samples

Now this waveform is an output of a anomaly simulating setup that has been fed a pure sine wave of 50Hz, captured using an Oscilloscope at 1000 samples representing what was being displayed on the screen.

Questions:

How do I detect where one cycle starts and ends programatically, where there are multiple points representing the zero crossover?

I'd run an FFT over it once I can do that, but might need help in interpretation.

I do not have a formal background in DSP but am open to all reasonable ideas and suggestions, and willing to learn.

P.S. Here are the 1000 Samples

-3.15, -3.15, -3.24, -3.34, -3.53, -3.63, -3.73, -3.82, -4.02, -4.02, -4.11, -4.21, -4.31, -4.50, -4.50, -4.50, -4.60, -4.70, -4.79, -4.89, -4.99, -5.08, -5.08, -5.18, -5.28, -5.37, -5.47, -5.57, -5.66, -5.66, -5.86, -5.95, -5.95, -6.05, -6.15, -6.15, -6.24, -6.34, -6.44, -6.44, -6.53, -6.53, -6.63, -6.73, -6.73, -6.82, -6.92, -6.92, -6.92, -7.02, -7.02, -7.12, -7.12, -7.21, -7.21, -7.31, -7.31, -7.31, -7.31, -7.31, -7.41, -7.41, -7.41, -7.50, -7.41, -7.50, -7.41, -7.50, -7.41, -7.41, -7.41, -7.31, -7.31, -7.21, -7.12, -6.92, -6.63, -6.15, -5.37, -4.21, -2.76, -1.60, -0.82, -0.44, -0.24, -0.15, -0.05, -0.05, 0.05, -0.05, 0.05, -0.05, -0.05, 0.05, -0.05, -0.05, -0.05, -0.05, 0.05, -0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, -0.05, 0.05, -0.05, -0.05, 0.05, 0.05, 0.05, 0.05, 0.05, -0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.15, 0.05, 0.15, 0.15, 0.15, 0.24, 0.15, 0.15, 0.15, 0.24, 0.15, 0.15, 0.15, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.44, 0.44, 0.44, 0.53, 0.53, 0.53, 0.63, 0.73, 0.73, 0.82, 0.82, 0.92, 1.02, 1.02, 1.11, 1.21, 1.21, 1.40, 1.40, 1.50, 1.69, 1.69, 1.79, 1.89, 2.08, 2.08, 2.28, 2.37, 2.37, 2.57, 2.66, 2.76, 2.95, 2.95, 3.05, 3.24, 3.44, 3.44, 3.53, 3.73, 3.82, 3.92, 4.02, 4.11, 4.21, 4.31, 4.40, 4.50, 4.50, 4.60, 4.70, 4.79, 4.89, 4.99, 4.99, 5.08, 5.18, 5.28, 5.37, 5.47, 5.57, 5.66, 5.76, 5.76, 5.95, 5.95, 6.05, 6.15, 6.15, 6.24, 6.34, 6.44, 6.44, 6.44, 6.63, 6.73, 6.73, 6.73, 6.82, 6.92, 6.92, 7.02, 7.02, 7.12, 7.12, 7.21, 7.21, 7.21, 7.31, 7.31, 7.31, 7.41, 7.41, 7.41, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.41, 7.50, 7.50, 7.41, 7.41, 7.31, 7.21, 7.02, 6.63, 6.15, 5.37, 4.21, 2.76, 1.69, 0.82, 0.44, 0.15, 0.05, 0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.15, -0.15, -0.15, -0.05, -0.15, -0.15, -0.15, -0.05, -0.05, -0.05, -0.05, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.24, -0.24, -0.15, -0.24, -0.15, -0.24, -0.34, -0.24, -0.24, -0.24, -0.24, -0.24, -0.24, -0.34, -0.34, -0.24, -0.24, -0.34, -0.34, -0.34, -0.34, -0.44, -0.44, -0.44, -0.44, -0.53, -0.53, -0.53, -0.63, -0.63, -0.63, -0.73, -0.73, -0.82, -0.82, -0.92, -0.92, -1.02, -1.11, -1.21, -1.21, -1.31, -1.40, -1.50, -1.60, -1.69, -1.79, -1.89, -1.98, -2.08, -2.18, -2.28, -2.37, -2.47, -2.66, -2.76, -2.76, -3.05, -3.05, -3.24, -3.24, -3.34, -3.53, -3.63, -3.73, -3.82, -3.92, -4.11, -4.11, -4.21, -4.31, -4.40, -4.50, -4.50, -4.60, -4.70, -4.79, -4.89, -4.99, -5.08, -5.18, -5.28, -5.37, -5.37, -5.47, -5.57, -5.66, -5.76, -5.76, -5.95, -6.05, -6.05, -6.15, -6.15, -6.24, -6.34, -6.44, -6.44, -6.53, -6.53, -6.63, -6.73, -6.82, -6.82, -6.82, -6.92, -6.92, -7.02, -7.02, -7.12, -7.12, -7.12, -7.31, -7.31, -7.31, -7.31, -7.31, -7.41, -7.41, -7.31, -7.41, -7.41, -7.41, -7.50, -7.50, -7.41, -7.41, -7.41, -7.41, -7.31, -7.31, -7.21, -7.12, -6.92, -6.63, -6.15, -5.37, -4.21, -2.86, -1.69, -0.92, -0.44, -0.24, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, 0.05, 0.05, 0.05, 0.05, -0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, -0.05, 0.05, 0.05, 0.05, -0.05, -0.05, 0.05, -0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.15, 0.05, 0.05, 0.05, 0.15, 0.05, 0.15, 0.05, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.24, 0.15, 0.15, 0.24, 0.24, 0.24, 0.24, 0.15, 0.24, 0.24, 0.24, 0.24, 0.34, 0.34, 0.34, 0.34, 0.44, 0.44, 0.44, 0.53, 0.53, 0.53, 0.53, 0.63, 0.63, 0.73, 0.73, 0.82, 0.82, 0.92, 1.02, 1.02, 1.11, 1.21, 1.31, 1.31, 1.40, 1.50, 1.60, 1.69, 1.89, 1.89, 1.98, 2.08, 2.18, 2.28, 2.47, 2.57, 2.66, 2.76, 2.86, 3.05, 3.15, 3.24, 3.34, 3.44, 3.53, 3.73, 3.82, 3.82, 4.02, 4.11, 4.21, 4.40, 4.40, 4.50, 4.50, 4.60, 4.60, 4.79, 4.89, 4.89, 4.99, 5.18, 5.18, 5.28, 5.37, 5.47, 5.57, 5.66, 5.76, 5.76, 5.86, 5.95, 6.05, 6.15, 6.15, 6.24, 6.34, 6.44, 6.53, 6.53, 6.63, 6.63, 6.73, 6.73, 6.82, 6.82, 6.92, 7.02, 7.02, 7.12, 7.12, 7.21, 7.21, 7.31, 7.31, 7.31, 7.31, 7.41, 7.50, 7.41, 7.41, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.50, 7.41, 7.50, 7.41, 7.31, 7.21, 7.02, 6.73, 6.15, 5.47, 4.40, 2.86, 1.69, 0.92, 0.44, 0.15, 0.15, 0.05, 0.05, -0.05, -0.05, -0.05, -0.05, 0.05, 0.05, 0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.05, -0.15, -0.05, -0.05, -0.05, -0.05, -0.05, -0.15, -0.05, -0.05, -0.05, -0.15, -0.05, -0.15, -0.15, -0.05, -0.15, -0.05, -0.05, -0.15, -0.05, -0.15, -0.15, -0.15, -0.15, -0.05, -0.24, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.24, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.24, -0.15, -0.15, -0.24, -0.24, -0.24, -0.24, -0.24, -0.24, -0.24, -0.34, -0.34, -0.34, -0.24, -0.34, -0.34, -0.34, -0.44, -0.44, -0.44, -0.44, -0.53, -0.53, -0.53, -0.63, -0.63, -0.63, -0.73, -0.63, -0.73, -0.82, -0.92, -1.02, -1.02, -1.11, -1.11, -1.21, -1.31, -1.40, -1.50, -1.60, -1.69, -1.79, -1.79, -1.98, -2.08, -2.08, -2.37, -2.37, -2.57, -2.66, -2.76, -2.86, -2.95, -3.05, -3.24, -3.34, -3.44, -3.44, -3.53, -3.73, -3.82, -3.92, -4.02, -4.11, -4.11, -4.31, -4.50, -4.40, -4.60, -4.60, -4.70, -4.79, -4.89, -4.99, -4.99, -5.18, -5.18, -5.28, -5.37, -5.47, -5.57, -5.66, -5.76, -5.76, -5.86, -5.95, -6.05, -6.15, -6.24, -6.24, -6.34, -6.34, -6.44, -6.53, -6.53, -6.63, -6.73, -6.73, -6.82, -6.82, -6.92, -6.92, -7.02, -7.02, -7.12, -7.12, -7.12, -7.21, -7.31, -7.31, -7.31, -7.31, -7.41, -7.41, -7.41, -7.41, -7.41, -7.50, -7.41, -7.41, -7.41, -7.50, -7.41, -7.41, -7.41, -7.31, -7.21, -7.12, -6.92, -6.63, -6.15, -5.47, -4.40, -2.95, -1.69, -0.92, -0.53, -0.24, -0.15, -0.05, -0.05, -0.05, 0.05, -0.05, 0.05, 0.05, 0.05, -0.05, -0.05, -0.05, -0.05, -0.05, 0.05, -0.05, -0.05, -0.05, -0.05, -0.05, 0.05, 0.05, -0.05, 0.05, -0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, -0.05, 0.05, 0.05, 0.15, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.15, 0.05, 0.05, 0.05, 0.05, 0.05, 0.15, 0.15, 0.15, 0.05, 0.05, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.24, 0.15, 0.15, 0.15, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.34, 0.24, 0.34, 0.34, 0.34, 0.34, 0.34, 0.44, 0.44, 0.34, 0.44, 0.53, 0.53, 0.63, 0.63, 0.82, 0.73, 0.82, 0.73, 0.92, 1.02, 1.02, 1.11, 1.11, 1.21, 1.31, 1.40, 1.50, 1.60, 1.69, 1.79, 1.89, 1.98, 2.18, 2.28, 2.37, 2.47, 2.57, 2.66, 2.76, 2.95, 3.05
share|improve this question
    
"How do I detect where one cycle starts and ends programatically?" First you have to define where a cycle starts and ends non-programmatically. –  endolith Jan 4 '13 at 3:32
    
@endolith, I might have had the terminology wrong, but what I meant that the waveform must be periodic in the FFT aperture. I want to be able to discard the extra samples. –  Vaibhav Garg Jan 4 '13 at 3:37

3 Answers 3

First, you need to precisely define what you mean by starting point of the cycle. What exactly is your reference that determines t=0 and what exactly determines the start of the cycle

Your signal is comprised of the fundamental and a lot of odd harmonics. The fundamental is the strongest. You can easily determine the "start of the fundamental as follows:

Multiply the signal with a complex exponential of 50 Hz. Sum the result (which will be a complex number). Calculate the phase and the associated time delay. In your case this comes out to be 238.38 samples and roughly matches the maximum in the wave form.

You can do this with an FFT as well, but you need to make sure that the frequencies of interest (50 Hz, 150 Hz, 250 Hz, etc) are on the FFT grid. Assuming a 20 kHz sample rate, you could use an FFT length of 800 points which gives you a frequency resolution of 25 Hz and 50Hz would map to bin 2, 150 Hz to bin 6, etc.

You can also track the maxima and minima, which is much easier than the zero crossings for this waveform.

[EDIT: added Matlab code how to derive the fundamental delay] Multiplying with a complex exponential is basically the same as multiplying with a cosine and a sine wave. However this only works if your sampling clock doesn't drift a lot with respect to the 50 Hz fundamental and if the delay your are interested in is the delay of the fundamental itself. The higher harmonics have actually different delays.

% assume the signal is in variable x as a column vector
nx = length(x)
fs = 20000; % sample rate (guess on my part)
%
% create a complex exponentional at 50 Hz
cx = exp(j*2*pi*(0:nx-1)'*50/fs);
% scalar product
zx = sum(cx.*x);
% convert into a delay by calcualting pahse, wrapping and converting to 
% samples
za = angle(zx); if(za < 0), za = za + 2*pi; end
% phase to delay in samples
dx = fs * ( za/(2*pi)/50);
% plot original wave form delayed cosine
plot([x max(x)*cos(2*pi*50*((0:nx-1)' - dx)/fs)])
share|improve this answer
    
Thanks for the excellent suggestions. I need to figure out the complex exponential method. Could you please elaborate just a little bit? –  Vaibhav Garg Jan 4 '13 at 3:50

To detect where one cycle starts and ends programatically for this signal the simplest approach would be to detect when the sign of the gradient of the curve flips - this will give you the extrema of the signal.

To do so simply take the difference between the current sample and the previous sample - when this value changes sign you have reached an extrema.

share|improve this answer

It seems that there is an implicit assumption that the signal of interest has a fundamental of 50Hz. If this is the case, why not just collect N consecutive samples of the signal where N*T (T being the period of your sampling clock) is known to just exceed the period of the signal of interest(1/50Hz)? The FFT doesn't care where you start or stop your cycle as long as you capture a complete cycle.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.