How to write a sigma calculation

조회 수: 19 (최근 30일)
doyoun Kim
doyoun Kim 2018년 5월 25일
댓글: doyoun Kim 2018년 5월 27일
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
doyoun Kim
doyoun Kim 2018년 5월 27일
got it

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by