1
$\begingroup$

I've got a WAV file with a rectangular pulses coding zeros and ones. By specification, a 1 bit is a 320 microseconds wide rectangle, and a 0 bit is a 640 microseconds.

So basically the idea is to detect "zero points" where the signal comes over the time axis. When I get it, further processing is trivial.

The naive approach is to iterate samples in the signal and find points where sample * sampleNext < 0.

For low-noise files with this approach produces rectangles quite close to the specified ones, but for high-noise ones I get all sorts of rectangles from 20 to 1400 microseconds in width.

Is there a better way to detect zero points in a noisy rectangular pulse?

$\endgroup$
3
  • $\begingroup$ Why are you mentioning AFSK in your question? AFSK means that 0 and 1 are being modulated as different change in frequency of carrier frequency. $\endgroup$
    – DSP Rookie
    Apr 17, 2020 at 20:49
  • $\begingroup$ So, even if we leave the AFSK part and go with what you have explained, you are changing the polarity of the rectangles too, right, and not just the duration between 320 and 640msec? $\endgroup$
    – DSP Rookie
    Apr 17, 2020 at 20:57
  • $\begingroup$ yeah, the polarity is reversed, and these points are called zero-crossings, the duration between neighboring zero-crossings means zeros and ones $\endgroup$
    – Hedin
    Apr 18, 2020 at 19:03

1 Answer 1

1
$\begingroup$

How about you take a short time Fourier transform with window length equal to the granularity with which you want to locate the zero crossing. At a zero crossing the signal will have high frequency components. You could detect those by running a short time Fourier transform on the incoming samples to identify the location of zeros. For ex: if you window 5ms of data and take FFT and see if there are high frequency components of significant magnitude then this would mean that this window contains the zero crossing. If you want, you can go even narrower like 1ms, but you be would loosing on frequency resolution. So, pick an optimum resolution in frqeuency and required zero crossing accuracy in time and window the incoming signal and keep taking the FFTs. You could go for rectangular windows.

Even if noise is high it will be constant in spectrum (atleast close to it as is theoretically for white nosie) and this should not be a big trouble in FFT domain, unless it is higher compared to signal power itslef.

For just 13 sample long pulse durations use the following emperical algorithm

Maintain two numerical derivate with a reference point x samples apart. Fir ex: consider "sample number" $N_o$, take two derivates between $N_o$, $N_o -x$ call this gradient 1, and second derivative between $N_o$, $N_o + x$, call this gradient 2, take the magnitude of these two gradients, if they are greater than a threshold, usually gradient is close to 90 degree near the zero crossing, then the point $N_o$ is a good approximation of zero crossing. $x$, and the threshold can be tuned based on pulse length.

$\endgroup$
3
  • $\begingroup$ Unfortunately, it doesn't work. My smallest rectangle is 300 microseconds which is at sample rate 44100 is just 13 samples long. I tried applying FFT with 8-sample window, but it makes little sense. $\endgroup$
    – Hedin
    Apr 19, 2020 at 17:41
  • $\begingroup$ @Hedin, I have edited the answer for microsecond pulses.please have alook $\endgroup$ Apr 19, 2020 at 18:22
  • $\begingroup$ I accept this answer as this works perfectly. Thanks a lot! $\endgroup$
    – Hedin
    Apr 20, 2020 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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