Pulsewidth command giving empty column vector
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello
I am trying to find the 66% width of different pulses of a Atrial Blood Pressure signal by using following command syntax:
pulsewidth(chunk,t,'MidPercentReferenceLevel',66)
where "chunk" is pulse and "t" is time.
when i use this command, it gives me values for some pulses width and for some pulse i get "0×1 empty double column vector". for example i am getting "0×1 empty double column vector" in the attached picture of pulse. can someone tell me which thing i am doing wrong? and can someone help me how to find 66% width without having empty column vector?
i would be thankful to you

채택된 답변
Star Strider
2021년 8월 21일
It would be nice to see the waveforms that give values and those that do not.
I suspect the reason is that the ones that do not, have initial or final values that are not the same, as the one in the plot image shows. One possible way to deal with that is to get the minimum of the pressure waves for the entire recording and use that as the zero reference. For the waves that do not return values, it would then be necessary to find the maximum for that particular wave and calculatlate the 66% width.
One approach to that might be something similar to:
x = linspace(-5000, 5000, 250);
y = [7.5; 1.9; 0.9] .* exp(-(0.001*[1; 0.85; 0.6] * x).^2);
[ymx,idx] = max(y,[],2);
hafmax = ymx*0.66;
for k = 1:numel(hafmax)
idxrng1 = find(y(k,1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(k,idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(k,idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(k,idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
end
format short g
xm
xm = 3×2
-644.86 644.86
-758.58 758.58
-1074.5 1074.5
format short
figure
plot(x, y)
hold on
for k = 1:numel(hafmax)
plot([xm(k,1) xm(k,2)], [1 1]*hafmax(k), '-k', 'LineWidth',1.5)
end
hold off
grid
xlim([-1 1]*2000)

This was designed to reply to a different problem, however it would work here as well, since it returns the independent variable values for the dependent variable equalling a specific value, so determining the width would simply mean subtracting those values (here, the columns of ‘xm’). It will be necessary to decide, likely for every waveform that does not return values, to use either the ascending or descending parts of the waveform to calculate the 66% value.
.
댓글 수: 8
Shehzaib Shafique
2021년 8월 22일
편집: Shehzaib Shafique
2021년 8월 22일
Respected sir,
thank you for you reply.
Actually sir i am not expert in MATLAB so i did not get the logic of your code.
Moreover, when i try to replave "y" and "x" with my variables "chunk" and "t" respectively, i do not get results properly.
is it possible if you help me in finding the 66% width of my data pulse? i am attaching the data of pulse here.
Your help would mean a lot.
I did my best to make this a general as I could, so it would work with multiple pulses, however I cannot test that as rigorously as I would like (note that it is designed to work with row vectors):
LD = load('pulse.mat');
chunk = LD.chunk;
t = linspace(0, numel(chunk)-1, numel(chunk));
x = t(:).'; % Force Row Vectors
y = chunk(:).'; % Force Row Vectors
[ymx,idx] = findpeaks(y, 'MinPeakProminence',10);
hafmax = ymx*0.66;
for k = 1:numel(hafmax)
idxrng1 = find(y(1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
end
format short g
xm = xm
wp = diff(xm,[],2)
format short
figure
plot(x, y)
hold on
for k = 1:numel(hafmax)
plot([xm(k,1) xm(k,2)], [1 1]*hafmax(k), '-k', 'LineWidth',1.5)
end
hold off
grid
text(x(idx), hafmax.*ones(1,numel(idx)), compose('\\uparrow\nWidth = %.3f',wp), 'Horiz','center', 'Vert','top')
producing:

It measures the height from 0, not with respect to the baseline (since I have no idea what that is), so it may be necessary to change the code to reflect that, likely by subtracting the minimum of the entire signal from tthe entire signal, then present that corrected signal to findpeaks and the rest of the code. The resulting ‘hafmax’ and width calculations should then be correct.
Experiment with it to get the result you want.
I could have done this with the onlilne Run feature, however getting it to read .mat files takes more effort than just copying and pasting the result from running it on my computer.
.
It worked. Thank you so much sir.
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Shehzaib Shafique
2021년 8월 22일
편집: Shehzaib Shafique
2021년 8월 22일
Respected sir,
Thank you for your help. your code worked on all pulse accept the last one, the last pulse gives following error.
Error using matlab.internal.math.interp1
Sample points must be unique and sorted in ascending order.
Error in interp1 (line 154)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
I tried to fix it but i could not. Can you resolve this error?
Thnaks in advance
load 'filtered_abp'
fs=250;
filtered_abp = [filtered_abp zeros(1,80)]; % zero padding
time=[1:length(filtered_abp)]./fs;
[pks,loc,width,prominace]=findpeaks(filtered_abp,'MinPeakHeight',22,'annotate','extents');
invert_abp=-filtered_abp;
[inv_pks,inv_locs]=findpeaks(invert_abp,'MinPeakHeight',-20,'MinPeakDistance',50);
wind=50; % window
vec=[];
for c=2:2:length(inv_pks)
chunk=filtered_abp(inv_locs(c): inv_locs(c+1)+wind); % pulse + window
% 66% width
t = linspace(0, numel(chunk)-1, numel(chunk));
x = t(:).'; % Force Row Vectors
y = chunk(:).'; % Force Row Vectors
[ymx,idx] = findpeaks(y, 'MinPeakProminence',10);
hafmax = ymx*0.66;
for k = 1:numel(hafmax)
idxrng1 = find(y(1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
end
format short g
xm = xm
wp = diff(xm,[],2)
format short
% figure
% plot(x, y)
% hold on
% for k = 1:numel(hafmax)
% plot([xm(k,1) xm(k,2)], [1 1]*hafmax(k), '-k', 'LineWidth',1.5)
% end
% hold off
% grid
% text(x(idx), hafmax.*ones(1,numel(idx)), compose('\\uparrow\nWidth = %.3f',wp), 'Horiz','center', 'Vert','top')
%vec=[vec; wp]
end
xm = 1×2
21.638 53.465
wp =
31.827
xm = 1×2
19.551 48.337
wp =
28.785
xm = 1×2
23.522 53.226
wp =
29.704
xm = 1×2
22.451 55.069
wp =
32.617
xm = 1×2
22.435 53.091
wp = 30.6561
xm = 1×2
19.4712 46.0098
wp = 26.5386
xm = 1×2
23.8133 57.1841
wp = 33.3708
xm = 1×2
22.6255 53.5973
wp = 30.9718
xm = 1×2
18.9069 44.4516
wp = 25.5446
xm = 1×2
23.7565 57.1283
wp = 33.3718
Error using matlab.internal.math.interp1
Sample points must be unique.
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
I am attaching the whole signal here
I am not certain what the problem is.
Using my original code, and detrending the data (this makes it more reliable), I get these results —
LD = load('filtered_abp[1].mat');
y = LD.filtered_abp;
t = linspace(0, numel(y)-1, numel(y));
x = t(:).'; % Force Row Vectors
y = y(:).'; % Force Row Vectors
figure
plot(t, y)
grid
xlabel('t')
ylabel('Pressure')
title('Original Signal')

y = detrend(y, 15);
[ymx,idx] = findpeaks(y, 'MinPeakProminence',10);
hafmax = ymx*0.66;
for k = 1:numel(hafmax)
idxrng1 = find(y(1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
end
format short g
xm = xm
xm = 14×2
9.524 20.757
125.76 151.4
266.74 294.41
408.61 436.83
550.15 578.03
692.72 719.91
832.49 859.11
973.75 1002.9
1118.4 1144.9
1258.1 1283.4
wp = diff(xm,[],2);
wpmtx = buffer(wp,7) % Show All Values
wpmtx = 7×2
11.233 29.107
25.646 26.537
27.67 25.27
28.217 30.241
27.881 25.185
27.192 0
26.62 20.373
format short
figure
plot(x, y)
hold on
for k = 1:numel(hafmax)
plot([xm(k,1) xm(k,2)], [1 1]*hafmax(k), '-k', 'LineWidth',1.5)
end
hold off
grid
text(x(idx), hafmax.*ones(1,numel(idx)), compose(' \\leftarrow Width = %.3f',wp), 'Horiz','left', 'Vert','middle', 'Rotation',-90, 'FontSize',7)
xlabel('t')
ylabel('Pressure')
title('Detrended Signal With Data')
xlim([-50 max(t)])

Experimnent to get different results.
.
Now it worked. Thank you so much sir for you time and help.
As always, my pleasure!
.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Signal Generation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
