Plotting DTFT of Finite Sum in MATLAB

In summary, to plot the DTFT of a finite sum in MATLAB, you can use the function <code>freqz</code> and then use the <code>plot</code> function to visualize the results. Additionally, you can use the <code>fft</code> function to plot the DTFT, but it is recommended to use the <code>freqz</code> function for a more accurate representation. To specify the frequency range for the plot, you can use the optional <code>w</code> input argument in the <code>freqz</code> function. Labels and a title can be added to the plot using the <code>xlabel</code>, <code>ylabel</code>, and <
  • #1
XcKyle93
37
0

Homework Statement


x[n] = Ʃ ck * δ(n-k), from k = -N to N. Plot the DTFT as a function of the number of terms N. This is a finite sum.


Homework Equations



The equation for the DTFT of a signal, which is Ʃ x[n] * e-j*2∏*∅*n, from n = -∞ to +∞

The Attempt at a Solution


I have nothing... something like
N = 50;
ck = 1;


X = [];
phi = 1/(2*pi);

for n = -1000:1:1000
sum = 0;
for k = -N:1:N
sum = sum + dirac(n-k);
end
X = [X sum*exp(-1i*2*phi*n)];
end


n = -1000:1:1000;
plot(n, X);

But this is obviously wrong. I don't know how to compute the DTFT for a signal of a finite length like that, much less plot it using MATLAB!
 
Physics news on Phys.org
  • #2


Thank you for your forum post. I understand your struggle with computing and plotting the DTFT for a finite sum. However, there are a few things that can help you in this task.

Firstly, it is important to note that the DTFT is a continuous function and can only be plotted using a continuous variable. In your attempt at a solution, you have used a discrete variable for n, which will not accurately represent the DTFT.

To compute the DTFT for a finite sum, you can use the following steps:

1. Define the values of N and ck.
2. Create a vector n that represents the continuous variable for the DTFT.
3. Use the equation for the DTFT to compute X for each value of n.
4. Plot n against X.

In MATLAB, you can use the "stem" function to plot a discrete signal. However, since the DTFT is a continuous function, it is better to use the "plot" function to plot n against X.

I have provided a sample code below, assuming N = 50 and ck = 1. I hope this helps in your understanding and plotting of the DTFT.

N = 50;
ck = 1;
n = -1000:0.1:1000; % use a smaller step size for a smoother plot
X = zeros(size(n));

for k = -N:N
X = X + ck*exp(-1i*2*pi*k*n);
end

plot(n, X);
xlabel('n');
ylabel('DTFT');
title('Plot of DTFT for finite sum');

Best of luck with your homework!
 

1. How do I plot the DTFT of a finite sum in MATLAB?

To plot the DTFT of a finite sum in MATLAB, you can use the function freqz. This function takes in the coefficients of the finite sum as input and returns the magnitude and phase of the DTFT as output. You can then use the plot function to visualize the results.

2. Can I plot the DTFT of a finite sum using the FFT function in MATLAB?

Yes, you can use the fft function in MATLAB to plot the DTFT of a finite sum. However, keep in mind that the fft function returns the discrete Fourier transform (DFT), which is a sampled version of the DTFT. To get a more accurate representation of the DTFT, it is recommended to use the freqz function.

3. How do I specify the frequency range for the DTFT plot in MATLAB?

The freqz function has an optional input argument called w which specifies the frequency range for the plot. You can specify the frequency range in radians by using the syntax w = -pi:pi/1000:pi. Alternatively, you can specify the frequency range in Hz by using the syntax w = -fs/2:fs/1000:fs/2, where fs is the sampling frequency.

4. How can I add labels and a title to the DTFT plot in MATLAB?

You can use the xlabel, ylabel, and title functions to add labels and a title to the DTFT plot. For example, xlabel('Frequency (Hz)') will add a label to the x-axis of the plot.

5. Can I plot multiple DTFTs on the same plot in MATLAB?

Yes, you can plot multiple DTFTs on the same plot by using the hold and plot functions. First, use the hold function to enable the hold on the current figure. Then, use the plot function to plot each DTFT on the same figure. Lastly, use the legend function to add a legend to the plot.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
952
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
819
  • Engineering and Comp Sci Homework Help
Replies
3
Views
805
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
941
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top