phase jumps in dtft

5 views (last 30 days)
Abbas Jafarzadeh
Abbas Jafarzadeh on 18 Jan 2024
Answered: Paul on 18 Jan 2024
hey what causes the phase jumps in angle plot? whats the problem ? its not like that theorically it just happens in matlab
this is the code:
% Plotting the spectrum of a discrete-time rectangular pulse
n=-20:20;
w=-2.5*pi:.01:2.5*pi;
x1=zeros(size(n));
x1(n>=-2 & n<=2)=1;
% x1(19:23)=1;
X=dtft(n,x1,w);
subplot(3,1,1)
stem(n,x1,'linewidth',3);
set(gca,'fontsize',24)
axis([-20 20 0 1.2])
xlabel('n')
ylabel('x[n]')
subplot(3,1,2)
plot(w/pi,abs(X),'linewidth',3);
set(gca,'fontsize',24)
xlabel('\omega (\times\pi rad)')
ylabel('|X(e^{j\omega})|')
subplot(3,1,3)
plot(w/pi,angle(X),'linewidth',1);
set(gca,'fontsize',24)
xlabel('\omega (\times\pi rad)')
ylabel('\angle X(e^{j\omega})')

Answers (1)

Paul
Paul on 18 Jan 2024
n=-20:20;
w=-2.5*pi:.01:2.5*pi;
x1=zeros(size(n));
x1(n>=-2 & n<=2)=1;
% x1(19:23)=1;
Matlab doesn't have a function dtft.
which -all dtft
'dtft' not found.
try
X=dtft(n,x1,w);
catch ME
ME.message
end
ans = 'Undefined function 'dtft' for input arguments of type 'double'.'
Here's one way to generate the DTFT over the frequency range
X = freqz(x1,1,w).*exp(-1j*w*n(1));
Yes, the angle jumps around.
subplot(211);
plot(w,abs(X))
subplot(212);
plot(w,angle(X))
That's because the DTFT as computed by freqz returns very, very, very small imaginary part, presumably due to round off, which causes the phase to be either very close to zero, very close to pi, over very close to -pi
figure
subplot(211),plot(w,real(X))
subplot(212),plot(w,imag(X))

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!