- Summing Overlapping Segments: For each segment, add its values to the corresponding indices in the reconstructed signal.
- Weighting: Keep track of how many segments contribute to each index in the reconstructed signal.
- Averaging: Divide the summed values by the number of contributing segments to get the final reconstructed signal.

# How to extract the individual segments from overlapped segments in a 1-D signal?

18 views (last 30 days)

Show older comments

I have a deep learning architecture, where I want to create input using a 1-D ECG signal by spliting the signal into segments, where the each segments consists of 2000 samples, and each segment is 90% overlapped between consecutive segments. I think this can be done using buffer() or bsxfun(@plus,...) in matlab. However, I have some concerns,

- If I use the overlapped segments as input to the deep learning network, I persume the output follows the same format. For instance in https://in.mathworks.com/help/signal/ug/signal-source-separation-using-w-net-architecture.html#mw_rtc_SignalSourceSeparationWithWnetExample_M_317EA6F7 the input segment size is 1024 and produced output is of same size. So, if the output follows the same format how can we separate the overlapped segments?
- Is it a right way to use bsxfun(@minus,...) function for extracting the non-overlapped segments from the overlapped output segments?

Apologies earlier, for not uploading the signal and the network. Kindly request to demonstrate using random signal of some size 1-by-N (with certain window size of M).

Kindly, Thanking you in advance for the help.

##### 0 Comments

### Answers (1)

Garmit Pant
on 9 Jul 2024 at 5:40

Hello Bipin

To create the segments from your 1-D ECG signal, you don’t need to use the MATLAB function “bsxfun”. The function is used when binary functions need to applied to two arrays in an element-wise fashion. In your use-case, only the correct indices need to be calculated. Please follow the code snippet below to create the segments with the required size and overlap:

% Generate a random signal of size 1-by-N

N = 10000; % Length of the signal

signal = randn(1, N);

% Define segment size and overlap

segmentSize = 2000;

overlap = 0.90;

stepSize = round(segmentSize * (1 - overlap));

% Create overlapped segments

numSegments = ceil((N - segmentSize) / stepSize) + 1;

segments = zeros(segmentSize, numSegments);

for i = 1:numSegments

startIdx = (i-1) * stepSize + 1;

endIdx = startIdx + segmentSize - 1;

if endIdx > N

endIdx = N;

startIdx = endIdx - segmentSize + 1;

end

segments(:, i) = signal(startIdx:endIdx);

end

The shape of your output will be dependent on various factors like network architecture, task, output layer. For example, in tasks like signal source separation (as in the provided MathWorks example), it is common to design the network such that the input and output segment sizes are the same. In a classification task, the output shape would differ and be a single output. You need to ascertain the nature of the output based on the deep learning network used.

Assuming that the output is received as overlapped segments with the same format as the input segments, the non-overlapped signal can be reconstructed using the following code snippet:

% Placeholder for deep learning model output (assuming same size as input)

outputSegments = segments; % This should be the output from your deep learning model

% Reconstruct the signal from the overlapped output segments

reconstructedSignal = zeros(1, N);

weighting = zeros(1, N);

for i = 1:numSegments

startIdx = (i-1) * stepSize + 1;

endIdx = startIdx + segmentSize - 1;

if endIdx > N

endIdx = N;

startIdx = endIdx - segmentSize + 1;

end

reconstructedSignal(startIdx:endIdx) = reconstructedSignal(startIdx:endIdx) + outputSegments(:, i)';

weighting(startIdx:endIdx) = weighting(startIdx:endIdx) + 1;

end

reconstructedSignal = reconstructedSignal ./ weighting;

% Plot original and reconstructed signals for comparison

figure;

subplot(2, 1, 1);

plot(signal);

title('Original Signal');

subplot(2, 1, 2);

plot(reconstructedSignal);

title('Reconstructed Signal');

In the above code snippet, the following operations have been performed to reconstruct the non-overlapped signal:

The above steps should be helpful in constructing overlapped segments and reconstructing non-overlapped signals from the output.

I hope you find the above explanation and suggestions useful!

##### 0 Comments

### See Also

### Products

### Community Treasure Hunt

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

Start Hunting!