Beat detection in Matlab or Python
The area you're asking about is called "Onset Detection" this is used all throughout signal processing, but most oven used in Music Information Retrieval to identify the start and stop to notes. 



While there are many ways to accomplish this lets consider two: energy and  frequency domain. 

Energy: We know that when there is a spike in a signal there is a marked increase in the energy of the signal. You could simply create sampling windows and calculate the average absolute energy of the window by tracking the area under the curve. When you see a large increase it means you've reached a peak (or close enough to an onset) 

Frequency: 
We know that in the time domain, if a signal is high in amplitude and short in time it will have a wide spread in the frequency domain with most of that content in the higher end of the frequency spectrum. (Dirac function is a prime example of this) 

You could cut your signal into small windows, calculate the FFT and detect when there is a large change in high frequency content. 

These two methods are theoretically the same, however your implementation would result in different accuracy. 

Here's a tutorial on many of the onset detection algorithms out there.