How can I smooth data around a specific region?
10 views (last 30 days)
Show older comments
Steven Manz on 20 Jan 2023
Commented: Steven Manz on 21 Jan 2023
I have data. It is fairly noisy just as it is. But I only really want to smooth the oscillations. In the figure attached, the dashed red line is what I hope to achieve. I assume that there may be a need for a piecewise smoothing function. But I am not sure how to accomplish this. The data is also attached for anyone that wants to play. Thank you ahead of time for any advice.
Image Analyst on 20 Jan 2023
Try a median filter. It smooths out local oscillations while keeping true steps intact and steep:
s = load('matlab_question.mat');
time_ = s.time_;
ids_ = s.ids_;
plot(time_, ids_, 'b-', 'LineWidth', 2)
% Take median filter
smoothIds = medfilt1(ids_, 451);
plot(time_, smoothIds, 'r--', 'LineWidth', 2)
More Answers (1)
Joel Van Sickel on 20 Jan 2023
Here is a simple script that gives you an easy way to implement filtering on specific pieces of data. You can accomplish this by writing something that goes inside a conditional expression looking at time. I'm just creating my own time and data vector as an example.
t = 0:0.1:1;
data = sin(t);
for i = 1:length(t)
if t(i) > 0.5 && t(i) < 0.75 % only filter data for times between 0.5 and 0.75
data(i) = (data(i-1)+data(i)+data(i+1))/3
now, that just averages the 3 points next to each other, which is a very small amount of filtering, but you can replace that line with a more sophisticated filter or averaging approach.
Image Analyst on 21 Jan 2023
@Alex Sha he said "I only really want to smooth the oscillations" and that formula has the oscillations still in there.
More Answers in the Power Electronics Control
Find more on Smoothing and Denoising in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!