MATLAB Answers


extract valuable data from signal

Asked by FeiMing
on 15 Dec 2012
Latest activity Commented on by Mansour Aljohani on 25 Jul 2015

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.

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.

  1 Comment


Did you find the answer. please tell me how? Thank you.


No products are associated with this question.

2 Answers

Answer by Image Analyst
on 16 Dec 2012
Edited by Image Analyst
on 16 Dec 2012
 Accepted answer

Try something like this, where I take the absolute value, then filter it to get rid of the oscillating parts, then take the difference, and finally extract the 5 bursts:

clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.
workspace;  % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Generate sample data.
signal = 0.003 * rand(1, 550) - 0.0015
signal(50:100) = 0.03 * rand(1, 51) - 0.015
signal(150:200) = 0.03 * rand(1, 51) - 0.015
signal(250:300) = 0.03 * rand(1, 51) - 0.015
signal(350:400) = 0.03 * rand(1, 51) - 0.015
signal(450:500) = 0.03 * rand(1, 51) - 0.015
subplot(3, 1, 1);
title('Original Signal', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Take absolute value and median filter to get rid of oscillations.
filteredSignal = medfilt1(abs(signal), 13);
subplot(3, 1, 2);
title('Filtered Signal', 'FontSize', fontSize);
% Find the quiet parts between the bursts.
quietParts = filteredSignal < 0.002;
subplot(3, 1, 3);
plot(quietParts, 'LineWidth', 3);
ylim([0 1.2]);
title('Quiet Parts', 'FontSize', fontSize);
% Find the starting and ending elements of the bursts.
startingBlockIndexes = find(diff(quietParts) < 0)
endingBlockIndexes = find(diff(quietParts) > 0)
% Extract the 5 blocks (known to be exactly 5)
v1 = signal(startingBlockIndexes(1):endingBlockIndexes(1));
v2 = signal(startingBlockIndexes(2):endingBlockIndexes(2));
v3 = signal(startingBlockIndexes(3):endingBlockIndexes(3));
v4 = signal(startingBlockIndexes(4):endingBlockIndexes(4));
v5 = signal(startingBlockIndexes(5):endingBlockIndexes(5));
% Plot the 5 signals.
subplot(5, 1, 1);
grid on;
title('V1', 'FontSize', fontSize);
subplot(5, 1, 2);
grid on;
title('V2', 'FontSize', fontSize);
subplot(5, 1, 3);
grid on;
title('V3', 'FontSize', fontSize);
subplot(5, 1, 4);
grid on;
title('V4', 'FontSize', fontSize);
subplot(5, 1, 5);
grid on;
title('V5', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);


on 17 Dec 2012

That is right but only for the signal you generated. It does not work for other signals (I tried to apply your codes on real signals).


1- Applying median filter in some cases does not give the required result.

2-Using a filter sometimes removes important information from the original signal, that leads to wrong analysis (the same thing regarding choosing the order of the filter, in your example n=15, changing n gives a wrong result).

3- The same thing regarding choosing threshold level (which determines the length of the block). Changing it does not give the nice train of pulses in Quiet Parts(as you named it).

It will be far better to find a way to split the signal without filtering it, the main idea behind splitting is, to study every block alone without affecting the other block.

To remove the noises in the signal I tried to use this:


% ( a ) is the signal We want to split it. But it does not work well.

At the end, I constructed high pass filter (hpF) by using filtfilt. The same problem, choosing cut frequency and sampling frequency (for sampling frequency, it is solved by Nyquist).

I followed the same steps you sent(only by changing the median filter and using hpF) it gave almost a good result.

4-One point I used padding zero at the beginning of the signal, to avoid any malfunction in calculating “startingBlockIndexes” and “endingBlockIndexes”. Because at the beginning of the measurements some unwanted noises added to the signal from different sources(of course, putting zeros done after plotting the signal).

At the end, as mentioned above using filter is not the right way to split the signal, but maybe is the only way.

Thanks for the idea.

OK, well as you know, you did not provide your data so I had to make up some. Of course it may need to be tweaked to work with your data. Glad I could point you in the right direction. Mark it as Answered if you're all done with this discussion.

Answer by bym
on 15 Dec 2012

Then use

v = V(abs(V)>thr);

  1 Comment

on 16 Dec 2012

That is right, it is (abs), but in this case the output is a one vector that contains all blocks together. But the question is, how to get every block in a mini vector. So the result should be, in our example, five mini vectors not only one.

The reason, I want to study every block alone.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!