Neural Network Based Sine Wave Prediction
Piyush Kumar
April 27, 2025
Contents
1 Introduction
2
2 Problem Statement
2.1 Question 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Question 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2
2
3 Dataset Preparation
2
4 Methodology
4.1 Neural Network Architecture . . . . . . . . . . . . . . . . . . .
4.2 Training Details . . . . . . . . . . . . . . . . . . . . . . . . . .
3
3
3
5 Implementation Details
5.1 Activation Functions . . . . . . . . . . . . . . . . . . . . . . .
5.2 Loss Function . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3 Training Algorithm Steps . . . . . . . . . . . . . . . . . . . . .
3
3
3
4
6 Results
6.1 Question 1: 50Hz Sine Wave . . . . . . . . . . . . . . . . . . .
6.2 Waveform Comparison . . . . . . . . . . . . . . . . . . . . . .
6.3 Question 2: 130Hz Sine Wave . . . . . . . . . . . . . . . . . .
4
4
5
6
7 Observations and Conclusion
6
1
1
Introduction
Artificial Neural Networks (ANNs) have proven effective for learning complex
patterns in data, including time-dependent signals like sine waves. In this
report, we design and train neural networks to predict single-phase sine waves
based on scalar time input. We analyze the effect of the network architecture,
particularly the hidden layer size, on the prediction accuracy.
2
Problem Statement
This report addresses two main questions:
2.1
Question 1
Design and train a feedforward neural network to predict a 50Hz single-phase
sine wave given time input t. The target output is:
V (t) = sin(2π · 50 · t)
2.2
Question 2
Design and train a feedforward neural network to predict a 130Hz singlephase sine wave given time input t. The target output is:
V (t) = sin(2π · 130 · t)
Additionally, vary the number of neurons in the hidden layer from 1 to 200,
and study the impact on prediction error.
3
Dataset Preparation
For both problems, the training and testing datasets were generated synthetically:
• Input: Time values t sampled uniformly within one time period.
• Output: Corresponding sine values V (t).
• Training set: 200 points.
2
• Testing set: 1000 points.
• Time values normalized between 0 and 1.
4
Methodology
4.1
Neural Network Architecture
• Input Layer: 1 neuron (time t)
• Hidden Layer: Variable number of neurons (1 to 200)
• Activation Function: ReLU for hidden layer
• Output Layer: 1 neuron with linear activation
4.2
Training Details
• Loss Function: Mean Squared Error (MSE)
• Optimizer: Gradient Descent
• Learning Rate: 0.01
• Number of Epochs: 500
5
Implementation Details
5.1
Activation Functions
• ReLU Activation:
ReLU(x) = max(0, x)
• Linear Activation:
Linear(x) = x
5.2
Loss Function
n
MSE =
1X
(ytrue − ypred )2
n i=1
3
5.3
Training Algorithm Steps
1. Initialize weights randomly with small values.
2. Forward propagate input to get output prediction.
3. Compute the MSE loss.
4. Backpropagate errors to update weights and biases.
5. Repeat for specified number of epochs.
6
Results
6.1
Question 1: 50Hz Sine Wave
A simple network was trained to learn the 50Hz sine wave. The network
accurately learned the sine wave after training, achieving low mean squared
error.
The following plot shows how the Mean Squared Error (MSE) decreases
as the number of points per cycle increases:
Figure 1: MSE vs Number of Points per Cycle
4
6.2
Waveform Comparison
The predicted and true waveforms for the best and worst cases are shown
below:
Figure 2: Best Case Prediction (Lowest MSE)
Figure 3: Worst Case Prediction (Highest MSE)
5
6.3
Question 2: 130Hz Sine Wave
Multiple models were trained by varying the hidden layer neurons from 1 to
200.
Figure 4: MSE vs Number of Neurons in Hidden Layer for 130Hz Sine Wave
As observed in the plot:
• For very few neurons (1-10), the error was high due to underfitting.
• As the number of neurons increased, the error reduced significantly.
• Beyond a certain number of neurons (∼100), further increasing neurons
had diminishing returns.
7
Observations and Conclusion
• Small networks (low number of neurons) fail to capture the rapid oscillations of high-frequency sine waves.
• Increasing neurons improves model capacity and reduces prediction error.
6
• Over-parameterizing (too many neurons) can still yield good results in
this simple problem without leading to overfitting due to limited model
complexity.
• Proper normalization and weight initialization play a crucial role in
convergence.
Overall, neural networks can effectively approximate even high-frequency
sine waves, provided sufficient hidden layer capacity and proper training.
7