Plots of Savitzky-Golay
Show older comments
Hi,
I have several questions regarding the Savitzky-Golay filter.
I managed to follow the example from the website here: http://uk.mathworks.com/help/signal/ref/sgolay.html
I basically want to show visually, several signals filtered on top of the noisy signal. The example given only shows for one filter and the default colours. Here are the codes that I currently used.
1) This is saved as a .mat file so I have the same noisy signal to use with different filters.
xLim = 1000; % Generate numbers from 0 to 1000.
dx = 0.1; % Increment of 0.1.
x = 0:dx:xLim-1; % Generate a series of numbers from 0 to 999 (xLim-1) with increment of 0.1.
y0 = 6*sin(0.4*pi*x); % Create sine signal.
y = awgn(y0,0.01,'measured'); % Add white Gaussian noise.
2) I load the above and then apply the filter.
N = 2; % Order of polynomial fit (2,4,6,8 required)
F = 11; % Window length (11,23,35,47,59 required)
[b,g] = sgolay(N,F); % Calculate S-G coefficients
HalfWin = ((F+1)/2) -1;
for n = (F+1)/2:(length(x)-5)-(F+1)/2,
% Zeroth derivative (smoothing only)
SG0(n) = dot(g(:,1),y(n - HalfWin:n + HalfWin));
end
plot(x(1:length(SG0)),[y(1:length(SG0))',SG0']); % plot of noisy and smoothed signal
axis ([480 520 -20 20]); % changes view of axis to certain limits
set(gca,'Color',[0.8 0.8 0.8]); % changes background colour to grey
ylabel('Noisy Signal')
Questions:
- How can I change the colour and width of the lines?
(I have tried using the code below but this changes both line colours) >>plot(x(1:length(SG0)),[y(1:length(SG0))',SG0'],'k','LineWidth',2.5);
- How can I present other filters (Different N or F value on the same figure)
(I am able to produce multiple smoothed filters on top of the noisy signal but I'd want it to be already in colour within the codes rather than manually editing it in)
- Rather than visually seeing which smoothing filter best represents the signal. Is there another way to compare the two signals (noisy + smoothed) with one another and give a numerical value at the end?
(I tried to use corrcoef (x,y) but I do not know how to apply it properly)
I hope I can get some help from you guys.
Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Smoothing and Denoising in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!