How to cut a signal en two parts?

2 次查看(过去 30 天)
Hi friends, I'm new usign matlab,I would like to know, how to cut a signal en two parts? I mean, divide the low and the high part . I add a simple code and an image as a example.
ylim([0 6])
x=[0 0 5 5 5 0 0];
plot(x,'r')
[maximo,MaxFreq]=findpeaks(x,'NPeaks',1) %%here we found the max peak, in this case is 5
media= maximo-(maximo/2) %%here we calculate the half signal and the result is 2.5
plot(x)
hold on
plot(0:length(x),media,'*')
Thank you very much and sorry for my english.

回答(1 个)

Baltam
Baltam 2016-4-20
编辑:Baltam 2016-4-20
You better make some x-axis parameter, I called it 't'. From there on it is basically the same as wat Star strider told you.
x=[0 0 5 5 5 0 0];
t = 1:length(x); % Make x-axis value to plot
[maximo,MaxFreq]=findpeaks(x,'NPeaks',1); %%here we found the max peak, in this case is 5
media= maximo-(maximo/2); %%here we calculate the half signal and the result is 2.5
plot(t,x,[t(1),t(end)],[media,media])
% Make more points on the curve by using interpolation
T = linspace(0,length(x),1000);
X = interp1(1:length(x),x,T);
% Filter data dependent on media. Devide in top and bottom.
T_top = T(X>media);
T_bottom = T(X<media);
X_top = X(X>media);
X_bottom = X(X<media);
% Plot again
figure(2),
plot(T_top,X_top,T_bottom,X_bottom)
Kind regards
Baltam

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by