【 MATLAB 】DFT的性质讨论(二)序列的循环移位及其 MATLAB 实现(频域方法)

版权声明:本博客内容来自于个人学习过程中的总结,参考了互联网、数据手册、帮助文档、书本以及论文等上的内容,仅供学习交流使用,如有侵权,请联系,我会重写!转载请注明地址! https://blog.csdn.net/Reborn_Lee/article/details/83513278

上篇博文:【 MATLAB 】DFT的性质讨论(二)序列的循环移位及其 MATLAB 实现(时域方法)

提到了对序列x(n)做循环移位后的DFT形式为:

上篇博文已经讨论过了第一种实现循环移位的方法,通过在时域中对序列移位,之后取模运算,得到循环移位。并给出了精辟地验证。可以很放心的使用。

这篇博文呢?我们就通过序列循环移位后的DFT形式来反推序列的循环移位,并独立给出函数。

这个函数的功能可就强大了。

假设移位量为m:

如果m 是一个标量,那么序列移位后就得到一个移位后的序列,这个序列是一个向量。

如果m是一个向量,向量的每一个元素都是移位量,那么得到的移位后的序列是一个矩阵。

这个矩阵的每一行都是对输入序列的循环移位,而移位值就是m中的相应元素,例如m的第一个元素为4,那么得到的y的第一行就是x循环右移4位得到的序列。

趁热打铁,我编写了一个相关的函数,并给出了验证,几经修改,结果正确,自己都把自己感动哭了。成就感就如当年考研最后一门专业课考完后把自己感动哭了的感觉一样。

知识是用来分享的,我也附出所有代码以及测试:

function y = cirshftf(x,m,N)
% Circular shift m samples in sequence x over[0:N-1](frequency domain)
% ____________________________________________________________________
% y = cirshftf(x,m,N)
% y = output sequence containing circular shift
% x = input sequence of length <= N
% m = sample shift
% N = size of circular buffer
% Method: y(n) = idft(dft(x(n))*WN^(mk))
% 
% If m is a scalar then y is a sequence(row vector)
% If m is a vector then y is a matrix where each row is a circular shift 
% m and x should not be matrices
% 
k = 0:1:N-1;
x = [x,zeros(1,N - length(x))];
m = m(:); %m is a column vector
Nm = length(m);
Xk = dft(x,N);
WNmk = (exp(-j*2*pi/N).^(m*k)) ; %WNmk is a matrix with Nm * N
Xk1 = zeros(Nm,N); %initialization
for i = 1:Nm
    Xk1(i,:) = WNmk(i,:).*Xk;
end
y = zeros(Nm,N); % initialization

for i = 1:Nm
    y(i,:) = idft(Xk1(i,:),N);
end


注意,这个函数里面用到了dft以及idft函数,这些函数我以前的博文都给出了。

见博文:【 MATLAB 】离散傅里叶变换(DFT)以及逆变换(IDFT)的MATLAB实现

这里说一句,我的数字信号处理的MATLAB专栏,不断更新这方面的知识,有兴趣的可以关注下:数字信号处理的MATLAB实现

下面给出验证代码:

clc
clear
close all
 
 
n = 0:10;
x = [5:-1:0,0:4];
m = -5;
N = 11;

subplot(2,1,1);
stem(n,x);
title('original sequence  x(n)');
xlabel('n');

y = cirshftf(x,m,N);
subplot(2,1,2);
stem(n,y);
title('sequence after circular shift for m = -5');
xlabel('n');



如果m是一个向量的话,假设m = [-5,3],就是对序列x(n),分别循环移位-5和3,得到的y的第一行就是循环移位-5后的序列,而第二行就是循环移位3后的序列:

clc
clear
close all
 
 
n = 0:10;
x = [5:-1:0,0:4];
m = [-5,3];
N = 11;

subplot(3,1,1);
stem(n,x);
title('original sequence  x(n)');
xlabel('n');

y = cirshftf(x,m,N);
subplot(3,1,2);
stem(n,y(1,:));
title('sequence after circular shift for m = -5');
xlabel('n');

subplot(3,1,3);
stem(n,y(2,:));
title('sequence after circular shift for m = 3');
xlabel('n');


最后给出序列的频域循环移位性质:

猜你喜欢

转载自blog.csdn.net/Reborn_Lee/article/details/83513278