I’m trying to detect various features of a toy train track while driving on it: example test setup

The primary input is data from an optical sensor. The following image shows the recorded signal when driving over the railway switch (at the bottom of the pictured track) and the curved segment after it (click to enlarge): signal

I want to detect:

  1. the start/end of each track and
  2. the presence of switch tracks.

The first one is easy to extract from either the black or the blue signal using a few lines of C code. But I run into trouble as soon as I try to distinguish between a switch track center and a rounded male connector (like the one at the end of the switch track segment). Both produce relatively similar long, jagged drops in the blue and black curves and there’s significant variance across multiple runs.

I can distinguish these features quite well by looking at the graph, but I don’t know how to "pour" this into code that classifies reliably. I have no real background in signal processing or classification algorithms so I lack the vocabulary and intuition to even search for possible solutions.

I’m looking for online algorithms, i.e., they should classify these features while driving on the track. Ideally, it should be able to run on a small embedded computer, but I’d appreciate any pointers to techniques that might work, even if they might require more processing power.

Disclaimer: I’ve originally posted this question on the Signal Processing site but it seems that Cross Validated is a better fit.

  • 1
    $\begingroup$ I agree with @user86895's answer. By the way when you say real-time, what delay are you allowing for the decision? When you perform a visual inspection ("I can distinguish these features quite well by looking at the graph") you are probably looking not only at the onset of each event but at the entire pattern, which may include future information if your decision delay is short. $\endgroup$
    – Steven
    Jan 7, 2018 at 16:21
  • $\begingroup$ @Steven, it’s mostly about the mapping part of SLAM, i.e. it’s fast enough to classify a track segment after we’ve cleared it (eg. 100ms after we’ve passed the beginning of the next segment). The delay could be longer (eg. 1s after clearing the segment) but then buffering all the data might become a problem on embedded devices and we’d already have cleared the next 3-4 segments by then. (Throughput must be around 4-5 segments per second at normal driving speed.) $\endgroup$
    – rluba
    Jan 7, 2018 at 20:05

1 Answer 1


Note sure if it could run on a small embedded computer, but this is otherwise a good use case for a recurrent neural network, provided that you have a lot of labeled data. You may also be able to use a time window aggregation approach (e.g., just transforming some section of the tracing into a vector and then using a non time-series model to classify it).

If you don't have a lot of labeled data, unsupervised learning might help to get them. Some kind of dimensionality reduction (e.g., for PCA is looks like there might be a question of interest here) might show that the different locations on the track are very far from one another. Hallac 2017 might help, too.

  • $\begingroup$ Thank you, @user86895. It’s been a decade since I worked on neural networks, but I don't think we can feasibly generate enough training data for a neural network without introducing track sequence biases (eg. traversing hundreds of times over the same track course, thereby learning the sequence of segments of this route instead of the characteristics of each individual track segment.) I’ll look into all the other techniques you’ve mentioned. $\endgroup$
    – rluba
    Jan 7, 2018 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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