How to write a sigma calculation

5 ビュー (過去 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 Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by