Get the number of pulses from data set

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Scope 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