Answers.Body: <blockquote>
    <p><em>Is this a task suited for a neural network</em> </p>
  </blockquote>
  
  <p>Yes. You have choices in fact:</p>
  
  <ul>
  <li><p>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.</p></li>
  <li><p>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.</p></li>
  <li><p>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.</p></li>
  </ul>
  
  <p>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.</p>
  
  <blockquote>
    <p><em>and if so, would it be less efficient than other means of detection?</em></p>
  </blockquote>
  
  <p>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.</p>
  
  <p>Typically for specific frequency detection you would take a window of samples, adjust them (using e.g. <a href="https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.signal.hamming.html" rel="nofollow noreferrer">Hamming window</a>) 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 <a href="https://dsp.stackexchange.com/">Signal Processing Stack Exchange</a>, where use of FFT is well understood.</p>
  
  <p>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.</p>
  
  <blockquote>
    <p>sampled at 100Hz - it is possible to increase the sample rate to 200Hz or 400Hz at max</p>
  </blockquote>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-09T07:15:58.433Z
Answers.Text: @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.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-09T06:57:17.813Z
Answers.LastActivityDate: 2019-10-09T08:14:28.820Z
Answers.LastEditDate: 2019-10-09T08:14:28.820Z
Answers.UserDisplayName: Neil Slater
Answers.Body: <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-09T06:34:07.717Z
Answers.LastActivityDate: 2019-10-09T06:34:07.717Z
Answers.UserDisplayName: Klushka
Body: <p>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 (<span class="math-container">$-1$</span> to <span class="math-container">$+1$</span>) over time.</p>
  
  <p>I would like to develop a program to <strong>detect the presence</strong> of a 50Hz sine wave on a steady stream of input data. I will have <span class="math-container">$X$</span> and <span class="math-container">$Y$</span> measurements, where <span class="math-container">$X$</span> represents amplitude and <span class="math-container">$Y$</span> the time (sampled at 100Hz - it is possible to increase the sample rate to 200Hz or 400Hz at max)</p>
  
  <p><em>Is this a task suited for a neural network, and if so, would it be less efficient than other means of detection?</em></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-08T20:26:01.790Z
Comments.Text: 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
Comments.UserDisplayName: Neil Slater
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-08T22:58:55.793Z
Comments.Text: 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.
Comments.UserDisplayName: John Doucette
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-09T05:54:36.453Z
Comments.Text: @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
Comments.UserDisplayName: GatCode
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-09T05:54:52.750Z
Comments.Text: @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!
Comments.UserDisplayName: GatCode
Tags: <neural-networks><pattern-recognition><signal-processing>
Title: Can a neural network be used to detect sine waves?
UserDisplayName: GatCode
ThreadText: # Can a neural network be used to detect sine waves?
  
  (Asked by: username_0 on 2019-10-08)
  
  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?*
  
  **Tags:** neural-networks, pattern-recognition, signal-processing
  
  > **Comments:**
  > **username_1**: 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  
  > **username_2**: Following up on what @username_1 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 username_1 mentions, be much easier to perform exactly with a FFT, rather than trying to build a function approximator with a neural network.  
  > **username_0**: @username_1, 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  
  > **username_0**: @username_2, 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!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-10-09. Score: 1 | Accepted answer
  
  > *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](https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.signal.hamming.html)) 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](https://dsp.stackexchange.com/), 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.
  
  > **Comments:**
  > **username_1**: @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.  
  
  ---
  
  ### Answer by username_3 on 2019-10-09. Score: 0
  
  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.
  
  
  ---
  
  