# [Scilab-users] Padding and clipping a grid

15 messages
Open this post in threaded view
|

## [Scilab-users] Padding and clipping a grid

Open this post in threaded view
|

## Re: Padding and clipping a grid

 Hello Lester, Le 29/07/2018 à 13:18, arctica1963 a écrit : > Hello all, > > I need to increase the dimensions over which the FFT is calculated to avoid > edge effects, AFAIK, padding the initial signal does not avoid edge effects (i guess one deal with edges discontinuity). It can even be the source of discontinuity, and so yield fake high fft amplitudes at high frequencies. It will be the case if  the original signal S has no edge discontinuity ( S(1)~S(\$)) but you padd it with zeros while its edge does not fall to zeros (=> |S(\$)|>>0, S(\$+1)==0). Even worse, in this case, windowing the signal will no longer be effective, since the padding will move the discontinuity in the body of the padded signal instead of on signal's edge. Padding a signal increases the lowest frequency of its numerical FT, that is the sampling frequency of its FFT. AFAIUnderstand, there is no edge matter there. But this is more a signal processing topic than a Scilab one. Regards Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 In reply to this post by arctica1963 Le 29/07/2018 à 13:56, Samuel Gougeon a écrit : Hello Lester, Le 29/07/2018 à 13:18, arctica1963 a écrit : Hello all, I need to increase the dimensions over which the FFT is calculated to avoid edge effects, AFAIK, padding the initial signal does not avoid edge effects (i guess one deal with edges discontinuity). It can even be the source of discontinuity, and so yield fake high fft amplitudes at high frequencies. It will be the case if  the original signal S has no edge discontinuity ( S(1)~S(\$)) but you padd it with zeros while its edge does not fall to zeros (=> |S(\$)|>>0, S(\$+1)==0). Even worse, in this case, windowing the signal will no longer be effective, since the padding will move the discontinuity in the body of the padded signal instead of on signal's edge. Padding a signal increases the lowest frequency of its numerical FT, that is the sampling frequency of its FFT. AFAIUnderstand, there is no edge matter there. But this is more a signal processing topic than a Scilab one. Le 29/07/2018 à 13:18, arctica1963 a écrit : ```Hello all, I need to increase the dimensions over which the FFT is calculated to avoid edge effects, and following the suggestion of Samuel Gougeon back in 2016, this was recommended: Scilab: 6.0.1 data = [1 2 3; 4 5 6; 7 8 9] addedRows = 3; addedCols = 3; tmp = [data ; data(\$, :) .*. ones(addedRows, 1)]; // add rows to bottom tmp = [tmp tmp(:, \$) .*. ones(1,addedCols)]; // add columns to right tmp = [repmat(tmp(1, : ), addedRows, 1) ; tmp]; // add rows to top paddedMat = [repmat(tmp(:,1) , 1, addedCols) tmp] // add columns to left``` --> paddedMat = [repmat(tmp(:,1) , 1, addedCols) tmp] // add columns to left  paddedMat  =    1.   1.   1.   1.   2.   3.   3.   3.   3.    1.   1.   1.   1.   2.   3.   3.   3.   3.    1.   1.   1.   1.   2.   3.   3.   3.   3.    1.   1.   1.   1.   2.   3.   3.   3.   3.    4.   4.   4.   4.   5.   6.   6.   6.   6.    7.   7.   7.   7.   8.   9.   9.   9.   9.    7.   7.   7.   7.   8.   9.   9.   9.   9.    7.   7.   7.   7.   8.   9.   9.   9.   9.    7.   7.   7.   7.   8.   9.   9.   9.   9. OK: here the padding is not done with zeros. Sorry for my misunderstanding. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 In reply to this post by Samuel GOUGEON Hi,   A standard practice is to apply tapering then padding (with zeros).   Regards, Rafael     _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 Le 29/07/2018 à 14:07, Rafael Guerra a écrit : Hi,   A standard practice is to apply tapering then padding (with zeros). AKA windowing. In Scilab: https://help.scilab.org/docs/6.0.1/en_US/window.html 2D windows can be built from these 1D profiles. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 Le 29/07/2018 à 14:25, Samuel Gougeon a écrit : Le 29/07/2018 à 14:07, Rafael Guerra a écrit : Hi,   A standard practice is to apply tapering then padding (with zeros). AKA windowing. In Scilab: https://help.scilab.org/docs/6.0.1/en_US/window.html 2D windows can be built from these 1D profiles. By the way, it could be useful to upgrade window() in order to become able to generate such 2D or N-D windows without external postprocessing. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 In reply to this post by Samuel GOUGEON Hi all, I will have to look further into this. I can check the results against GMT (grdfft), I think they may use tapering but will have to look at the code (C++). Can I confirm that clipping is done via resize_matrix? Cheers Lester -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 Le 29/07/2018 à 14:53, arctica1963 a écrit : > Hi all, > > I will have to look further into this. I can check the results against GMT > (grdfft), I think they may use tapering but will have to look at the code > (C++). > > Can I confirm that clipping is done via resize_matrix? Not if it is symetric. The f = fft() result put high frequencies (to be removed) at the center of the spectrum. So, if you don't use fftshift() to put it on the spectrum's edges, you will have to do someting like: pw = [pwr, pwc];  // predefined padding widths s = size(f); tf = f([1:s(1)/2-pwr s(1)/2+pwr:s(1)], [1:s(2)/2-pwc s(2)/2+pwc:s(2)]; But this expression is approximative, depending on the oddness of s components, etc. It is easier to trimmed the shifted spectrum: sf = fftshift(f); tsf = sf(pwr+1:\$-pwr, pwc+1:\$-pwc); and then backshift the trimmed spectrum: sf = fftshift(tsf); This is the idea. Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 Le 29/07/2018 à 15:06, Samuel Gougeon a écrit : But this expression is approximative, depending on the oddness of s components, etc. Sorry for my bad (and too fast) english. I meant: the parity: if each size is even or odd. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 In reply to this post by Samuel GOUGEON Le 29/07/2018 à 14:48, Samuel Gougeon a écrit : Le 29/07/2018 à 14:25, Samuel Gougeon a écrit : Le 29/07/2018 à 14:07, Rafael Guerra a écrit : Hi,   A standard practice is to apply tapering then padding (with zeros). AKA windowing. In Scilab: https://help.scilab.org/docs/6.0.1/en_US/window.html 2D windows can be built from these 1D profiles. By the way, it could be useful to upgrade window() in order to become able to generate such 2D or N-D windows without external postprocessing. Wish now reported as bug 15694. See also https://en.wikipedia.org/wiki/Window_function#Two-dimensional_windows _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 Thanks for the suggestions and clarification. -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 In reply to this post by Samuel GOUGEON Hi,   A more detailed reference is:   In the simplest approach, the 2D window is the outer product of two 1D windows:  Wxy = wx'*wy   For example:    nx=100;    ny=200;    wx = window('hm',nx);    wy = window('hm',ny);    ix = linspace(0,1,length(wx));    iy = linspace(0,1,length(wy));    Wxy = wx'*wy;    clf()    gcf().color_map = hotcolormap(64);    Sgrayplot(ix,iy,Wxy)   Regards, Rafael _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Padding and clipping a grid

 Hi Rafael, I reviewed the methodology applied in GMT (grdfft) and they use tapering from the grid edges to zero. The documentation page details more: GMT_grdfft   The padding method that has been discussed previously is the similar to that of grdfft edge-point symmetry, but without the tapering to zero. It would be handy to have this padding and tapering better defined in Scilab for 2D grids. Lester -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users