[Scilab-users] circshift() : Scilab Enhancement Proposal

Samuel Gougeon sgougeon at free.fr
Thu May 31 11:39:08 CEST 2018


Hello Rafael,

Le 10/01/2018 à 00:01, Rafael Guerra a écrit :
>
> Hi Samuel,
>
> .../...
>
> Regarding extending circshift() to non-integers I had in mind 
> n-dimensional matrices and the discrete Fourier transform.
>
> These matrices could represent regularly sampled 1D time signals, or 
> 2D/3D spatial functions, etc.
>
> In this context the shift theorem gives a specific meaning to the 
> circular shifts of the input signals (corresponding to linear phase 
> shifts in their spectrum).
>

Using fractional shifts means that we somewhat address some frequencies
higher than the sampling one. Then, as expected, if such a feature is
implemented through the DFT, and unless the input signal is
* a truly periodic one
* sampled over an integer number of its period,
which are very restrictive conditions, we will face issues such as the Gibb
artefact, deserving or even demanding some damping window options, etc.

This is far beyond the main purpose of circshift() whose elementary job 
misses for years now.
We would go then into signal processing, with its usual complications,
only applicable to arrays of real or complex numbers, while circshift() is
basically applicable to all arrays of any datatype.

To me, your proposal to extend circshift() to fractional shifts needs some
further analysis, to compare several possible implementations.
It could make an additional SEP with its own new options, after merging
the basic but very expected circshift().

Using the DFT to interpolate input data has the main advantage to not be
a local method. As a trade-off, it yields some artefacts, at least with 
a simple
implementation as provided herebelow.
Please do not hesitate to go on with it. I have not tried to recover the 
undamped
shifted signal after using some damping window to get ride of Gibb.

Using classical local interpolations -- linear or splined ones -- is 
also meaningful
and applicable only to real or complex numerical data.

A benchmark could be set to compare performances of DFT versus local 
interpolations,
iterating small fractional shifts summed to an integer, and measuring 
the distance
of the result to the true expected one (after an integer shift).
I let you do that and build your extension proposal.

Cheers
Samuel


// Fractional circshift: tests
n  =  100;
sig  =  sin(linspace(0,  2.5,  n));  // Built discontinuity from 2.5=>0
clf
subplot(1,  3,  1)
plot(sig)
title("Input 1D signal",  "fontsize",3);

subplot(1,  3,  2)
v  =  frac_shift(sig,  35);
plot(real(v))
title("Integer shift = 35",  "fontsize",3);

subplot(1,  3,  3)
v  =  frac_shift(sig,  35.4);   // fractional shift = 35.4
plot(real(v))
title("Fractional shift = 35.4",  "fontsize",3);
gca().tight_limits="on";
// As expected, we get some Gibb artefact oscillations near the
// discontinuity. Avoiding them required to damp wings of the input
// signal in order to damp the discontinuity, requiring to use a
// damping window and profile.

function  v= frac_shift(x, n)
     // x: 1D signal
     // n: shift, in decimal number of samples
     // v: x shifted by i samples
     N  =  length(x)
     sp  =  fft(x,  -1).';
     frequencies  =  (floor(-(N-1)/2):floor((N-1)/2))/N
     c  =  exp(2*%pi*%i*n*frequencies).';
     shifted_sp  =  ifftshift(fftshift(sp).*c);
     v  =  fft(shifted_sp,1);
     mprintf("%5.2f max(abs(imag(shifted sig)))= %f\n",  n,  max(abs(imag(v))));
endfunction

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20180531/3ee75b8b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lhameelmlamodjop.png
Type: image/png
Size: 10079 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20180531/3ee75b8b/attachment.png>


More information about the users mailing list