Clear Filters
Clear Filters

extract and store valuable data in vectors

1 view (last 30 days)
I have a signal (vector) consists of many blocks (for example five blocks).I want to extract, separate, these blocks (that contain a valuable information ) from the main signal and store every block in a vector. This is real data and the 5 valuable information in the example are not always in same location.
For example like:
So if I have an input vector (V), The result , in our case, should be five mini vectors (v1, v2, v3, v4, v5).
I tried to apply this method: If a specific consecutive elements from (V) vector have a value above a threshold (for example 0.02 > Thr) start put the elements in a a mini vector, but it does not work because values in the input vector (V) are getting positive and negative.

Accepted Answer

Image Analyst
Image Analyst on 26 Jul 2015
Simple thresholding won't work because in each burst there are dips that you probably want to keep. Luckily for you I solved this same problem for another person in this discussion: http://www.mathworks.com/matlabcentral/answers/229678#answer_185935 :
% Setup - read in the signal and plot it.
s=load('signal.mat')
signal = s.coarse_d;
subplot(3,1,1);
plot(signal, '-', 'Color', [0,.5,0]);
grid on;
% MAIN CODE IS THE FOLLOWING TWO LINES OF CODE.
% Threshold the signal
lowSignal = abs(signal) < 0.1;
% Remove stretches less than 10,000 elements long.
% And invert it to get the high signal areas instead of the quiet areas.
lowSignal = ~bwareaopen(lowSignal, 10000);
% Now we're done. Plot the results.
subplot(3,1,2);
plot(lowSignal, 'b-', 'LineWidth', 2);
grid on;
% Plot both on the same graph now.
subplot(3,1,3);
plot(signal, '-', 'Color', [0,.5,0]);
hold on;
plot(lowSignal, 'b-', 'LineWidth', 2);
grid on;
As you can see it identifies each "block" but leaves the inside of the block intact.
  5 Comments
Image Analyst
Image Analyst on 27 Jul 2015
I don't think I have that data anymore. I can use yours if you upload it. Like Jan says, because each chunk may be different lengths, it will have to be a cell array, not a regular numerical matrix.
Mansour Aljohani
Mansour Aljohani on 27 Jul 2015
Dear Sir, I attached my data. And thank you so much for your help.

Sign in to comment.

More Answers (1)

Jan
Jan on 26 Jul 2015
Edited: Jan on 27 Jul 2015
What about using the absolute value of V?
T = (abs(V) > Thresh);
blockStart = strfind(T, [false, true]);
blockEnd = strfind(T, [true, false]);
But even then the signal can have a value below the threshold during a block.
[EDITED]
You can use Fex: RunLength to remove short gaps:
T = (abs(V) > Thresh);
% To fill gaps with less than e.g. 3 frames:
[B, N, Idx] = RunLength(T);
gap = find((B == false) & (N < 3)); % Two frames
T(gap) = true;
T(gap+1) = true;
blockStart = strfind(T, [false, true]) + 1;
blockEnd = strfind(T, [true, false]);
% Split signal into blocks:
Block = cell(1, length(blockStart));
for k = 1:length(BlockStart)
Block{k} = V(blockStart(k):blockEnd(k));
end

Community Treasure Hunt

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

Start Hunting!