Question

Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES: • Explore the DTFT, its meanings and concepts. •...

Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES:

• Explore the DTFT, its meanings and concepts. • Get acquainted with Matlab/Octave

1) Start MATLAB and change the “Current Directory” in the top of the window (or type) >> cd '' (example: >> cd 'C:\NIU\lab2') Alternatively, if you don't want to use MATLAB, you can open a web-browser and go to “octave-online.net”.

2) Download and execute LAB2forStudent_A.M with >> lab2forStudent_A and observe that it produces a Discrete-Time (DT) signal xVec.

3) TO DO: Replace the 1st line “if (0)” with “if (1)”, and add lines to compute the DTFT of the signal xVec at w=π/10 (note: in Matlab/Octave, the word “pi” to represent π; thus, you can use w=pi/10). Store the value of X(exp(jw)) for w=pi/10 it in a variable bigX. TIP: Recall the formula for the DTFT of a signal x[n]: NOTE: it is okay to use a FOR LOOP for this task.

4) Execute the script again and observe the value of the variable bigX.

5) If you don't obtain bigX = 40.000 + i (a very small value); STOP and double check your code.

6) TO DO: Replace the 2nd line “if (0)” with “if (1)”. Surround the code that you used to compute the DTFT with an outer FOR LOOP to compute the DTFT various values of w. (Use wVec defined in the script)

7) Execute the script again. You should see a plot of the absolute values of the DTF

8) QUESTION: Considering that xVec contains the samples of a periodic continuous-time signal x(t) sampled with a sampling frequency of 1,000 samples/second, change the line that plots the DTFT so that the x-axis shows frequency components in Hz.

10) Download and execute the script lab2forStudent_B.m. >> lab2forStudent_B

11) TO DO: Replace the 1st line “if (0)” with “if (1)”, and copy the part of the code of PART-A into the script lab2forStudent_B.m in order to compute the DTFT of the signal xVec of PART-B for various values of w

12) Observe the values of the 1st 10 entries of the vector bitXvec, which stores the computed values of the DTFT. >> bigXvec(1:10)

14) TO DO: To better observe the DTFT, add lines to the script to plot the MAGNITUDE and the PHASE graphs of the DTFT. In Matlab/Octave, the commands abs(aVec) and angle(aVec) respectively give the magnitude and the phase of a complex value (or vector) aVec.

16) Re-open the script lab2forStudent_A.m and change the number of samples as below: nVec=0:45; Save the code and re-execute.

lab2forStudnent_A:

clear all %clears the memory
close all %close all figures

nVec=0:39;
xVec=2*cos(2*pi*nVec*0.05);
figure(1);
stem(nVec,xVec);

if(1)
w=pi/10;
bigX = 0;
%Note that we define nVec=0:39 above. The purpose of this vector
%is to create a vector with the time index of each sample in the signal xVec.
%we will use this vector to compute the DTFT.
%(You could also obtain the time of each sample directly from the looping variable (k). It is a matter of taste. In my opinion keeping a separate vector with the sample indexes or times keep the code more organized.)

%%%%%%%%%%% FOR STUDENT:
%%%%%%%%%%%
%%%%%%%%%%% add lines to compute the DTFT of the signal xVec at w=pi/10
%%%%%%%%%%% NOTE: it is okay to use a FOR LOOP for this task.

  


disp(sprintf('X(exp(jw)) for w=pi/10 is '))
disp(bigX)
end

%compute DTFT
if (0)
%%%%%%%%%%% FOR STUDENT:
%%%%%%%%%%%
%%%%%%%%%%% Copy and change the lines that you used above to compute
%%%%%%%%%%% the DTFT of xVec so that you compute for every w inside wVec below
wVec=[-2.5:0.05:2.5]*pi;
bigXvec = zeros(1,length(wVec)); %this creates a vector to store the DTFT for each value of w

%%% START HERE: build a loop over all the w's inside wVec

figure(2);
fs = 1000;
grid on;
plot(wVec,abs(bigXvec),'ro');
xlabel('normalized angular frequency (radians/second)')
end

lab2forStudent_B:

clear all %clears the memory
close all %close all figures


nVec=0:50;
for j=1:length(nVec)
if nVec(j) < 10
xVec(j) = 1;
else
xVec(j) = 0;
end
end
figure(1);
stem(nVec,xVec);

if (1)
%%%%%%%%%%% FOR STUDENT:
%%%%%%%%%%%
%%%%%%%%%%% copy the part of the code of PART-A that computes the DTFT for
%%%%%%%%%%% several values of w below the definition of wVec.
wVec=[-2.5:0.01:2.5]*pi;


%%%%%%%%%% FOR STUDENT:
%%%%%%%%%% add lines to plot the MAGNITUDE and the PHASE graphs of the DTFT.
%%%%%%%%%% In Matlab/Octave, the commands abs(aVec) and angle(aVec) respectively give the magnitude and the phase of a complex value (or vector) aVec.

end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

nVec=0:39;
xVec=2*cos(2*pi*nVec*0.05);
figure(1);
stem(nVec,xVec);

if(1)
w=pi/10;
bigX = 0;
%Note that we define nVec=0:39 above. The purpose of this vector
bigX=0; %Initialize bigX value to zero
N=length(xVec); %Find the size of xVec
w=pi/10;
for n=1:N
bigX=bigX+xVec(n)*exp(-1j*w*(n-1)); % Compute the DTFT at w=pi/10;
end
  
disp(sprintf('X(exp(jw)) for w=pi/10 is '))
disp(bigX)
end

%compute DTFT
if (1)
wVec=[-2.5:0.05:2.5]*pi;
bigXvec = zeros(1,length(wVec)); %this creates a vector to store the DTFT for each value of w
for n=1:N
bigX=bigX+xVec(n)*exp(-1j*wVec*(n-1)); % Generate DTFT signal
end

figure(2);
fs = 1000;
grid on;
plot(wVec,abs(bigXvec),'ro');
xlabel('normalized angular frequency (radians/second)')
end

Output:

X(exp(jw)) for w=pi/10 is
40.0000 + 0.0000i

Second Program:

clear all %clears the memory
close all %close all figures


nVec=0:50;
for j=1:length(nVec)
if nVec(j) < 10
xVec(j) = 1;
else
xVec(j) = 0;
end
end
figure(1);
stem(nVec,xVec);

if (1)
N=length(xVec); %Find the size of xVec
wVec=[-2.5:0.01:2.5]*pi;
bigXvec = zeros(1,length(wVec)); %this creates a vector to store the DTFT for each value of w
for n=1:N
bigXvec=bigXvec+xVec(n)*exp(-1j*wVec*(n-1)); % Compute the DTFT at w=pi/10;
end

%%%%%%%%%% FOR STUDENT:
%%%%%%%%%% add lines to plot the MAGNITUDE and the PHASE graphs of the DTFT.
%%%%%%%%%% In Matlab/Octave, the commands abs(aVec) and angle(aVec) respectively give the magnitude and the phase of a complex value (or vector) aVec.
figure(2)
plot(wVec,abs(bigXvec),'ro');
figure(3)
plot(wVec,angle(bigXvec),'ro');
end

Output:

Now Change nVec=0.45 in first plot

The outputs are:


Add a comment
Know the answer?
Add Answer to:
Lab #2 Discrete-time Fourier Transform (DTFT) OBJECTIVES: • Explore the DTFT, its meanings and concepts. •...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT