Comparison of waveforms with Savitzky-Golay filter

2 次查看(过去 30 天)
Hi,
I have managed to produce the plot of different filters on the same noisy signal. I would like to be able to compare each smoothed signal with the noisy signal. However I think the way I am running the codes I am over writing the previous smoothing filter and just plotting the results. Will this affect the comparison when I choose to compare the noisy signal with any of the filters?
This is how I currently run the codes:
load 'SineNoise'
Filter1
Filter2
Filter3
Filter4
Filter5
Plot
1) load 'SineNoise'
- This is the same from previous post
2) Filter1
N = 2; % Order of polynomial fit 2,4,6,8
F = 11; % Window length 11,23,35,47,59
[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 against x 0,0.1,0.2,....,
plot(x(1:length(SG0)),y(1:length(SG0)));
hold on
plot(x(1:length(SG0)),SG0','y','LineWidth',2.5);
3) Filter2 to Filter5 are pretty much the same except for the F value changing.
N = 2; % Order of polynomial fit 2,4,6,8
F = 23; % Window length 11,23,35,47,59
[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 against x 0,0.1,0.2,....,
plot(x(1:length(SG0)),SG0','m','LineWidth',2.5);
4) Plot - changing the axis and background colour aswell as legend
axis ([480 520 -20 20]); %changes view of axis to certain limits
legend('Noisy data','Filter1', 'Filter2', 'Filter3', 'Filter4', 'Filter5')
set(gca,'Color',[0.8 0.8 0.8]); %changes background colour to grey
ylabel('Noisy Signal')
I am just curious if it's possible when comparing the filter with the noisy signal to do something like this: Difference between the filter and the noise for each data point at a certain range (say from 480-520) and the average between the two. I am basically just looking for a number or a percentage difference between the two waveforms.
Or is there another/better way to compare the waveforms?
Thanks

采纳的回答

Image Analyst
Image Analyst 2015-1-29
There are several ways, such as RMS, mean absolute difference, PSNR, etc. Sounds like you're mostly describing the mean absolute difference. I suppose it's as good a way as any. It should work for your purposes, I would guess.
  1 个评论
Vince Roman
Vince Roman 2015-1-29
How could I apply it within the codes shown above. I use it after I apply a filter at a time?

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by