discrete time signals

an anonymous user · August 25, 2025
%let's find the DTFT of a rectangular pulse:x[n]=1,1,1,1,1 for n=0,1,2,3,4
% define the discrete time sequence
x[1,1,1,1,1];
n=0:length (x)-1;% time index
%Number of FFT Points (for higher resolution in frequency)
N\FFT=512;% Choose a power of 2 for efficiency, greaterthan (or) equal to length(x)
%compute the DFT (Approximation of DTFT )X\FFT=FFT(X,N\FFT);
%Create the frequency vector (normalisied frequency ,0 to 2^k*pi)
% W=(0:N\FFT-1)^(2*Pi\n\ft);
%(or)0 to fs it using sampling frequency 
w=linspace\0,2,pi,N-FFT;% Angular frequency from 0 to 2Pi
% magnitude and phase
N-FFT=512;% Choose a power of 2 for efficiency,greaterthan(or)equal to length(x)
%compute the DTFT (Approximation of DTFT)
X-FFT=FFT(X,N-FFT);
% Create the frequency vector (Normalisied frequency 0 to 2*Pi)
% w=(0:N-FFT-1)*(2*Pi\n-fft);% or 0 to fs
if using sampling frequency
w=linspace (0,2*pi,n-FFT);% Angular frequency from 0 to 2 Pi
% magnitude and phase 
magnitude -x=abc(x-FFT);% Unwrap to handle phase jumps
%plotting
figure;
subplot(2,1,1);
plot(w,magnitude -x);
title(magnitude spectrum|x(e^{j\omega})\);
x label ('angular frequency(\omega ,rad|sample)');
y label('magnitude');
grid on;
xlim([0 2*Pi]);% Limit to one period
subplot(2,1,2);
plot(w, phase_X);
Title ('phase spectrum\angleX(e^{jomega})');
    xlabel('Angular frequency(\omega,rad/sample)');
    ylabel('phase(radians)');
    grid on;
    xlim ([0 2*Pi]);% limit to one period
Output

Comments

Please sign up or log in to contribute to the discussion.