在Matlab中通过非整数移位来移动向量的元素 [英] shift the elements of a vector by non-integer shift in matlab

查看:341
本文介绍了在Matlab中通过非整数移位来移动向量的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过非整数移位对向量进行移位,线性插值似乎不太准确,因此我尝试通过以下使用傅里叶变换的代码使用 sinc 插值.

I want to shift a vector by non-integer shift, linear interpolation seems to be not very accurate so I'm trying to use sinc interpolation by the following code which uses Fourier transform.

function y = fshift(x,s)
% FSHIFT Fractional circular shift
%   Syntax:
%
%       >> y = fshift(x,s)
%
%   FSHIFT circularly shifts the elements of vector x by a (possibly
%   non-integer) number of elements s. FSHIFT works by applying a linear
%   phase in the spectrum domain and is equivalent to CIRCSHIFT for integer
%   values of argument s (to machine precision).


needtr = 0; if size(x,1) == 1; x = x(:); needtr = 1; end;
N = size(x,1); 
r = floor(N/2)+1; f = ((1:N)-r)/(N/2); 
p = exp(-j*s*pi*f)'; 
y = ifft(fft(x).*ifftshift(p)); if isreal(x); y = real(y); end;
if needtr; y = y.'; end;

当我将方波整数移位时,代码中没有问题,但是当移位为非整数时,输出会出现明显的波动 即

there is no problem in the code when i shift a square wave by integer shift but when the shift is non-integer the output suffers from significant fluctuations i.e.,

s=[zeros(1,20) ones(1,20) zeros(1,20)];
b=fshift(s,3.5);
stem(b)

如何克服这个问题,还有其他准确的方法吗?

How to overcome this problem and is there any other accurate method?

推荐答案

您可以使用傅立叶移位定理,与您一样,但是增加了滤波.我在此处问了类似的问题.结果看起来错误"的原因是因为您的输入向量不连续.您真正得到的结果是正确的"(或者至少是 true ).

You can do this with the fourier shift theorem as you do, but with added filtering. I asked a similar question here. The reason that the result looks 'wrong' is because your input vector is not continuous. The result you are getting really is 'correct' (or at least true).

您看到的问题称为 Gibbs振铃.您可以使用低通滤波器(维基百科链接很好地解释了该解决方案),其阶跃响应中没有振铃.在有和没有高斯滤波器的情况下尝试代码.这种伪影经常出现在MRI成像(以及许多其他信号处理情况)中,有时可以通过过滤加以缓解.

The problem you are seeing is called Gibbs Ringing. You can make this less extreme by using a low pass filter (this wikipedia link explains the solution pretty well) that has no ringing in its step response. Try your code with and without a gaussian filter. This artefact is often seen in MRI imaging (and many other signal processing situations) and is sometimes alleviated by filtering.

这篇关于在Matlab中通过非整数移位来移动向量的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆