Thread Subject: Efficient weighting

Subject: Efficient weighting

From: Christopher Hummersone

Date: 9 Mar, 2009 14:35:03

Message: 1 of 2

Hi,

I'm trying to weight a signal using an exponential window; the signal is three-dimensional. The code I'm currently using is forming a major bottleneck in my script. So I've narrowed down the line responsible and the two methods I've tried so far to elimiate the bottleneck, shown here in a minimal working example (MWE) as the first line in the for loops (it's not entirely accurate to what I'm doing but is the same in essence):

tau = 480;
t = 160;
MyLength = 33;
MyWidth = 41;
E = zeros(t,MyLength,MyWidth);
E_dash = zeros(t+tau,MyLength,MyWidth);

%% Method 1
expwin = ((1-1/(tau)).^(1:tau))';
expwin = expwin(:,ones(MyLength,1));
E_prev = 0;
tic
for k = 1:t
    E(k,:,:) = E_prev + (1/tau).*sum(bsxfun(@times,expwin,E_dash(k:k+tau-1,:,:)));
    E_prev = E(k,:,:);
end
toc

%% Method 2
expwin = repmat(((1-1/(tau)).^(1:tau))',[1 MyLength MyWidth]); % exponential window function
E_prev = 0;
tic
for k = 1:160
    E(k,:,:) = E_prev + (1/tau).*sum(expwin.*E_dash(k:k+tau-1,:,:));
    E_prev = E(k,:,:);
end
toc

In my script, it takes about 140 secs to run (this is part of a bigger loop), but when I remove the line in question the time drops to 25 secs. I cannot vectorise it any further as it is simply too much data. Anyone any ideas on how I might optimise this?

Cheers,

Chris

Subject: Efficient weighting

From: Christopher Hummersone

Date: 9 Mar, 2009 14:44:02

Message: 2 of 2

oops, perhaps "zeros" should have been "rand" or such like...

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
multidimensiona... Christopher Hummersone 9 Mar, 2009 10:40:20
efficient code Christopher Hummersone 9 Mar, 2009 10:40:20
rssFeed for this Thread

Contact us at files@mathworks.com