Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
determing the DFT & Ploting of its magnitude and phase

Subject: determing the DFT & Ploting of its magnitude and phase

From: BC Tan

Date: 22 Aug, 2009 13:54:02

Message: 1 of 4

Hi All,

I am new to matlab. I had the following 10 point sequence y(n) = { 1, 2, 3, 4, 5, 5, 4, 3, 2, 1].

a) I would like to determine the DFT Y(k) of y(n) and plot (using stem function) its magnitude and phase.

b) i would like to determine the DTFT of y(n) and plot the magnitude and phase. (plus i would like to know how can i properly define the resolution of the DTFT in the frequency domain.

Can anyone advise me or provide me with an example?

Thanks

Subject: determing the DFT & Ploting of its magnitude and phase

From: Sprinceana

Date: 22 Aug, 2009 15:49:03

Message: 2 of 4

For your first question 1 :

"a) I would like to determine the DFT Y(k) of y(n) and plot (using stem function) its magnitude and phase."

FFT is an efficient Algorithm for implementing DFT. So simply use it.

So first time in command window:

>>doc fft
>>help stem
>>help plot

For first step I'll make this in my case your vector with 10 points y=dft_vector (I named dft_vector my variable).


>> dft_vector = [ 1, 2, 3, 4, 5, 5, 4, 3, 2, 1] % your desired vector - input data as y as you named

dft_vector =

     1 2 3 4 5 5 4 3 2 1

>> x=randn(1,n) % generate a random vector with 10 values

x =

   -0.1867 0.7258 -0.5883 2.1832 -0.1364 0.1139 1.0668 0.0593 -0.0956 -0.8323


>> y=x*dft_vector' % dft_vector is a column vector you can only multiply a column vector with a line vector

y =

   11.5416

>> y1=fft(x)

>> stem(dft_vector) % to plot your desired 10 points with stem function

Hope this little idea helps for the moment!

Subject: determing the DFT & Ploting of its magnitude and phase

From: Sprinceana

Date: 22 Aug, 2009 15:55:06

Message: 3 of 4

"BC Tan" <rainzz@live.com> wrote in message <h6ot9q$1gu$1@fred.mathworks.com>...
> Hi All,
>
> I am new to matlab. I had the following 10 point sequence y(n) = { 1, 2, 3, 4, 5, 5, 4, 3, 2, 1].
>
> a) I would like to determine the DFT Y(k) of y(n) and plot (using stem function) its magnitude and phase.
>
> b) i would like to determine the DTFT of y(n) and plot the magnitude and phase. (plus i would like to know how can i properly define the resolution of the DTFT in the frequency domain.
>
> Can anyone advise me or provide me with an example?
>
> Thanks

To plot the magnitude for dft_vector using stem function you have a detailed example here:

http://www.bearcave.com/misl/misl_tech/signal/dftwin/index.html

Also here is a source to compute the dft and plot magnitude for a triangular window. You can adapt the code to your needs.

http://matlabdb.mathematik.uni-stuttgart.de/download.jsp?MC_ID=3&MP_ID=356

Also you cand plot your magnitude and find your phase by looking here:

DFT is defined as X(k)= summation from n=0 to N-1 of E-j*2*pi*k*(n/N)

% program to find N-point DFT of a given function x(n) and also its IDFT

clear all ; % close all

x=input('enter the sequence ');

N=input('Enter the length of the DFT');

xk=fft(x, N); %find DFT

magnitude=abs(xk); %find magnitude

subplot(2,2,1);

n=0:N-1;

stem(n,magnitude); % plot magnitude response.

phaseplot=angle(xk); %find phase angle

subplot(2,2,2);

stem(n,phaseplot); %plot phaseplot

%To find IDFT

xn=ifft(xk); %find IDFT

subplot(2,2,3);
stem(xn); %plot IDFT sequence

I think it's exactly what you need!

Best wishes,

Michael

Subject: determing the DFT & Ploting of its magnitude and phase

From: Sprinceana

Date: 22 Aug, 2009 16:06:01

Message: 4 of 4

If you look carefully on google you'll find exactly the thing you want to achieve for question 1:

http://209.85.129.132/search?q=cache:JixXsHX6n4sJ:gear.kku.ac.th/~nawapak/DSP/DSPLAB_05.doc+plot+magnitude+for+dft&cd=20&hl=ro&ct=clnk&gl=ro

http://www.cmpe.boun.edu.tr/~gurgen/cmpe530/pdft.htm

Hope all this helps for question 1!

Michael

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us