Clear Filters
Clear Filters

Finding the best parameters for Savitzky-Golay filter

35 views (last 30 days)
Hello,
I have been using Savitzky-Golay filter to smoothed a noisy signal.
There are 2 options for parameters, N: Polynomial fit and F: Window length
Are there any ways to quantify which best filter would be to use?
Below is for a polynomial fit of 2 and different window lengths for different filters
I know that by looking at the graph visually, you can at an extent say which filter is best but is there a possibility that a number can be generated in a form of comparison from each filters?
Regards

Answers (2)

Jan
Jan on 17 Feb 2015
It depends on how you define "best". It is impossible to find a unique definition for "best" filter parameters, because this depends on the nature of the signal: A filter should distinguish between the noise and the wanted signal. But the noise could have lower or higher frequencies than the wanted signal, and both can have different frequency spectra in addition.
So how do you define "good" in your specific case?
  3 Comments
Jan
Jan on 17 Feb 2015
Again: It is impossible to find a general method to obtain the "original" signal. It depends on the nature of the signal and of the noise. Imagine that you have a sine wave and triangle wave with two different frequencies. Then it matters for the "best" filter parameters, if you want to obtain the sine or the triangle wave.
You can use the Mean Absolute Deviation, if this satisfies your needs. Do you have the original signal for a comparison?
Vince Roman
Vince Roman on 17 Feb 2015
Yes,
This is my current codes that I used for this sine wave:
xLim = 1000; % Generate numbers from 0 to 1000.
dx = 0.01; % Increment of 0.01.
x = 0:dx:xLim-1; % Generate a series of numbers from 0 to 999 (xLim-1) with increment of 0.01.
y0 = 6*sin(0.4*pi*x); % Create sine signal.
y = awgn(y0,10,'measured'); % Add white Gaussian noise lowest to highest 10, 6, 3, 0.01
This is saved as SineNoise1. I then apply the filters with different polynomial fit/window lengths.
This new figure might make more sense:
I am trying to find a way to use to compare the different filters with one another on different noise level signals and also on different waveforms such as triangle, square and complex.
Using the Mean Absolute Deviation, it has worked for the sine, triangle and complex wave but they are all giving me the same filter as the 'best' one which made me think if that is actually the case.
However, for the square wave the mad(x) doesn't give similar results, could it be due to the codes I use? y = square(2*x)

Sign in to comment.


swapnil mishra
swapnil mishra on 9 Jan 2018

HOW TO KNOW THE ORDER AND FRAMELENGTH ??

clc

clear all

close all

[x,fs]=audioread('Record_0001.wav'); %load the sound

sound(x,fs)

pause(3)

figure(1)

plot(x)

x = x+(randn(size(x)));

figure(2)

plot(x)

sound (x,fs);

pause(3)

order = 8;

framelen = 21;

b = sgolay(order,framelen);

y = conv(x,b((framelen+1)/2,:),'valid');

z = b(end:-1:(framelen+3)/2,:) * x(framelen:-1:1);

z1 = b((framelen-1)/2:-1:1,:) * x(end:-1:end-(framelen-1));

sound(x)

z3 = sgolayfilt(x,7,41);

y = [z; y; z1];

figure(3)

plot([x y])

legend('Noisy Sinusoid','S-G smoothed sinusoid')

figure(4)

sound(z3,fs)

subplot(2,1,1) plot(1:2000, x(1:2000)) axis([0 2000 -4 4]) title('mtlb') grid

subplot(2,1,2) plot(1:2000,z3(1:2000)) axis([0 2000 -4 4])

title('smtlb') grid

                                 graph_of_input_speech
                                 graph_of_input_speech_with_noise
                                 graph after using sgolay
                                couldn't get desired output
  1 Comment
KAE
KAE on 9 Apr 2019
Can you put some description in your answer to tell what you are doing? I can't see how you are estimating the optimal frame length and polynomial order here.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!