Smoothing only a part of a Curve

13 次查看(过去 30 天)
Anirudh
Anirudh 2014-2-17
评论: Anirudh 2014-2-20
What functions/commands can I use to smooth only a part of my curve? Lets say I have data from x= 0 to x= 500 on the x-axis with corresponding y points. I would like to smooth only data between x= 200 to x= 400, and the rest to be the original data itself. So that sharp edges between x= 0 and x= 200 remains, and then between x= 200 to 400, I get a smooth curve part, and then beyond x= 400 it retains the original shape. There was nothing I could find that would let me smoothen only a part of my curve.
Could someone please help me on this one?
Best regards, Anirudh

回答(1 个)

Image Analyst
Image Analyst 2014-2-17
Just smooth everything and replace the smoothed parts, like this code:
fontSize = 25;
% Make sample signal a noisy cosine
x = 1 : 500;
period = 70;
noisySignal = 3*cos(2*pi*x/period) + rand(1, length(x));
subplot(2,2,1);
plot(x, noisySignal, 'b.-');
title('Original Noisy Signal', 'FontSize', fontSize);
grid on;
yl = ylim();
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Apply the Savitzky-Golay filter.
k = 2; % Order of the polynomial
windowSize = 25;
smoothedSignal = sgolayfilt(noisySignal, k, windowSize);
subplot(2, 2, 2);
plot(x, smoothedSignal, 'b.-');
grid on;
title('Savitzky-Golay Filtered Signal', 'FontSize', fontSize);
% Make y limits be the same.
ylim(yl);
% Make a new signal with x=200 to 400 being smooth
newSignal = noisySignal; % Initialize.
newSignal(200:400) = smoothedSignal(200:400);
subplot(2, 2, 3:4);
plot(x, newSignal, 'b.-');
grid on;
title('Composite Signal', 'FontSize', fontSize);
% Make y limits be the same.
ylim(yl);
  3 个评论
Image Analyst
Image Analyst 2014-2-20
It's virtually the same code. I don't really care WHERE you get noisy signal - I just made up the cosine curve because I needed some data. Of course you can get it however you need to , such as reading it in from a file, or whatever. After that the code is the same. Basically, filter it all and replace the chunk you want to with the filtered data.
Anirudh
Anirudh 2014-2-20
Hi,
Its me again. And I'm still not satisfied with the curves I have :(. The specificity of my problem now lies in the convergence of both raw and smooth signals.
I'm attaching a file for your reference with the raw signals. This is exactly what I have, and I only need to smooth-en the peak which is around the x=800 mark with a smoothing window that could decide how much to do so.
While the constant slope from around x=720 to the point where smoothing of the peak starts needs to be from the original raw data. So in effect, I need the raw data up until the start of the peak, then the smoothed part, and then back with the original data once the smoothed signal rejoins the original signals. Could that be done?
Looking to hear your views Image Analyst, thanks a ton for your time.
Regards, Anirudh

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by