# What is the best way to detect rectangular pulse for AFSK demodulation?

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?

• 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. Apr 17, 2020 at 20:49
• 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? Apr 17, 2020 at 20:57
• yeah, the polarity is reversed, and these points are called zero-crossings, the duration between neighboring zero-crossings means zeros and ones Apr 18, 2020 at 19:03

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.