Adding the signal in a specific interval

2 次查看(过去 30 天)
Hi,
I want to add all the signal values between these peaks. For example my first peak is at X = 204 and my second peak is at X =324. I want to add all vales between the interval [ X= 204 to X =324]. Similarly I want to add these values between all the intervals.
[ X = 324 to X = 446]
[ X= 446 to X = 577]
[ X= 577 to X = 698]
[ X= 698 to X = 820]
[ X= 820 to X = 946]
How I can achieve this. Thanks

采纳的回答

Sudheer Bhimireddy
Use the 'findpeaks' function to get the locations, from there you can find the sum between the indices
[peak_magnitudes,peaks_locs] = findpeaks(your_signal);
If you want the locations in terms of the x-axis variable, use the following:
[peak_magnitudes,peaks_locs_x] = findpeaks(your_signal,your_x_variable);
For finding the sum between the peaks:
% initialize your summation array
signal_peak_sum(numel(peaks_locs)) = 0;
% For the first peak
signal_peak_sum(1) = sum(your_signal(1:peaks_locs(1)));
% For the remaining peaks
for i=2:numel(peaks_locs)
signal_peak_sum(i) = sum(your_signal(peaks_locs(i-1):peaks_locs(i)));
end
Hope this helps.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by