Skip to content

Instantly share code, notes, and snippets.

@caub
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caub/192c95cccddfa45f25f3 to your computer and use it in GitHub Desktop.
Save caub/192c95cccddfa45f25f3 to your computer and use it in GitHub Desktop.
Border effects, the importance of padding method

padding in green without padding, in red with symmetric padding

% generate a  noisy signal
y = flipud( 3*sin(0.14*(1:128)')-1/20*(1:128)'+ (((1:128)'-64)/20).^2 + randn(128,1));
w=[-21;14;39;54;59;54;39;14;-21]/231; % http://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter#Tables_of_selected_convolution_coefficients

z = zeros(length(y)+10,1); % bigger
z(5:end-4) = y; 
z(1:5) = flipud(z(6:10)); % symmetric padding
z(end-4:end) = flipud(z(end-9:end-5));

y_ = conv(w, y);
z_ = conv(w, z);

plot([y y_(5:end-4) z_(10:end-9)])
% generate a  noisy signal
y = flipud( 3*sin(0.14*(1:128)')-1/20*(1:128)'+ (((1:128)'-64)/20).^2 + randn(128,1));

dwtmode('zpd') % sets padding to zero outside range
plot([y wden(y,'heursure','s','one',3,'sym8') wden(y,'heursure','s','one',4,'sym8')], 'lineWidth',2)

zero padding

dwtmode('sym') % (default) sets symmetric padding outside range
% http://www.mathworks.fr/fr/help/wavelet/ug/dealing-with-border-distortion.html
plot([y wden(y,'heursure','s','one',3,'sym8') wden(y,'heursure','s','one',4,'sym8')], 'lineWidth',2)

sym padding

% no more border effects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment