# StackMat G4 signal glitch?



## Voltara (May 24, 2018)

I purchased a StackMat G4 timer to experiment writing software to interface it with my computer. While doing that, I encountered a semi-frequent glitch in the output signal that causes single-bit errors in the data.

Here's what the glitch looks like:
https://imgur.com/a/QHMC56d​
What happens is sometimes when the signal is supposed to invert (low->high or high->low), it instead inverts twice: low->high->low or high->low->high. This may not be completely obvious from the images because it's being smoothed into a shallow dip either by capacitance or the sampling rate of the sound card; I have not yet hooked it up to an oscilloscope.

I'm already detecting and correcting for this in software, but I'm curious to know whether anybody else has encountered this, or if it's just a defect in my particular timer?


----------



## Lucas Garron (May 30, 2018)

I believe Tim Habermaas and Jeremy Fleischman have the most experience in reverse-engineering Stackmat signals; I'll ask them to respond here if they know anything about this!


----------



## jfly (May 30, 2018)

I can't say I've seen this exact abberation before, but as you said, it doesn't look like a big issue, so long as you have nicely tuned high and low water marks for declaring that the signal has changed from high to low.

This is not super relevant to you, but I started a page here: https://www.jflei.com/stackmat-phones/ documenting what various phones see when they attempt to record a stackmat signal. I didn't keep track of which stackmats were used for which experiments, however.


----------



## tim (May 30, 2018)

I can't remember seeing that glitch either when working on https://github.com/timhabermaas/stackmat.js. I haven't used the new G4 timer when building it, though.


----------



## Voltara (Jun 1, 2018)

Thanks for the replies. I will experiment more with the hardware when I get an opportunity to borrow a scope (though the one likely available to me is not a storage scope, so it may be of limited use.) Another idea might be to connect it to an Arduino board and have it time the pin change interrupts.

By the way, I found the collection of phone recordings to be very informative. I wonder if the distortion is completely due to voice band pass filtering, or if there are other contributing factors. I tried a couple of different sound card inputs at home (laptop, desktop, external USB audio.) The laptop was fine, but the sample rate on the desktop dropped as soon as I turned on the stackmat (but returned to normal after I shut it off) - my guess is it didn't like the input voltage. The USB device (M-Audio Fast Track Pro) has a "pad" button which you can use to attenuate inputs that are too hot. With the "pad" disabled, the waveform was heavily distorted - and in places it almost looked like the ADC counter overflowed from positive to negative in some spots. Enabling the "pad" helped a lot, though it was still far from perfect.

I have a Moto X Gen 2 (one of the phones for which you have a recording), so I could try duplicating the distortion with mine, then try attenuating the signal to see if it helps. I'll have to look around to see if I have a spare TRSS plug.

Another source of distortion, which you can see pretty clearly in the "nexus" track of https://www.jflei.com/public/img/dialup-stackmat/stackmat-fsk-gerty-nexus5-iphone3gs.png is the DC offset removal at the audio input. That's what is causing the flat tops of the square wave to ramp toward zero. It's happening in the "iphone" track too, but it's harder to see.


----------



## Voltara (Jun 21, 2018)

jfly said:


> This is not super relevant to you, but I started a page here: https://www.jflei.com/stackmat-phones/ documenting what various phones see when they attempt to record a stackmat signal. I didn't keep track of which stackmats were used for which experiments, however.



I got a couple of parts in the mail today, so I'm back experimenting with the G4's signal. My Moto X Gen 2's captured signal looks basically identical to the one you documented: a high-pass filtered square wave. Since I was curious about the iPhone signal which looked particularly bad, I searched and came across https://blog.faberacoustical.com/2009/ios/iphone/iphone-dock-and-headset-io-frequency-response/ which shows a steep rolloff below 200 Hz. A later post on the same blog points out that iOS 6 fixes this behavior: https://blog.faberacoustical.com/20...6-kills-the-filter-on-headset-and-mic-inputs/ I wonder if you saw any improvement after the upgrade to iOS 6?

My current prototype is using on-off keying of a 2200 Hz square wave carrier with good success. It's based on Arduino which is way overkill... I'm thinking the same basic concept could also be implemented very inexpensively with a 555 timer output through a tri-state buffer pulled to half Vcc - the stackmat signal controls the Output Enable pin of the tri-state. However, one advantage of using a microcontroller is it can be programmed to correct the glitch I described in the original post.

By the way, I was able to confirm the issue with a short Arduino program that uses a pin change interrupt and logs the timing of the pin changes via serial output. One thing I noticed is it only seems to glitch when the timer is idle - so maybe the stackmat enters a power-saving mode when the timer's not running, and that's causing occasional problems with the signal?


----------



## Voltara (Jun 28, 2018)

To follow up on my previous post, the 555-based circuit worked just fine, but I came up with an even simpler way to modulate the Stackmat signal. This new version is passively powered - no batteries needed.

Other than the TRRS jacks/plugs, all it requires are:

2 1k resistors
1 1.6k resistor (I used two 3.3k in parallel)
1 10k resistor
2 100nF ceramic capacitors
1 N-Channel MOSFET (I used a ZVN4206AV which I had left over from a previous project)

I created a model of the modulator on the falstad.com circuit simulator: http://tinyurl.com/ybgz4for

A sine-wave carrier, supplied by the computer/smartphone through the left audio output, is OOK modulated by the Stackmat data signal, and the result is fed back into the computer/smartphone microphone input.

I used an 18 kHz tone in my testing, which is nearly inaudible when I accidentally play it at full volume while wearing headphones. Lower frequencies such as 4 kHz work too, however the lower the frequency, the less sharp the on/off transitions will be in the modulated signal.


----------

