# Can a neural network be used to detect sine waves?

I am recording the vibrations of an AC Motor (50Hz Europe) and I am trying to find out whether it is powered on or not. When I record these vibrations, I basically get the vibration values ($$-1$$ to $$+1$$) over time.

I would like to develop a program to detect the presence of a 50Hz sine wave on a steady stream of input data. I will have $$X$$ and $$Y$$ measurements, where $$X$$ represents amplitude and $$Y$$ the time (sampled at 100Hz - it is possible to increase the sample rate to 200Hz or 400Hz at max)

Is this a task suited for a neural network, and if so, would it be less efficient than other means of detection?

• A 50Hz sin wave sampled at 100Hz is going to appear as +x, -x alternating, maybe with some variation if there are other frequencies mixed in. It would be very difficult to assert anything about the shape of that wave. Also are you aware of Fourier analysis? It is possible to get the frequency mix of a signal using Fast Fourier Transform, but that is not quite the same as classifying something as a sine wave or not - could you add more details about what you are looking for? Also, is it possible to increase the sample rate, because detecting 50Hz in a 100Hz sample rate is right on the limit Oct 8 '19 at 20:26
• Following up on what @NeilSlater says, you should clarify what you mean by detect. Do you mean "detect the presence or absence" of such a wave? Do you mean "detect the location (phase) of the wave"? Both of these tasks would, as Neil mentions, be much easier to perform exactly with a FFT, rather than trying to build a function approximator with a neural network. Oct 8 '19 at 22:58
• @NeilSlater, I think the FFT could solve my problem. Basically, I am recording the vibrations of an AC Motor (50Hz Europe) and I am trying to find out weather it is powered on or not. When I record these vibrations, I basically get the vibration values (-1 to +1) over time (X and Y). Yes it is possible to increase the sample rate to 200Hz or 400Hz at max Oct 9 '19 at 5:54
• @JohnDoucette, I want to find out if some kind sine wave frequency between e.g. 40Hz and 60Hz is present. With that information I then can signal if the AC Motor is on or not. Thank you both! Oct 9 '19 at 5:54

Is this a task suited for a neural network

Yes. You have choices in fact:

• A fully-connected network would be simplest architecture, and would work if you gave it some time window of samples (e.g. every 0.5 seconds or every 50 samples) and supervised training data - sets of samples with sensor readings and the ground truth value of whether the motor was on or not.

• A 1D convolutional neural network would likely be most efficient and robust to train, and would take the same inputs and outputs as the fully-connected network.

• A recurrent neural network would be tricker to train, but a nicer design as you could feed it samples one at a time. The input would be the current sample, and output the probability that the motor was on. When training this, you would also want to provide it transitions between the motor being on and off. The nice feature about this is that it should give you quick feedback about whether the motor was on or off - with the caveat that it may be more likely to trigger intermittent false positives, so a little extra post-processing might be required.

All of the above require you to collect training data, ideally in situations identical to planned use of the detector. So if the motor is mounted somewhere that could experience other vibrations, a few of those kind of scenarios should be simulated with motor both on and off.

and if so, would it be less efficient than other means of detection?

In terms of computing power and effort on your part, you may find that an off-the-shelf Fast Fourier Transform (FFT) library function with a simple threshold at your target frequency will make a robust and simple detector, with no need for a neural network.

Typically for specific frequency detection you would take a window of samples, adjust them (using e.g. Hamming window) to reduce edge effects which would appear as frequencies in the conversion, and then run FFT. This combination is so common that you may find it already combined in the FFT library. For more on this, you would want to ask in Signal Processing Stack Exchange, where use of FFT is well understood.

If the environment is noisy or the target frequency can drift (making it hard to set a simple threshold) then you could also combine FFT with a neural network. This combination can solve much more complicated signal detection, and is used in speech processing for instance.

sampled at 100Hz - it is possible to increase the sample rate to 200Hz or 400Hz at max

For reliably detecting a 50Hz signal, I would say that 200Hz sample rate is minimum. The theorectical minimum is 100Hz (i.e. twice the signal frequency) but may give you problems with noise and the possibility that your sample points just happen to fall on low amplitude parts of the oscillations, making it look like the motor is off even when it is on.

• What about a 150Hz signal giving the same samples as 50Hz?
– user9947
Oct 9 '19 at 7:09
• @DuttaA: Good point, I missed that, although that is also covered by increasing the sample rate. A 150Hz signal would leave a different trace even sampled at 100Hz, but with a strong 50Hz component (because any high frequency noise is likely to drive a 50Hz detected signal at a 100Hz sample rate). Given the OP's use case though, it does not look like a major problem. However, these kinds of detail are why the OP should consider asking further questions in DSP stack exchange. Oct 9 '19 at 7:15

You can implement an autoencoder network. Autoencoder is an unsupervised artificial neural network that learns how to efficiently compress and encode data then learns how to reconstruct the data back from the reduced encoded representation to a representation that is as close to the original input as possible. When you train autoencoder with 50Hz sine wave data, your model can reconstruct correctly if gets 50Hz sine wave data as an input. When input's "Reconstruction Loss" is less than your threshold value that can be say the given input is 50Hz sine wave.