Filter löschen
Filter löschen

How to write a sigma calculation

3 Ansichten (letzte 30 Tage)
doyoun Kim
doyoun Kim am 25 Mai 2018
Kommentiert: doyoun Kim am 27 Mai 2018
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?

Akzeptierte Antwort

Abraham Boayue
Abraham Boayue am 26 Mai 2018
Bearbeitet: Abraham Boayue am 26 Mai 2018
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 Kommentare
Abraham Boayue
Abraham Boayue am 26 Mai 2018
Bearbeitet: Abraham Boayue am 26 Mai 2018
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 am 27 Mai 2018
got it

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by