https://github.com/sudo-arash/sincos2angle
Convert sin and cos to an angle using neural networks in MATLAB.
https://github.com/sudo-arash/sincos2angle
Last synced: 4 months ago
JSON representation
Convert sin and cos to an angle using neural networks in MATLAB.
- Host: GitHub
- URL: https://github.com/sudo-arash/sincos2angle
- Owner: sudo-arash
- License: apache-2.0
- Created: 2025-06-27T14:16:21.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-06-27T14:37:31.000Z (12 months ago)
- Last Synced: 2025-06-27T15:33:24.677Z (12 months ago)
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [sin, cos] => angle
Convert sin and cos to an angle using neural networks in MATLAB.
## How to use
First, load the network using this command:
```matlab
load("network.mat");
```
Then, you need to give it sin and cos of the angle you want! But, you have to first convert angle to radians:
```matlab
angle = 30;
inputs = [sin(deg2rad(angle)), cos(dregrad(angle))];
```
And now, we use the `net` function:
```matlab
net(inputs)
```
## Training
We had a dataset of about 10,000 inputs and outputs which were like this:
```matlab
outputs = linspace(0, 359, 10000); % We didn't train the network to do 360 degree or negative degrees.
inputs = [sin(deg2rad(a)), cos(dregrad(a))];
% and then we setup the network and used the train function to train it.
train(net, inputs, outputs);
```
## Layers
We first thought one hidden layer does the job, but it still failed the validation tests. So, we changed it to 2. The first layer has about 15 neurons while the second has 10. This gave better results.
## Limitations
You can give it negative angles or angles bigger than 359. This is because of the fact that we couldn't train the network to learn 0 or 360 degrees, that would change it's behaviour completely.