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:
help for simple algorithm

Subject: help for simple algorithm

From: kk KKsingh

Date: 19 Feb, 2010 10:17:05

Message: 1 of 4

This is a simple part of problem i posted in another thread !

Suppose i have vector
t=[1 2 3 4 5 8 10 11]

I want to calculate mid point of each vector from formula
n=0:N-1
deltat(n)=t(n+1)-t(n-1)/2...

Now problem is that assuming that n=0:9, When n=0, I will get t(-1) from above formula

As t(-1) = t(N-1)-period and t(9)=t(0)+Period where period=max(t) - min (t) .... since I am talking abt periodic signal. Thus last two mid point wil be calculated by above way....

Now i want to use this in for loop in Multiplication with some DFT kernal..But I dont know how to apply this in loop how to use t(-1) and t(9).....In the end my vector deltat will be made up of 9 vectors

KK

Subject: help for simple algorithm

From: Ravi ch

Date: 25 Feb, 2010 21:23:20

Message: 2 of 4


%%from ur description and wht i understood, this shud work...

deltat=[];
t=[1 2 3 4 5 8 10 11]
period =max(t)-min(t);
t=[t(end)-period t t(1)+period]
for n=2:length(t)-1
deltat(n-1)=(t(n)-t(n-1))/2;
%multiply here
end




"kk KKsingh" <akikumar1983@gmail.com> wrote in message <hllof0$b3q$1@fred.mathworks.com>...
> This is a simple part of problem i posted in another thread !
>
> Suppose i have vector
> t=[1 2 3 4 5 8 10 11]
>
> I want to calculate mid point of each vector from formula
> n=0:N-1
> deltat(n)=t(n+1)-t(n-1)/2...
>
> Now problem is that assuming that n=0:9, When n=0, I will get t(-1) from above formula
>
> As t(-1) = t(N-1)-period and t(9)=t(0)+Period where period=max(t) - min (t) .... since I am talking abt periodic signal. Thus last two mid point wil be calculated by above way....
>
> Now i want to use this in for loop in Multiplication with some DFT kernal..But I dont know how to apply this in loop how to use t(-1) and t(9).....In the end my vector deltat will be made up of 9 vectors
>
> KK

Subject: help for simple algorithm

From: John D'Errico

Date: 25 Feb, 2010 22:44:05

Message: 3 of 4

"kk KKsingh" <akikumar1983@gmail.com> wrote in message <hllof0$b3q$1@fred.mathworks.com>...
> This is a simple part of problem i posted in another thread !
>
> Suppose i have vector
> t=[1 2 3 4 5 8 10 11]
>
> I want to calculate mid point of each vector from formula
> n=0:N-1
> deltat(n)=t(n+1)-t(n-1)/2...
>
> Now problem is that assuming that n=0:9, When n=0, I will get t(-1) from above formula
>
> As t(-1) = t(N-1)-period and t(9)=t(0)+Period where period=max(t) - min (t) .... since I am talking abt periodic signal. Thus last two mid point wil be calculated by above way....
>
> Now i want to use this in for loop in Multiplication with some DFT kernal..But I dont know how to apply this in loop how to use t(-1) and t(9).....In the end my vector deltat will be made up of 9 vectors
>
> KK

t(1:(end-1)) + diff(t)/2

John

Subject: help for simple algorithm

From: Greg Heath

Date: 27 Feb, 2010 00:20:04

Message: 4 of 4

On Feb 19, 5:17 am, "kk KKsingh" <akikumar1...@gmail.com> wrote:
> This is a simple part of problem i posted in another thread !
>
> Suppose i have vector
> t=[1 2 3 4 5 8 10 11]
>
> I want to calculate mid point of each vector from formula
> n=0:N-1
> deltat(n)=t(n+1)-t(n-1)/2...

Incorrect formula. MATLAB does not allow nonpositive
indices

> Now problem is that assuming that n=0:9, When n=0, I will
> get t(-1) from above formula

Again, nonpositive indices are not allowed.

> As t(-1) = t(N-1)-period and t(9)=t(0)+Period where
> period=max(t) - min (t) .... since I am talking abt periodic signal.

There is a basic problem with trying to directly
extend the DFT of a sequence that is assumed to be
a uniformly spaced sample from a periodic function
to the DFT of a sequence that is assumed to be a
nonuniformly spaced sample from a periodic function.

Typically, the seqences x[1:N] and t[1:N] are
specified with the periodic assumption

x[n+N] = x[n], n >= 1

For uniform sampling

t[n] = (n-1)*dt, 1<= n <= N

with the obvious periodic extension

t[n+N] = t[n] + T, T = N*dt

Therefore, the period T is obtained from

T = t[N] - t[1] + dt

T = max(t) - min(t) + dt

Notice that this cannot be directly extended
to nonuniform sampling because dt is not
constant and t[N+1] is not defined.

Therefore, the nonuniformly sampled case must
include additional information so that t[N+1]
or T can be unambiguously determined.

The easiest way is to begin with the full
period sample x[1:M}, t[1:M} with

x[M] = x[1]
t[M] = t[1] + T

When dt is constant, the M = N+1 term DFT
result can be reduced to the familiar N
term result by using the above relationships
between the quantities at [M] and [1].

One alternative is to approximate

dt[N] = t[N+1]-t[N]

as the average of the N-1 differences
dt[n] = t[n+1] - t[n], 1 <= n <= N-1,
i.e.,

dt[N] = (t[N]-t[1])/(N-1)
      = (dt[N-1] + dt[1])/2


Hope this helps.

Greg

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