I have an old audio cassette tape of digital data I converted to .wav and am hacking to recover the original data. I demodulated the 4K/2K FSK modulation with minimodem. Then I get stuck with insufficient understanding of the NRZI bit-stuffing algorithm. Short-cut: does anybody know of sox-like or minimodem-like program that does NRZI decoding through Linux pipes?

Many references explain that bits are stuffed into NRZI data streams after 5 consecutive bits of one polarity. But to be precise, I haven't found a clarification. Does this mean:

1. a bit stuff happens after 5 bits, or 
2. a bit stuff happens in order to prevent a run of 6 bits?

By example, if the original data is ...11111001... does it get transmitted as is, or does a bit stuff occur to send the data ...111110001... ? If the bit-stuff is only to cause a transition after 5 bits, then the stuff is not necessary. But the docs say "after 5 bits" which would create unnecessary stuffs if the original data had inherent runs of exactly 5 bits.

Here's the bit stream I'm trying to decode.

    root@kali:~# minimodem --rx -R 44100 --mark 4000 --space 2000 --binary-raw 26 -f monoshort8008.wav 500
    CARRIER 500 @ 4000.0 Hz
    11111111111111111111111111
    11111111111111111111111111
    11111111111111111110111010
    00001111100000100000111110
    00001000001111100000100000
    11111000001000001111100000
    10000011111000001000001111
    10000010000011111010101011
    11111110100010001011111000
    00100000110000010010111000
    00101100110101110111111000
    10101000110000010101111000
    00100000110100010001011000
    00100101110101110101011000
    10101001110110010101111000
    10101000110101110000011011
    00100000110101110100011001
    00101011110110010100011000
    00101011110000010000011010
    00100111110000010110011010
    11101011110001010100111000
    00101011110000010000011001
    00100001110000010110011010
    11101001110001010100111000
    00101011110000010000011011
    00100100110000010110011000
    11100010110001010100011000
    00101011110111110111111011
    11101111110000110111011110
    NOCARRIER ndata=29 confidence=150.653 ampl=0.126 bps=500.04 (0.0% fast)

Notice the sets of 5 bits near the beginning. Notice also the periodicity of 13 bytes, visible as vertical column runs of 1 or 0 through all the data.

Andy suggested Octave check the frequencies of the modulation.  Here is a plot of the data - x axis is unscaled.  Data was collected at 44,100 Hz.  Working the scale factor shows 2K and 4K Hz 2msec bits. 
[![Octave wav data plot][1]][1]


  [1]: https://i.sstatic.net/Z9Xfe.jpg