1. 程式人生 > >【 MATLAB 】DFT的性質討論(二)序列的迴圈移位及其 MATLAB 實現(時域方法)

【 MATLAB 】DFT的性質討論(二)序列的迴圈移位及其 MATLAB 實現(時域方法)

如果一個N點序列在任一方向上移位,那麼其結果都不在是位於 0 < = n <= N-1之間。因此,需要進行下面的操作:

為了形象化,可以設想將序列x(n)放在一個圓上,現在將這個圓旋轉k個樣本,並從 0 < = n <= N-1展開這個序列。

它的DFT給出為:

下面給出迴圈移位的函式:

function y = cirshftt(x,m,N)
% Circular shift of m samples in sequence x over 0:N-1(time domain)
% _________________________________________________________________
% y = cirshftt(x,m,N)
% y = output sequence containing the circular shift
% x = input sequence of length <= N
% N = size of circular buffer
% Method: y(n) = x( (n-m) mod N )
% Check for length of x
if length(x) > N 
    error('N must be >= the length of x');
end
x = [x,zeros(1,N-length(x))];
n = [0:1:N-1];
n = mod(n-m,N);
y = x(n+1);

下面給出一個案例,實現迴圈移位:

已知一個11點的序列x(n) = 10(0.8)^n,0 \leq n \leq 10

a.求出並畫出迴圈左移4個樣本後的序列;

b.假設x(n)是一個15點序列(補零),求出迴圈右移3個樣本後的序列。

clc
clear
close all
 
 
n = 0:1:10;
x = 10 * (0.8).^n;
N = 11;
m = -4;
y1 =  cirshftt(x,m,N);

subplot(2,2,1);
stem(n,x);
title('x(n) with n over [0,10]');
xlabel('n');

subplot(2,2,2);
stem(n,y1);
title('circularly left shift for 4');
xlabel('n');




x = [x,zeros(1,4)];
n = 0:1:14;
N = 15;
m = 3;
y2 = cirshftt(x,m,N);

subplot(2,2,3);
stem(n,x);
title('x(n) with n over [0,15] by padding 0');
xlabel('n');

subplot(2,2,4);
stem(n,y2);
title('circularly right shift for 3');
xlabel('n');