Get the number of pulses from data set

1 回表示 (過去 30 日間)
Lalmi Ahmed
Lalmi Ahmed 2021 年 4 月 3 日
回答済み: Image Analyst 2022 年 5 月 27 日
i have a set of data in xlsx file
it containes about 500 row and 3 column i want to get the number of pulses for each vector (column).
here is my draft, i was trying to count the number of values colser to the center(100)
clc
D = xlsread('newData.xlsx');
size(D)
T = D(:,1);
V = D(:,2);
I = D(:,3);
plot(T,V,T,I);
p= 0;
r = 100;
first = false;
for j = 1:length(V)-1 % loop through the vector V
if abs(V(j)-100) < 10 % if the difference between the value and 100 (horizonal center) is less than 10
if first == false
t = j; % t is the first time when we got point close to the center
p = 1;
first = true;
endif
if first == true
if j-t > 0.2 % if we find another point it sould be a bit far from the previous one
t = j;
p = p +1;
endif
endif
endif
endfor
disp('the number of pulses is ')
disp(p);
i think this is not a good way to do it so if you have any suggestion please help.
  1 件のコメント
dpb
dpb 2021 年 4 月 4 日
Have you tried findpeaks with a discrimination level and, possibly, a distance requirement?

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

回答 (1 件)

Image Analyst
Image Analyst 2022 年 5 月 27 日
Try this:
%============================================================================================================================================
% Demo by Image Analyst to count pulses
% Initialization Steps.
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 long g;
format compact;
fontSize = 20;
data = readmatrix('newData.xlsx');
x = data(:, 1); % X is the first column.
data = data(:, 2:end); % Y are the other columns.
[rows, columns] = size(data)
for col = 1 : columns
% Get this signal.
thisColumn = data(:, col);
% Plot it.
subplot(columns, 1, col);
plot(thisColumn, 'b-');
grid on;
% Get a threshold.
threshold = mean(thisColumn);
yline(threshold, 'Color','r', 'LineWidth', 2)
% Count pulses
binarySignal = thisColumn > threshold;
[~, numPulses] = bwlabel(binarySignal);
caption = sprintf('%d Pulses', numPulses);
title(caption, 'FontSize',fontSize)
end

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by