×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Misterious problem with rewriting for loop into matrix operation

Misterious problem with rewriting for loop into matrix operation

Misterious problem with rewriting for loop into matrix operation

(OP)
Hello!
I'm writing a phase vocoder in MATLAB, with synthesis of sum of sinusoids. As the for loop is very slow in MATLAB, to process a 10 seconds long wav it takes 6 secs with "for" loop, while with a matrix operation it's only 0.3 secs. The problem is that with matrix operation the output is just some noise, the original sound is almost unrecognizable.
The part of the code is the following:
With for loop:

for k=1:step_size
r0 = r0+delta_r;
psi = psi+delta_psi;
res(k) = r0'*cos(psi);
end

with matrix op.:
res=(r0 + (1:step_size)*delta_r).*cos(psi + (1:step_size)*delta_psi);
psi=psi+step_size*delta_psi;

I've tried out the codes, and they seem to give the completely same result, that's why it's misterious why it doesn't work.

The whole .m file is attached, I'd be very pleased if anyone could tell me what the problem is, it'd be quite important.
 

RE: Misterious problem with rewriting for loop into matrix operation

So your r0 and phi0 are column vectors (from the m-file):

 phi0 = zeros(step_size,1);
 r0 = zeros(step_size,1);
 psi = phi0;

and your looped version looks to be incrementing the whole of r0 and the whole of psi in each loop by the same amount.  So every element in r0 is identical, as is every element in psi.  Now you do a mtrix multiply:

 res(k) = r0'*cos(psi);

the value of res(k) will be the summation of step_size identical multiplications.  Equal to

  res(k)=step_size*r0(1)*cos(psi(1))

Looks wrong to me.  It doesn't seem to do anything sensible.





 

- Steve

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now