窗外的知了叽叽喳喳叫个不停,屋里温度应该有30°,伏天的日子难过啊!
频率域的方法来计算圆周移位
代码:
子函数的
function y = cirshftf(x, m, N) %% ----------------------------------------------------------------------- % Circular shift of m samples wrt size N in sequence x: (freq domain) % --------------------------------------------------------------------- % y = cirshftf(x, m, N) % y : output sequence containing the 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, each row is a circular shift % in x corresponding to entries in vector m % M and x should not be matrices if length(x)>N error('N must >= length(x)' ) end x = [x zeros(1, N-length(x))]; k = [0:1:N-1]; WN = exp(-j*2*pi/N); mk = m*k; y = real(idft( dft(x, N) .* ( WN .^ (mk) ), N ));
主函数的
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 5.20 '); banner(); %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % --------------------------------------------------------------------------------- % circular shift % method 1 : cirshftt function, time domain % method 2 : cirshftf function, freq domain % % --------------------------------------------------------------------------------- n = [0:10]; x = [5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4]; % N=11 sequence m1 = -5; N1 = 12; n1 = [0:N1-1]; m2 = 8; N2 = 15; n2 = [0:N2-1]; % ----------------------------------------------------- % 1st way to get circular shift---time domain % ----------------------------------------------------- y1_1 = cirshftt(x, m1, N1); y2_1 = cirshftt(x, m2, N2); % -------------------------------------------------------- % 2rd way to get circular shift --- freq domain % -------------------------------------------------------- y1_2 = cirshftf(x, m1, N1); y2_2 = cirshftf(x, m2, N2); figure('NumberTitle', 'off', 'Name', 'P5.20.a x(n) and its cir shift') set(gcf,'Color','white'); subplot(3,1,1); stem(n, x); xlabel('n'); ylabel('x(n)'); title('x(n), N=11'); grid on; subplot(3,1,2); stem(n1, y1_1); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('n'); ylabel('y(n)'); title('TIME domain circular shift x(n), m=-5, N=12'); grid on; subplot(3,1,3); stem(n1, y1_2); xlabel('n'); ylabel('y(n)'); title('FREQ domain circular shift x(n), m=-5, N=12'); grid on; axis([0, N1, 0, 6]); figure('NumberTitle', 'off', 'Name', 'P5.20.b x(n) and its cir shift') set(gcf,'Color','white'); subplot(3,1,1); stem(n, x); xlabel('n'); ylabel('x(n)'); title('x(n), N=11'); grid on; subplot(3,1,2); stem(n2, y2_1); %axis([-N/2, N/2, -0.5, 50.5]); xlabel('n'); ylabel('y(n)'); title('TIME domain circular shift x(n), m=8, N=15'); grid on; subplot(3,1,3); stem(n2, y2_2); xlabel('n'); ylabel('y(n)'); title('FREQ domain circular shift x(n), m=8, N=15'); grid on; axis([0, N2, 0, 6]);
运行结果: