Dear all, how to select the values for k and f, of savitzky-golay filter?
2 ビュー (過去 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!