[pks locs] = findpeaks(data_compact(:,2),'MinPeakHeight',0.992*max(data_compact(:,2)),'MinPeakDistance',5000e-3); % peaks data_inverted(:,1) = data_compact(:,1); data_inverted(:,2) = -data_compact(:,2); %[valley valleys_locs] = findpeaks(data_inverted(:,2),'MinPeakDistance',0.2e-3); % valleys
try this:
clc; % Clear the command window. clear all; close all; workspace; % Make sure the workspace panel is showing. format short g; format compact; fontSize = 22; fprintf('Beginning to run %s.m ...\n', mfilename); %-------------------------------------------------------------------------------------------------- % Load data from mat file. s = load('data_compact.mat') data_compact = s.data; x = data_compact(:,1); % Plot data. plot(x, data_compact(:,2), 'b-'); xlim([x(1), x(end)]); grid on; hold on; %-------------------------------------------------------------------------------------------------- % Smooth with a savitzky-golay filter. Polynomial order = 2, window width = 351 elements. smoothY = sgolayfilt(data_compact(:, 2), 2, 351); plot(x, smoothY, 'r-'); %-------------------------------------------------------------------------------------------------- % Find peaks. Must be separated by 13000 elements. [peakValues, indexesOfPeaks, widths, proms] = findpeaks(smoothY, 'MinPeakDistance',13000); % peaks % Remove an occasional outlier that is below the midpoint. meanSignal = mean(smoothY); outlierIndexes = peakValues < meanSignal; peakValues(outlierIndexes) = []; indexesOfPeaks(outlierIndexes) = []; % Plot peaks. plot(x(indexesOfPeaks), peakValues, 'g.', 'MarkerSize', 30); %-------------------------------------------------------------------------------------------------- % Find Valleys. Must be separated by 13000 elements. [valleyValues, indexesOfValleys] = findpeaks(-smoothY, 'MinPeakDistance', 13000); % valleys valleyValues = -valleyValues; % Make upright again. % Remove an occasional outlier that is above the midpoint. outlierIndexes = valleyValues > meanSignal; valleyValues(outlierIndexes) = []; indexesOfValleys(outlierIndexes) = []; % Plot valleys. plot(x(indexesOfValleys), valleyValues, 'c.', 'MarkerSize', 30); message = sprintf('Found %d peaks, and %d valleys', length(indexesOfPeaks), length(indexesOfValleys)); title(message, 'FontSize', fontSize); % Maximize the figure window. g = gcf; g.WindowState = 'maximized' fprintf('%s\n', message); uiwait(helpdlg(message)); fprintf('Done running %s.m ...\n', mfilename);
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.