Email: [email protected]

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Exploring DTFT concept using MATLAB

Exploring DTFT concept using MATLAB

PuTI / 2025-01-18
Exploring DTFT concept using MATLAB
Matlab News

I am trying to understand the concept of DTFT using MATLAB. So I am doing the following experiments:
plot X1[n]=COS(2*pi*201/1024*n) where n=0 to1023
plot X2[n]=rect(N) where N=1024 i.e. X2[n]=1 for n=0 to 1023; else X2[n]=0
plot multiplication of both i.e. X1(n).*X2(n)
plot magnitude plot of Y1(w)=DTFT of { X1(n)*X2(n)} for -pi<w<pi
In figure 7, I expect the peak of sinc function (due to convolution of cosine and rectangular pulse) exactly at the location of the tone freq, but it does not. What may be the issue ???

My code is as below:

clear all; clc; close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nfft = 2^12; % FFT size

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Generate single tone sine wave %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tone_num=Nfft/5;
tone_bin = (2*floor(tone_num/2)+1)+0.5; % prime wrt Nfft
n = [0:Nfft-1];
xsin = cos(2*pi*tone_bin/Nfft*n);

%%%%%%%%%%% Plot single tone sine wave %%%%%%%%%%%%%%%%%
figure(1); plot(n,xsin);

%%%%%%%%%%% Plot DTFT of single tone sine wave %%%%%%%%%
[X1 , W1] = dtft ( xsin , Nfft) ;
figure(2);
plot( W1/2/pi , abs (X1) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Generate rectangular pulse %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nsampl = 200; % number of samples
width=100; % width of the rectangular pulse
sampl_offest=40; % offset from first sampple from where pulse will start
xrect = [zeros(1,sampl_offest) ones(1,width) zeros(1,Nsampl-width-sampl_offest)];

%%%%%%%%%%%%%% PLOT rectangular pulse %%%%%%%%%%%%%%%%%
figure(3);stem(xrect);

%%%%%%%%%%% Plot DTFT of rectangular pulse %%%%%%%%%%%%
[X2 , W2] = dtft ( xrect , Nfft) ;
figure(4);
plot( W2/2/pi , abs (X2) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Generate product of sine & rectangular pulse %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xpdt=xsin(1:Nsampl).*xrect;

%%%%%% Plot product of sine & rectangular pulse %%%%%%%
figure(5); plot(xpdt);

%%% Plot DTFT of product of sine & rectangular pulse %%
[X3 , W3] = dtft ( xpdt , Nfft) ;
figure(6);
plot( W3/2/pi , abs (X3) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )
ylim([-5 max(ylim)+5])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(7);
plot( W3/2/pi , abs (X3) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

k_tone=tone_bin/Nfft; % normalized freq. corresponding to sine tone
xline(k_tone,’:r’,{‘sine tone’}); % plot normalized freq. corresponding to sine tone

wk=1/(Nfft); % freq. bin width

ylim([-5 max(ylim)+5])
xlim([k_tone-30*wk k_tone+30*wk]) % zoom around sine tone freq
%xlim([0 0.5])

%%% generate xticks at every freq. bin w(k) = 2*pi/Nfft %%%%%%%%%%
xwtk=[-0.5 0 0.5];
i=1;
while i*wk < 0.5
xwtk = [xwtk i*wk];
i=i+1;
end
xwtk=sort(xwtk);
xticks(xwtk);
%xline([-k_tone k_tone],’:’,’c’,’sin_tone’);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% END %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% DEFINE FUNCTION dtft subroutine %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H, W] = dtft(h, N)
%DTFT calculate DTFT at N equally spaced frequencies
%—-
% Usage: [H, W] = dtft(h, N)
%
% h : finite-length input vector, whose length is L
% N : number of frequencies for evaluation over [-pi,pi)
% ==> constraint: N >= L
% H : DTFT values (complex)
% W : (2nd output) vector of freqs where DTFT is computed

%—————————————————————
% copyright 1994, by C.S. Burrus, J.H. McClellan, A.V. Oppenheim,
% T.W. Parks, R.W. Schafer, & H.W. Schussler. For use with the book
% "Computer-Based Exercises for Signal Processing Using MATLAB"
% (Prentice-Hall, 1994).
%—————————————————————

N = fix(N);
L = length(h); h = h(:); %<– for vectors ONLY !!!
if( N < L )
error(‘DTFT: # data samples cannot exceed # freq samples’)
end
W = (2*pi/N) * [ 0:(N-1) ]’;
mid = ceil(N/2) + 1;
W(mid:N) = W(mid:N) – 2*pi; % <— move [pi,2pi) to [-pi,0)
W = fftshift(W);
H = fftshift( fft( h, N ) ); %<— move negative freq components
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%I am trying to understand the concept of DTFT using MATLAB. So I am doing the following experiments:
plot X1[n]=COS(2*pi*201/1024*n) where n=0 to1023
plot X2[n]=rect(N) where N=1024 i.e. X2[n]=1 for n=0 to 1023; else X2[n]=0
plot multiplication of both i.e. X1(n).*X2(n)
plot magnitude plot of Y1(w)=DTFT of { X1(n)*X2(n)} for -pi<w<pi
In figure 7, I expect the peak of sinc function (due to convolution of cosine and rectangular pulse) exactly at the location of the tone freq, but it does not. What may be the issue ???

My code is as below:

clear all; clc; close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nfft = 2^12; % FFT size

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Generate single tone sine wave %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tone_num=Nfft/5;
tone_bin = (2*floor(tone_num/2)+1)+0.5; % prime wrt Nfft
n = [0:Nfft-1];
xsin = cos(2*pi*tone_bin/Nfft*n);

%%%%%%%%%%% Plot single tone sine wave %%%%%%%%%%%%%%%%%
figure(1); plot(n,xsin);

%%%%%%%%%%% Plot DTFT of single tone sine wave %%%%%%%%%
[X1 , W1] = dtft ( xsin , Nfft) ;
figure(2);
plot( W1/2/pi , abs (X1) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Generate rectangular pulse %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nsampl = 200; % number of samples
width=100; % width of the rectangular pulse
sampl_offest=40; % offset from first sampple from where pulse will start
xrect = [zeros(1,sampl_offest) ones(1,width) zeros(1,Nsampl-width-sampl_offest)];

%%%%%%%%%%%%%% PLOT rectangular pulse %%%%%%%%%%%%%%%%%
figure(3);stem(xrect);

%%%%%%%%%%% Plot DTFT of rectangular pulse %%%%%%%%%%%%
[X2 , W2] = dtft ( xrect , Nfft) ;
figure(4);
plot( W2/2/pi , abs (X2) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Generate product of sine & rectangular pulse %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xpdt=xsin(1:Nsampl).*xrect;

%%%%%% Plot product of sine & rectangular pulse %%%%%%%
figure(5); plot(xpdt);

%%% Plot DTFT of product of sine & rectangular pulse %%
[X3 , W3] = dtft ( xpdt , Nfft) ;
figure(6);
plot( W3/2/pi , abs (X3) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )
ylim([-5 max(ylim)+5])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(7);
plot( W3/2/pi , abs (X3) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

k_tone=tone_bin/Nfft; % normalized freq. corresponding to sine tone
xline(k_tone,’:r’,{‘sine tone’}); % plot normalized freq. corresponding to sine tone

wk=1/(Nfft); % freq. bin width

ylim([-5 max(ylim)+5])
xlim([k_tone-30*wk k_tone+30*wk]) % zoom around sine tone freq
%xlim([0 0.5])

%%% generate xticks at every freq. bin w(k) = 2*pi/Nfft %%%%%%%%%%
xwtk=[-0.5 0 0.5];
i=1;
while i*wk < 0.5
xwtk = [xwtk i*wk];
i=i+1;
end
xwtk=sort(xwtk);
xticks(xwtk);
%xline([-k_tone k_tone],’:’,’c’,’sin_tone’);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% END %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% DEFINE FUNCTION dtft subroutine %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H, W] = dtft(h, N)
%DTFT calculate DTFT at N equally spaced frequencies
%—-
% Usage: [H, W] = dtft(h, N)
%
% h : finite-length input vector, whose length is L
% N : number of frequencies for evaluation over [-pi,pi)
% ==> constraint: N >= L
% H : DTFT values (complex)
% W : (2nd output) vector of freqs where DTFT is computed

%—————————————————————
% copyright 1994, by C.S. Burrus, J.H. McClellan, A.V. Oppenheim,
% T.W. Parks, R.W. Schafer, & H.W. Schussler. For use with the book
% "Computer-Based Exercises for Signal Processing Using MATLAB"
% (Prentice-Hall, 1994).
%—————————————————————

N = fix(N);
L = length(h); h = h(:); %<– for vectors ONLY !!!
if( N < L )
error(‘DTFT: # data samples cannot exceed # freq samples’)
end
W = (2*pi/N) * [ 0:(N-1) ]’;
mid = ceil(N/2) + 1;
W(mid:N) = W(mid:N) – 2*pi; % <— move [pi,2pi) to [-pi,0)
W = fftshift(W);
H = fftshift( fft( h, N ) ); %<— move negative freq components
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I am trying to understand the concept of DTFT using MATLAB. So I am doing the following experiments:
plot X1[n]=COS(2*pi*201/1024*n) where n=0 to1023
plot X2[n]=rect(N) where N=1024 i.e. X2[n]=1 for n=0 to 1023; else X2[n]=0
plot multiplication of both i.e. X1(n).*X2(n)
plot magnitude plot of Y1(w)=DTFT of { X1(n)*X2(n)} for -pi<w<pi
In figure 7, I expect the peak of sinc function (due to convolution of cosine and rectangular pulse) exactly at the location of the tone freq, but it does not. What may be the issue ???

My code is as below:

clear all; clc; close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nfft = 2^12; % FFT size

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Generate single tone sine wave %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tone_num=Nfft/5;
tone_bin = (2*floor(tone_num/2)+1)+0.5; % prime wrt Nfft
n = [0:Nfft-1];
xsin = cos(2*pi*tone_bin/Nfft*n);

%%%%%%%%%%% Plot single tone sine wave %%%%%%%%%%%%%%%%%
figure(1); plot(n,xsin);

%%%%%%%%%%% Plot DTFT of single tone sine wave %%%%%%%%%
[X1 , W1] = dtft ( xsin , Nfft) ;
figure(2);
plot( W1/2/pi , abs (X1) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Generate rectangular pulse %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nsampl = 200; % number of samples
width=100; % width of the rectangular pulse
sampl_offest=40; % offset from first sampple from where pulse will start
xrect = [zeros(1,sampl_offest) ones(1,width) zeros(1,Nsampl-width-sampl_offest)];

%%%%%%%%%%%%%% PLOT rectangular pulse %%%%%%%%%%%%%%%%%
figure(3);stem(xrect);

%%%%%%%%%%% Plot DTFT of rectangular pulse %%%%%%%%%%%%
[X2 , W2] = dtft ( xrect , Nfft) ;
figure(4);
plot( W2/2/pi , abs (X2) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Generate product of sine & rectangular pulse %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xpdt=xsin(1:Nsampl).*xrect;

%%%%%% Plot product of sine & rectangular pulse %%%%%%%
figure(5); plot(xpdt);

%%% Plot DTFT of product of sine & rectangular pulse %%
[X3 , W3] = dtft ( xpdt , Nfft) ;
figure(6);
plot( W3/2/pi , abs (X3) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )
ylim([-5 max(ylim)+5])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(7);
plot( W3/2/pi , abs (X3) ) ; grid , title( ‘ MAGNITUDE RESPONSE ‘)
xlabel( ‘ NORMALIZED FREQUENCY omega/(2pi)’ ) , ylabel( ‘ I H(omega) I ‘ )

k_tone=tone_bin/Nfft; % normalized freq. corresponding to sine tone
xline(k_tone,’:r’,{‘sine tone’}); % plot normalized freq. corresponding to sine tone

wk=1/(Nfft); % freq. bin width

ylim([-5 max(ylim)+5])
xlim([k_tone-30*wk k_tone+30*wk]) % zoom around sine tone freq
%xlim([0 0.5])

%%% generate xticks at every freq. bin w(k) = 2*pi/Nfft %%%%%%%%%%
xwtk=[-0.5 0 0.5];
i=1;
while i*wk < 0.5
xwtk = [xwtk i*wk];
i=i+1;
end
xwtk=sort(xwtk);
xticks(xwtk);
%xline([-k_tone k_tone],’:’,’c’,’sin_tone’);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% END %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% DEFINE FUNCTION dtft subroutine %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H, W] = dtft(h, N)
%DTFT calculate DTFT at N equally spaced frequencies
%—-
% Usage: [H, W] = dtft(h, N)
%
% h : finite-length input vector, whose length is L
% N : number of frequencies for evaluation over [-pi,pi)
% ==> constraint: N >= L
% H : DTFT values (complex)
% W : (2nd output) vector of freqs where DTFT is computed

%—————————————————————
% copyright 1994, by C.S. Burrus, J.H. McClellan, A.V. Oppenheim,
% T.W. Parks, R.W. Schafer, & H.W. Schussler. For use with the book
% "Computer-Based Exercises for Signal Processing Using MATLAB"
% (Prentice-Hall, 1994).
%—————————————————————

N = fix(N);
L = length(h); h = h(:); %<– for vectors ONLY !!!
if( N < L )
error(‘DTFT: # data samples cannot exceed # freq samples’)
end
W = (2*pi/N) * [ 0:(N-1) ]’;
mid = ceil(N/2) + 1;
W(mid:N) = W(mid:N) – 2*pi; % <— move [pi,2pi) to [-pi,0)
W = fftshift(W);
H = fftshift( fft( h, N ) ); %<— move negative freq components
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% dtft, dft, matlab, fft MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Generate ST code from a look-up table with CONSTANT attribute
2025-05-22

Generate ST code from a look-up table with CONSTANT attribute

“no healthy upstream” error when trying to access My Account
2025-05-22

“no healthy upstream” error when trying to access My Account

MATLAB Answers is provisionally back?
2025-05-21

MATLAB Answers is provisionally back?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: [email protected]
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss