![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177802/image.jpeg)
extract and store valuable data in vectors
2 ビュー (過去 30 日間)
古いコメントを表示
Mansour Aljohani
2015 年 7 月 25 日
コメント済み: Mansour Aljohani
2015 年 7 月 27 日
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:
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
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.
0 件のコメント
採用された回答
Image Analyst
2015 年 7 月 26 日
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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177802/image.jpeg)
As you can see it identifies each "block" but leaves the inside of the block intact.
5 件のコメント
Image Analyst
2015 年 7 月 27 日
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.
その他の回答 (1 件)
Jan
2015 年 7 月 26 日
編集済み: Jan
2015 年 7 月 27 日
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]
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!