Find jumps in Signal take constant area and split signal to different mat files

Hey guys,
I have following Signal:
I need to split this signal into different mat files.
My problem i have the noise and the transient behaviour.
I need to save the constant "areas" into the different mat files.
In this case I have 7 to 8.
Thanks in advance.

7 件のコメント

darova
darova 2019 年 3 月 5 日
Kind of long code
clc, clear
noise = 0.1;
n = 10; % number of areas
jump = 1;
cur_jump = 0;
t = linspace(0,30,500);
signal = round(t./10) + rand(1,length(t))*noise;
ds = diff(signal);
t = t(abs(ds)<noise);
s = signal(abs(ds)<noise);
ar = zeros(length(signal),n);
time = zeros(length(signal),n);
ns = 0;
while cur_jump < max(s)
nj = 0;
ns = ns + 1;
for i = 1:length(s)
if cur_jump-jump/2 < s(i) && s(i) < cur_jump+jump/2
nj = nj + 1;
ar(nj,ns) = s(i);
time(nj,ns) = t(i);
end
end
cur_jump = cur_jump + jump;
end
subplot(3,2,1)
plot(t,s)
hold on
for i = 1:ns
subplot(3,2,i+1)
plot(time(:,i), ar(:,i),'r')
end
hold off
youjarr
youjarr 2019 年 3 月 6 日
Hey and thanks for your help.
I tested your Code and i get this plot:2019-03-06_09-31-59.png
What are those lines? Is there a way to remove them and which part of the code do I need? I think this part here:
ds = diff(signal);
t = t(abs(ds)<noise);
s = signal(abs(ds)<noise);
ar = zeros(length(signal),n);
time = zeros(length(signal),n);
ns = 0;
while cur_jump < max(s)
nj = 0;
ns = ns + 1;
for i = 1:length(s)
if cur_jump-jump/2 < s(i) && s(i) < cur_jump+jump/2
nj = nj + 1;
ar(nj,ns) = s(i);
time(nj,ns) = t(i);
end
end
cur_jump = cur_jump + jump;
end
Everything above is creating the signal and after the plot.
youjarr
youjarr 2019 年 3 月 6 日
編集済み: youjarr 2019 年 3 月 6 日
This is what is happening when I put my data in... .
It seems it get the area to early and ends the area to late
darova
darova 2019 年 3 月 6 日
Untitled.png
Did you adaptate those variable for you model?
Those lines you asked are zeros element in ar and time. Number of current "area" less than number of elements in ar
youjarr
youjarr 2019 年 3 月 6 日
Yes it is mostly the same -> noise = 0.1 and jump = 1. I changed the 0 to NaNs now.
The green marked area is the area i want to be saved.
2019-03-06_13-20-50.png
darova
darova 2019 年 3 月 6 日
can you attach your data?
youjarr
youjarr 2019 年 3 月 6 日
Yes. This is the Y-Axis.
Just Build a vector
t = 1:1:length(signal)
should be the same effect.

サインインしてコメントする。

回答 (2 件)

youjarr
youjarr 2019 年 3 月 7 日

0 投票

Maby an easier question.
How do I get the first value when it reached the next jump? I mean if it gets constant (green lines) that would be the best.2019-03-05_11-42-04_1.png
darova
darova 2019 年 3 月 7 日

0 投票

I tried to smooth data. Then get every 600th point to compare with noise value and filter.
Then comparing points to find stable areas.
Hard to pick parameters for data (smoothing and filter). Maybe with user interaction it will be a little bit easier to draw those areas. See attached script

2 件のコメント

youjarr
youjarr 2019 年 3 月 11 日
Thank you very much for your effort.
I am going to test it later.
But can I adpat this code 1:1 to following data?
2019-03-08_16-29-22.png
Or do I have to change smth. in the code?
darova
darova 2019 年 3 月 11 日
Hard to say. It depends on data, try to change smooth coefficient and filter point if needed.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Data Import and Analysis についてさらに検索

製品

リリース

R2018b

質問済み:

2019 年 3 月 5 日

コメント済み:

2019 年 3 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by