0

I have an array which stored samples of a signal during a period of time which called signalArray(1:n) and n is number of samples.

I'm going to split signal samples to several time-segments e.g. M segments (0:n/M), (n/M+1:2n/M+1),.... and I want to find maximum value of signal in each of theses M segments.

Are there any efficient methods for this?

6
  • Can we assume M divides n? Commented Jul 30, 2017 at 15:36
  • @LuisMendo It may happen that M does not divides n. Commented Jul 30, 2017 at 15:51
  • Then your poblem is not well defined. Do you simply want a final, shorter segment of which you also compute the maximum? Commented Jul 30, 2017 at 15:52
  • @LuisMendo It would be preferred to be like this. Commented Jul 30, 2017 at 15:54
  • Sure, it can be done. Do you need to specify M as the number of segments (including the last, possibly shorter segment), or as the segment length (except for the possibly shorter last segment)? Commented Jul 30, 2017 at 15:56

1 Answer 1

2

If M were assured to divide n you would only need to reshape the data into an M-row matrix, to trasnform each segment into a column, and then take the maximum of each column.

In general, if M doesn't necessarily divide n, the same procedure can be applied but the the last segment (i.e. column) may need to be padded with NaN entries. This works because max ignores NaN values.

n = 21;                   % Data size
M = 4;                    % Number of segments. If M doesn't divide n, the last 
                          % segment will be shorter (and will be padded by NaN)
signalArray = rand(1,n);  % Example data
t = NaN(ceil(n/M), M);    % Define matrix of NaN's with required size
t(1:n) = signalArray;     % Fill data (in column-major order). Some entries
                          % in the last column may be left as NaN
result = max(t, [] ,1);   % Maximum of each column
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.