I am trying to find the peak and valley of a waveform. My data is attached in the matrix. It is a waveform repeated four times. I have written code based off of another thread. I am using findpeaks function, which worked well. I then used taking the max of the matrix and subtracting it to inverse the waveforms. However, it is displacing the waveform, which is a problem because I am trying to get the ratio of the peak to valley, so the displacing of the waveform is giving me inaccurate ratio. I will attach my code. Any ideas on how I might go about finding the valleys without displacing the waveform?
if truedatain=example;fs=4e4;[pks,locs,w,p]=findpeaks(datain,fs,'NPeaks',4);inverted=max(datain)-datain;pksmean=mean(pks);[valleys,locsvalley,wvalley,pvalley]=findpeaks(inverted,fs,'NPeaks',4,'WidthReference','halfheight');valleysmean=mean(valleys);peakvalleyratio=pksmean/valleysmean;halfwidthaveragevalleys=mean(wvalley);end
Best Answer