Distance between peaks for many data
2 views (last 30 days)
Show older comments
Hello everyone. I am new to MATLAB and would like to know if you can help me or give me some information with the following problem. I have written a code that parses a 13999 data file, my code first changes the file format from .txt to .mat, then I normalize this data and invert the peaks (since my data is plotted with peaks down). Then it finds the highest peaks based on height (0.2) and gives me the data distance between peaks. Now this works fine with a single file, but I have 15000 of these files, for this I want to make a program that can apply my code to each file automatically and take the distance between the peaks of each file and save it in a single file .txt The other option I have in mind is that my code can be applied to a file with all the data (ie 13999x15000), on the condition that I load only an interval of this file, find the distance between peaks and save it for myself. in a single file. And I can analyze all my data in intervals this way. And so I can get the distance between peaks of all my data.
Any help, suggestion or reference I would appreciate very much.
my code to find the distance between peaks is:
%%txt to mat
M = dlmread('xag.txt'); %M = dlmread('xab.txt');
save('xag.mat','M');
%%load file
load('xag.mat')
s = M(1:13999,1);%
plot(s)
%Invert peaks
maxs = max(s);
s2 = maxs-s;
%figure
%plot(s2)
sn = s2/maxs; %the maximum point will be 1. rescale 0-1.
%figure()
%plot(sn)
%find peaks and their position, according to their height
[alt1,pos1] = findpeaks(sn,'MinPeakHeight',0.2);
figure()
findpeaks(sn,'MinPeakHeight',0.2)
title('find peaks and their position, according to their height')
%distance between 2 peaks that meet the condition
difpos = diff(pos1)
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!