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.
.
Shehzaib Shafique
2021 年 8 月 22 日
It worked. Thank you so much sir.
Star Strider
2021 年 8 月 22 日
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.
.
Shehzaib Shafique
2021 年 8 月 22 日
Now it worked. Thank you so much sir for you time and help.
Star Strider
2021 年 8 月 22 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
