Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!p33g2000vbn.googlegroups.com!not-for-mail
From: Greg Heath <heath@alumni.brown.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: DFT
Date: Wed, 4 Nov 2009 19:04:21 -0800 (PST)
Organization: http://groups.google.com
Lines: 63
Message-ID: <245da8f6-770e-4805-8d89-b587cb801764@p33g2000vbn.googlegroups.com>
References: <hcq6eq$855$1@fred.mathworks.com> <hcqbv1$kve$1@fred.mathworks.com> 
	<hcqk3m$622$1@fred.mathworks.com>
NNTP-Posting-Host: 69.141.163.135
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257390261 6350 127.0.0.1 (5 Nov 2009 03:04:21 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 5 Nov 2009 03:04:21 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: p33g2000vbn.googlegroups.com; posting-host=69.141.163.135; 
	posting-account=mUealwkAAACvQrLWvunjg50tRAnsNtJR
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
	2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:582598


On Nov 3, 8:07 pm, "Madhumitha Iyer" <pyarsa_ma...@yahoo.co.in> wrote:
> Thanx the code worked fine with your suggestion.Thank you once again
>
>
>
> "Wayne King" <wmkin...@gmail.com> wrote in message <hcqbv1$kv...@fred.mathworks.com>...
> > "Madhumitha Iyer" <pyarsa_ma...@yahoo.co.in> wrote in message <hcq6eq$85...@fred.mathworks.com>...
> > > x=[zeros(1,10),ones(1,15),zeros(1,10)];    %square wave generator
> > > %The total number of samples are 10+15+10=35
> > > figure(1)
> > > subplot(2,1,1)
> > > plot(x)
> > > N=35;
> > > for k=0:N-1
> > >     for n=0:N-1
> > >         x(k)=sum(x(n)*(exp(-j*2*pi*n*k/N)));
> > >         subplot(2,1,2)
> > > plot(x(k))
> > >     end
> > > end
>
> > > The above code is for finding the DFT coefficients.I am getting the following error while running this program:
>
> > > "Subscript indices must either be real positive integers or logicals."
>
> > > Error in ==> DSPnov3 at 9
> > >         x(k)=sum(x(n)*(exp(-j*2*pi*n*k/N)));
> > > Pls tell me how I can rectify the error.I am writing the code for finding DFTs without using the matlab command 'fft'
>
> > Hi, how about simplifying a bit and removing one of your for loops.
>
> > x=[zeros(1,10),ones(1,15),zeros(1,10)]; %square wave generator
> > %The total number of samples are 10+15+10=35
> > subplot(2,1,1)
> > plot(x)
> > N=35;
> > for k=1:N
> >     freq = (-1i*2*pi*(k-1))/N;
> >     Wnk=exp(freq.*(0:N-1));
> >     X(k)=sum(x.*Wnk);
> > end
> > subplot(2,1,2);
> > plot(abs(X))
>
> > % you can compare the result against fft() to see they match
> > figure;
> > plot(abs(fft(x)));
>
> > Hope that helps,
> > Wayne

The DFT calculation can be simplified further using no loops.
Just matrix multiplication.

Hope this helps.

Greg