How do I find the zeros of a filtered graph?
Show older comments
I imported data and applied filters. I can plot the newly filtered data and now I want to find all the points that the curves hit the x-axis. All functions I have found to find zeros want a defined function, which I don't have. I just have the x and y data. Code up until I plotted the data is shown below and a picture of an example of the resulting graph.
How can I find the values where the curves intersect the x-axis?
Thanks!

file_id1 = input('Enter the name of the csv file. i.e. Pilottesting\n', 's');
fprintf('Computing')
file_id2 = sprintf('%s', file_id1, '.csv');
data = csvread(file_id2, 2, 0); % All six channels, raw data
BSL1 = csvread(file_id2, 1, 6, [1 6 1 6]);
BSL2 = csvread(file_id2, 1, 7, [1 7 1 7]);
BSL3 = csvread(file_id2, 1, 8, [1 8 1 8]);
BSL4 = csvread(file_id2, 1, 9, [1 9 1 9]);
CF1 = csvread(file_id2, 1, 10, [1 10 1 10]);
CF2 = csvread(file_id2, 1, 11, [1 11 1 11]);
CF3 = csvread(file_id2, 1, 12, [1 12 1 12]);
CF4 = csvread(file_id2, 1, 13, [1 13 1 13]);
SampleRate = csvread(file_id2, 1, 14, [1 14 1 14]);
% Preallocate Variables
buffer = 0; % Extra data points so peak detection can have a wide range
L = length(data);
datap = zeros(L + buffer, 6);
displ = zeros(L + buffer, 1); % Displcement [mm]
fnet = zeros(L + buffer, 1); % Net force [N]
time = L/(SampleRate*60); % Length of trial [minutes]
fprintf('.') % Display progress; data loaded
%%Data Processing
% Apply Baseline and Calibration Factor
for n = 1:L
datap(n, 1) = CF1*(data(n, 1) - BSL1);
end
for n = 1:L
datap(n, 2) = CF2*(data(n, 2) - BSL2);
end
for n = 1:L
datap(n, 3) = -CF3*(data(n, 3) - BSL3);
end
for n = 1:L
datap(n, 4) = -CF4*(data(n, 4) - BSL4);
end
% Displacement and Net Force
displ(1, 1) = 0; fnet(1, 1) = 0; %Reset varaibles
for n = 1:L
displ(n, 1) = (datap(n, 4) - datap(n, 3));
end
for n = 1:L
fnet(n, 1) = (datap(n, 2) + datap(n, 1));
end
% Filter Data: Recursive, 6th degree low pass butterworth filter with cutoff frequency of 5 Hz
[b, a] = butter(6, 5/(SampleRate/2));
fn = filter(b, a, fnet);
fn = flipud(filter(b, a, flipud(fn)));
dis = smooth(displ, 50, 'lowess'); %Applies an n point moving average filter
% Plot Data
figure(1)
plot(dis,fn)
Answers (1)
Geoff Hayes
on 29 Jan 2016
A - since you have all of the x data, dis (?), then you could use sign to determine which elements are greater than zero (1), equal to zero (0), and less than 0 (-1) as
signData = sign(dis);
Of course, some of your data may not be identical to zero (so there will be no zeros in signData) so you will have to check when there is a difference in sign, from negative to positive). You can use diff to help with that.
The above assumes that dis a one-dimensional array. If this is not the case (and it may not be given the number of curves on your plot), then you will have to consider each row within the 2D array.
Categories
Find more on Matrix Decomposition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!