How to write a sigma calculation

7 次查看(过去 30 天)
I'm trying to plot a Dtft,
the question is number 2 in the picture.
This is how I wrote
x=ones(1,9);
N=length(x);
n=-4:N-5;
q=@(omega)exp(-1i.*omega.*n);
wn=linspace(-2,2,9);
plot(wn,real(q(wn)), '-b', wn, imag(q(wn)), '-r');
grid
there is no problems, but the graph isn't pretty.
My thought is to change omega's length somehow or is there a better way?

采纳的回答

Abraham Boayue
Abraham Boayue 2018-5-26
编辑:Abraham Boayue 2018-5-26
In part two of the problem, you will have to use the definition of the DTFT to compute X(omega). The resultant function is just a periodic version of X(jw) from part one of the problem. See the following code below.
%%Part 1
clear variables
close all
N= 200;
T = 2;
t = -2:4/(N-1):2;
x = rectpuls(t,T);
f= -2:4/(N-1):2;
X = T*sin(pi*f*T)./(pi*f*T);
figure
subplot(121)
plot(t,x,'linewidth',2,'color','b')
grid;
a = title('x(t)');
set(a,'fontsize',14);
a = ylabel('x');
set(a,'Fontsize',14);
a = xlabel('t');
set(a,'Fontsize',14);
subplot(122)
plot(f,abs(X)/(max(X)),'linewidth',2,'color','m')
a = title('|X(jw)|');
set(a,'fontsize',14);
a = ylabel('X');
set(a,'Fontsize',14);
a = xlabel('f');
set(a,'Fontsize',14);
grid
%%Part 2
M = 1000;
N = 7;
n = 0:N-1;
xn = ones(1,N);
w = 8*pi;
omega = -w:2*w/(M-1):w;
Xn= exp(-1i.*omega.*(N-1)./2).*(sin(omega*N/2)./sin(omega/2)); %define DTFT function
Mag = abs(Xn)/max(Xn); %compute magnitude
Phase = angle(Xn); %compute phase
figure
subplot(3,1,1)
stem(n,xn,'linewidth',2,'color','b');
a = title('x(n)');
set(a,'fontsize',14);
a = ylabel('xn');
set(a,'Fontsize',14);
a = xlabel('n');
set(a,'Fontsize',14);
grid
subplot(3,1,2)
plot(omega/pi,real(Mag),'linewidth',2,'color','k');
a = title('|X(\omega)|');
set(a,'fontsize',14);
a = ylabel('X');
set(a,'Fontsize',14);
a = xlabel('f');
set(a,'Fontsize',14);
grid
subplot(3,1,3)
plot(omega./pi,Phase,'linewidth',2,'color','k');
a = title('<X(\omega)');
set(a,'fontsize',14);
a = ylabel('X');
set(a,'Fontsize',14);
a = xlabel('f');
set(a,'Fontsize',14);
grid
  3 个评论
Abraham Boayue
Abraham Boayue 2018-5-26
编辑:Abraham Boayue 2018-5-26
fs = 4;
fo = 10;
f = -fo:2*fo/(M-1):fo; % -10<f<10
omega = 2*pi*f/fs;
fn = omega/2*pi; % You can plot the function vs the normalized frequency f/fs % if you wish

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by