필터 지우기
필터 지우기

Smoothing only a part of a Curve

조회 수: 12 (최근 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

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

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by