码迷,mamicode.com
首页 > 其他好文 > 详细

DSP using MATLAB 示例Example3.8

时间:2016-11-15 08:27:13      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:src   into   amp   error   --   dia   eal   art   bsp   

技术分享

 

技术分享

代码:

x = rand(1,11); n = 0:10;
k = 0:500; w = (pi/500)*k;                 % [0,pi] axis divided into 501 points.
X = x * (exp(-j*pi/500)) .^ (n‘*k);        % DTFT of x

% signal shifted by two samples
y = x; m = n + 2;
Y = y * (exp(-j*pi/500)) .^ (m‘*k);        % DTFT of y = x(n-2)

magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X);
magY = abs(Y); angY = angle(Y); realY = real(Y); imagY = imag(Y);

%verification
Y_check = (exp(-j*2) .^ w) .* X;             % multiplication by exp(-j2w)
error = max(abs(Y-Y_check));                 % Difference

figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘x & y sequence‘)
set(gcf,‘Color‘,‘white‘); 
subplot(2,1,1); stem(n,x); title(‘x sequence‘); xlabel(‘n‘); ylabel(‘x(n)‘); grid on;
subplot(2,1,2); stem(m,y); title(‘y sequence‘); xlabel(‘n‘); ylabel(‘y(n)‘); grid on;

%% --------------------------------------------------------------
%%        START X‘s  mag ang real imag
%% --------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘X its Magnitude and Angle, Real and Imaginary Part‘);
set(gcf,‘Color‘,‘white‘); 
subplot(2,2,1); plot(w/pi,magX); grid on;  % axis([-2,2,0,15]); 
title(‘Magnitude Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude  |X|‘); 
subplot(2,2,3); plot(w/pi, angX/pi); grid on;  % axis([-2,2,-1,1]);
title(‘Angle Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Radians/\pi‘);

subplot(‘2,2,2‘); plot(w/pi, realX); grid on;
title(‘Real Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Real‘);
subplot(‘2,2,4‘); plot(w/pi, imagX); grid on;
title(‘Imaginary Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);
%% --------------------------------------------------------------
%%        END X‘s  mag ang real imag
%% --------------------------------------------------------------

%% --------------------------------------------------------------
%%        START Y‘s  mag ang real imag
%% --------------------------------------------------------------
figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Y its Magnitude and Angle, Real and Imaginary Part‘);
set(gcf,‘Color‘,‘white‘); 
subplot(2,2,1); plot(w/pi,magY); grid on;  % axis([-2,2,0,15]); 
title(‘Magnitude Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Magnitude  |Y|‘); 
subplot(2,2,3); plot(w/pi, angY/pi); grid on;  % axis([-2,2,-1,1]);
title(‘Angle Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Radians/\pi‘);

subplot(‘2,2,2‘); plot(w/pi, realY); grid on;
title(‘Real Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Real‘);
subplot(‘2,2,4‘); plot(w/pi, imagY); grid on;
title(‘Imaginary Part‘);
xlabel(‘frequency in \pi units‘); ylabel(‘Imaginary‘);

%% --------------------------------------------------------------
%%        END Y‘s  mag ang real imag
%% --------------------------------------------------------------

运行结果:

技术分享  

技术分享

技术分享

技术分享

 

DSP using MATLAB 示例Example3.8

标签:src   into   amp   error   --   dia   eal   art   bsp   

原文地址:http://www.cnblogs.com/ky027wh-sx/p/6064251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!