There are many ways to do this, depending on your needs.
If you want to count each peak, you must go through all the frequencies in the spectrum, remembering whether the intensity increased or decreased. Each time you notice a change in direction from increasing to decreasing, you increase the peak counter. Please note, however, that this will include very weak peaks, which may or may not be what you need. You can set a minimum limit on how much the increase and decrease should be for the registered peak.
Alternatively, you can find the baseline for signal strength (using the average in the simplest case), and then count the number of positive spikes (with some configurable minimum deviation from the baseline). You will probably get better results if you change this approach to using a frequency-dependent baseline and minimum to allow for a gradual decrease in intensity at higher frequencies (again, it depends on your particular signal and the need for it to be useful ) One simple way to do this is to divide your spectrum into bands (small enough to be able to accept a more or less flat energy distribution throughout the group) and use different base and minimum values ββfor each band.
Adam zalcman
source share