Smoothing or special techniques to resolve uncertain peaks are required!!

25 views (last 30 days)
한 박 on 26 May 2024 at 14:47
Commented: Star Strider on 27 May 2024 at 11:00
I need to find the local extremum point in this data and The photo above shows the data where we found the maxima.
However, the peaks have an irregular pattern. How can I make this data as smooth as a sin function?

Star Strider on 26 May 2024 at 15:35
If you want to make it smooth, there are a few options. One of course is to calculate the Fourier transform, choose a suitable cutoff frequency from that information, and then use either the lowpass or bandpass functions to filter it. For best reulsts, use the name-value pair 'ImpulseResponse','iir' with those.
A second option is to use the Savitzky-Golay filter (sgolayfilt) function. I usually use a 3-degree polynomial,, and then vary the ‘framelen’ value to get the result I want.
If you are simply concerned about getting the ‘correct’ peak values and locations without the nearby additional peaks, an easier option is to use 'MinPeakDistance' with findpeaks or 'MinSeparation' with islocalmax.
All signal processing is somewhat interactive, and most techniques require some experimentation to get the desired result.
한 박 on 27 May 2024 at 5:47
thank you :)
Star Strider on 27 May 2024 at 11:00
As always, my pleasure!

William Rose on 26 May 2024 at 18:47
You ask "how can I make this data as smooth as a sin function?".
You could fit the data with a sinusoid. Here is an example.
xdata=0:100;
s=4; % amplitude of noise added to sinusoid
ydata=10*sin(0.3*xdata)+5+s*(rand(1,101)-.5); % noisy sine wave
% Define function
fun = @(p,x)p(1)*sin(p(2)*x+p(3))+p(4);
% p(1)=amplitude, p(2)=frequency, p(3)=phase, p(4)=offset
% Find parameters that give best fit
% p0=initial guess for parameters
r=zerocrossrate(ydata-mean(ydata)); % zero crossing rate
p0=[(max(ydata)-min(ydata))/2,r*pi,mean(ydata),0];
lb=[.1,.01,0,-50]; % lower bounds for parameters
ub=[100,10,2*pi,50]; % upper bounds for parameters
p = lsqcurvefit(fun,p0,xdata,ydata,lb,ub)
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
p = 1x4
10.2101 0.2998 6.2832 5.0292
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% compute the fitted curve
yfit=fun(p,xdata);
% plot result
figure; plot(xdata,ydata,'r*',xdata,yfit,'-r');
The maximum values of this fitted function are all the same. The maximum values of this fitted function are p(1)+p(4). You could make a different fitting function.