3.1 Practical Results
By implementing the designed algorithm on the FPGA chip, an internal signal was first generated in the FPGA memory. Finally, by the signal generator, two signals with the same frequency were given to the ADC. The practical results for internal and external signals at different frequencies are as follows. A calculator block was simulated in ISIM software so as to calculate all needed peaks and their equivalent points. This signal counts from − 6 to 255 and this process is repeated again and again. As shown in Fig. 9, the maximum number is 255, the minimum is 6 and the equivalent points in the second signal are 8 and 9 respectively, so the simulation results work properly.
3.2 Internal Signal Results Around a 90degree Phase Difference
The results of the internal signal with a phase difference of 89 degrees are shown in Fig. 10 that indicates the first signal (blue), the second one (yellow), the maximum value (red), and the equivalent (pink). In this phase difference, since the difference is less than 90 degrees, the equivalent line is higher than the horizontal axis. So, the closer the phase difference is to 90 degrees, the closer the equivalent values are to the horizontal axis.
Figure 11 shows the internal signals with a phase difference of 77 degrees. The results were checked for all angles and after ensuring the accuracy of the program, the implementation phase was started.
3.3 External Signal Results
According to Fig. 12 and Fig. 13, a phase difference circuit and the laboratory experimental setup were designed, then the experiment was done repeatedly at different angles from the frequency of 1 MHz to 22 MHz in different amplitudes. By correcting and improving the program, in the end, the error was minimized. As may be seen in Fig. 12, two input signals have different amplitudes which means the amplitude difference is not important in this algorithm.
Figure 14 shows the ADC input signal for the frequency of 10 MHz, in which the maximum of the first signal and its equivalent points, in the second signal, are calculated with high accuracy.
A 20 MHz signal is shown in ChipScope software. Moreover, the maximum and equivalent amplitude values are shown in Fig. 15. This signal accurately indicates the phase difference at 158 degrees. It should be noted that the error in this phase difference is much greater than that around 90 degrees.
3.4 The Number of Counts
To calculate the maximum and minimum of two input signals, a number of counts are defined in the program that can be changed by the user in Vio. This count must be optimized to the best value so that the best accuracy can be obtained. In this program, the number of counts is crucial to get the maximum and minimum values correctly. To illustrate, initially, the number of counts was set to roughly 5 million. But the result was very unstable and sensitive to noise, due to the impact of high frequency on the signals. It was difficult to measure the minimum and maximum values. Therefore, the count was reduced from 5 million to 10, step by step, in order to obtain the optimal count value at each frequency. The optimum value for the frequency of about 20 MHz was between 150 and 255 counts. As shown in Fig. 16, the phase difference of 98 degrees is obtained in practice, which has an error of about 3 degrees which can be reduced using a machine learning algorithm.
The results of phasedetection at a frequency of 10 MHz are shown in Fig. 17 which shows that at the phase difference of around 90 degrees, the error is less than that of around 150 degrees. As expected, the most error is around zero and 180 degrees. In some phases, such as 150 and 77 degrees, the highfrequency noise disturbs, but as mentioned before, this noise is considered invalid data. However, the most significant phase difference is around 90 degrees which is of better accuracy. It is worth mentioning that in order to obtain information about each phase difference, the export option was used in ISE software and all the information was entered in Excel software and the graph of each frequency was obtained separately.
The results of phase differences of different degrees in the frequency of 15 MHz are shown in Fig. 18, which shows the interference of highfrequency noise in the phase difference of 170 degrees, but it was ignored by reducing the count in the program. Accuracy is also lowat zero degrees and close to 180 degrees, while acceptable accuracy is observed close to the desired angle at 90 degrees.
The results of phase differences of different degrees at a frequency of 20 MHz are shown in Fig. 19. It can be seen that around the difference of the desired phase, the accuracy is much higher than that in other degrees.
3.5 Forecasting phase differences by applying machine learning
The data achieved in this work was used as input values in the linear regression algorithm to minimize errors and reach a trustworthy prediction based on the training set. As it may be seen, the error of algorithm is about 1(around 90 degrees) up to 5(in further degrees) degrees, this can make accelerator operation faulty. So, the error is to be eliminated as much as possible. Machine learning models make it possible to find a suitable pattern in order to predict the high accurate output. This pattern recognition is based on different models, here, linear kernel machine learning is used. To improve the results more than 60% of the data was used as a training set and the rest was used to test the accuracy. Then, actual values were compared with the predicted values (mean absolute error).
MAE = True values – Predicted values = 0.88
Another factor is the residual sum of squares (RSS) which measures the level of variance in the error term, or residuals, of a regression model. In this experiment obtained RSS was 1.03. In addition to that, the Mean Squared Error (MSE) was estimated, that is the average squared difference between the estimated values and true value shown in Eq. 3:
$$\text{M}\text{S}\text{E}=1/N{\sum }_{i=1}^{N}{\left(yiỷi\right)}^{2}=1.63$$
3
Where N is the number of samples we are testing.
As accepted, the performance of detecting phase differences was improved gradually, in all runs, R2score was always more than 0.99 which means the accuracy of prediction is acceptable. Figure 20 shows the accuracy of prediction plot between actual values and desired values.
The advantages of this method for the phase detection

No dependency on the sampling speed of ADC

No dependency on the input frequency

No dependency on the signal amplitude

The capability to remove the lowfrequency noise

The capability to remove highfrequency noise