필터 지우기
필터 지우기

Finding Valley of Waveform (local minimum) without displacing wave

조회 수: 19 (최근 30일)
Krispy Scripts
Krispy Scripts 2016년 11월 18일
댓글: Greg Dionne 2016년 12월 5일
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 true
datain=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

채택된 답변

Star Strider
Star Strider 2016년 11월 18일
It’s easiest to use the subscripts rather than the times to get the valleys. Also, there appears to be a bug in findpeaks such that supplying the sampling frequency does not produce the correct times for the peak locations. An easy workaround is to provide a time vector instead and use that.
See if this does what you want:
D = load('Krispy Scripts example.mat');
datain=D.datain;
fs=4e4;
t = linspace(0, 1, length(datain))'/fs; % Time Vector
[pks,locs,w,p]=findpeaks(datain,t,'NPeaks',4);
inverted=max(datain)-datain;
pksmean=mean(pks);
[valleys,locsvalley,wvalley,pvalley]=findpeaks(inverted,'NPeaks',4,'WidthReference','halfheight');
valleysmean=mean(valleys);
peakvalleyratio=pksmean/valleysmean;
halfwidthaveragevalleys=mean(wvalley);
valleys_actual = datain(locsvalley);
valleys_time = t(locsvalley);
figure(1)
plot(t, datain)
hold on
plot(locs, pks, '^r', 'MarkerFaceColor','r')
plot(valleys_time, valleys_actual, 'vr', 'MarkerFaceColor','r')
hold off
grid
The Plot
  댓글 수: 7
Star Strider
Star Strider 2016년 11월 19일
As always, my pleasure.
Greg Dionne
Greg Dionne 2016년 12월 5일
I think your observed issue with FINDPEAKS can be traced to how you set the input:
t = linspace(0, 1, length(datain))'/fs;
This should read instead:
t = (0:length(datain)-1)'/fs;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by