Dear all, how to select the values for k and f, of savitzky-golay filter?
조회 수: 5 (최근 30일)
이전 댓글 표시
Dear all, how to select the values for k and f, of savitzky-golay filter?
댓글 수: 0
채택된 답변
Image Analyst
2018년 9월 15일
You pick them to give the signal you want. There is no one right value for all situations. It's a judgment call. A longer frame width will take more points into consideration when fitting the polynomial and give a smoother curve. A higher polynomial will more accurately "hug" the actual/noisy training data, while a lower polynomial order will give a smoother, less "huggy" fit.
댓글 수: 5
Image Analyst
2018년 9월 15일
Try this:
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Make a noisy sine wave signal
x = 1 : 3000;
period = 500
y = sin(2*pi*x/period);
noiseAmplitude = 0.8;
y = y + noiseAmplitude * rand(size(y));
subplot(2,1,1);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
title('Noisy Signal', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Try orders of 1-4, and frame lengths of 3 to about a quarter of your signal length.
frameLengths = 3 : 8 : 201
for polynomialOrder = 2 : 4
for k = 1 : length(frameLengths)
% Make sure windowWidth is long enough given the polynomial order we are using.
windowWidth = max([polynomialOrder + 1, frameLengths(k)]);
% Make sure windowWidth is odd
if rem(windowWidth, 2) == 0
windowWidth = windowWidth + 1;
end
caption = sprintf('Smoothed Signal with Polynomial Order = %d, windowWidth = %d', polynomialOrder, windowWidth);
fprintf('%s\n', caption);
% Now smooth with a Savitzky-Golay sliding polynomial filter
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
subplot(2,1,2);
plot(x, smoothY, 'b-', 'LineWidth', 2);
grid on;
title(caption, 'FontSize', fontSize);
promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
break;
end
end
end

Adapt as needed for your signal.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!