I want to merge the right block (consisting of two smaller blocks) to look exactly like the two block to the left. I was thinking about morphological operations but these tend to alter the original shape, thus losing accuracy. Are there any other signal processing tools that would help? The data is presented as a time series.
Closing a gap in time series
167 views Asked by anopheles At
2
There are 2 answers
1
On
There are various ways to deal with gaps. This assumes that a single value may accidentally be zero (or low), and should be fixed to match its neighbors:
vo =ones(1,3);
vz = zeros(1,3);
ts = [vo vz vo vz vz vo 0 vo];
bar(ts)
c = min(circshift(ts,[0 1]),circshift(ts,[0 -1]));
ts_nogap = max(ts,c);
figure, bar(ts_nogap)
For more advanced requirements consider using filter
instead of circshift
or loop through all values and explore their 'neighborhood' in any way you like.
First we need a test data set:
Now we find first
and last index of each non-zero block (note that numbers really coincide with the ones I used to make test data)
Then we just delete the gap between 3rd and 4th block in X (I rearranged the output):
Also you may fill the gap in Y with ones instead of removing those elements: