Plots of Savitzky-Golay
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Mohammad Abouali
2015-1-28
编辑:Mohammad Abouali
2015-1-28
do it like this
plot(x(1:length(SG0)),y(1:length(SG0))','k','LineWidth',2.5);
hold on
plot(x(1:length(SG0)),SG0','r','LineWidth',2.5);
you can add more plots after hold on
plot(x(1:length(SG0)),FilteredDataUsingOtherParameters,'r','LineWidth',2.5);
then you can add the legend
legend('noisy data','Filtered using parameter 1', 'Filtered Using parameter 2')
corrcoef gives correlation coefficient. Once you smooth your data the correlation coefficient goes down anyway. The more it is smoothed the lower it would be. So, it is kinda hard to decide what is good and what is bad. Because the one that has the highest correlation coefficient is the one that is not smoothed at all (i.e. your original data), which certainly is the one that you don't want.
2 个评论
Image Analyst
2015-1-29
Overwriting a previous version of a signal does not affect the comparison of the current signal with your original noisy waveform - why would it?
Your proposed comparison, the "mean absolute difference" (see Wikipedia) is fine.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!