Smoothing or special techniques to resolve uncertain peaks are required!!
5 次查看(过去 30 天)
显示 更早的评论
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?
Nothing like LPF or moving average filters helped me, please help me out
0 个评论
采纳的回答
Star Strider
2024-5-26
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.
更多回答(1 个)
William Rose
2024-5-26
@한 박,
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)
% 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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!