Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!f18g2000prf.googlegroups.com!not-for-mail
From: TideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: DFT
Date: Tue, 3 Nov 2009 13:36:53 -0800 (PST)
Organization: http://groups.google.com
Lines: 33
Message-ID: <26b9039c-8b85-4c0b-b0de-f5050f962223@f18g2000prf.googlegroups.com>
References: <hcq6eq$855$1@fred.mathworks.com>
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257284214 16144 127.0.0.1 (3 Nov 2009 21:36:54 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 3 Nov 2009 21:36:54 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: f18g2000prf.googlegroups.com; posting-host=202.78.152.105; 
	posting-account=qPexFwkAAABOl8VUndE6Jm-9Z5z_fSpR
User-Agent: G2/1.0
X-HTTP-Via: 1.1 bc3
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.4) 
	Gecko/20091016 Firefox/3.5.4,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:582181


On Nov 4, 10:14 am, "Madhumitha Iyer" <pyarsa_ma...@yahoo.co.in>
wrote:
> 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'

Well, the error message says it all really:
"Subscript indices must either be real positive integers or logicals."

In other words, you cannot have zero as an index into a vector as you
have done.
You need to start at 1, not zero.
Then, in your summation you must use n-1 and k-1