Dear all, how to select the values for k and f, of savitzky-golay filter?

3 visualizaciones (últimos 30 días)
Dear all, how to select the values for k and f, of savitzky-golay filter?

Respuesta aceptada

Image Analyst
Image Analyst el 15 de Sept. de 2018
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 comentarios
Image Analyst
Image Analyst el 15 de Sept. de 2018
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.
Ayisha Nayyar
Ayisha Nayyar el 16 de Sept. de 2018
really thankful....I am trying to implement this discussion on my problem.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by