That should be plot(t,y) the second time.
why 0.1 ?
Finding the average difference between peaks in the correlation matrix does not tell you whether the signal is periodic.
Consider for example a square wave signal that pulses on for one unit, and each time the distance between pulses gets one unit further apart:
|^|_|^|__|^|___|^|____|^|_____|^|
The correlation measurement will have peaks that are not a constant distance apart, but despite not being constant distance, the mean of the distance is going to be some number. Like mean([1,3,6,10,15,21]) -> 9+1/3 . mean() of a series of values is always defined unless the values are empty or nan -- but the fact it exists does not tell you that the signal is periodic.
Best Answer