Using sox to generate a square wave signal

Posted on

Problem :

I have a script ( which uses sox to generate a wave form from a series of “pulses” and “spaces” generated by lirc from a remote control. The script creates a 19kHz sine wave for the pulses and “silence” for the spaces.

I would like to convert the resulting wave file to digital data (where the pulses (and their length) mark a one and the spaces a zero. Since this is on-off-keying there are various tools to do this for me. The problem is that those tools require the ones to be “maximum volume”, instead of a sine wave.

My question is – what can I use with sox to generate periods of “high volume”? Like the “pad” option, but outputting maximum volume instead of 0?

Solution :

I managed to figure it out. I used square instead of sine, as @dirkt suggested, but I had to lower the square wave frequency enough so that a “square” period is greater than my longest bit length. I tried a 10Hz square wave and here is the diff:

<       SOX_OPT="${SOX_OPT} synth ${LEN}s square 10 0 0" # square wave 10Hz
>       SOX_OPT="${SOX_OPT} synth ${LEN}s sine 19k 0 0 sine 19k 0 50" # sine wave 19kHz 2ch phase shift

The results look like this:

  • modulated sine wave:

  • square signal: