Any programmers, your help is needed!

Discussion in 'General Chat' started by Anex, Apr 15, 2005.

  1. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    I'm working in matlab at the moment (or as usual). It like to batch process things i.e. if I load in a wave file and process it, it likes to process every sample, then write an output. I want it to split the wavefile into blocks of 512 samples, process them, output them, then go back to the beginning and process the next 512 samples and so on.
    Can anyone tell me what that type of processing is called so I can look it up as things aren't going to plan. Or even better are there any matlab users with experience in doing it?
     
    Anex, Apr 15, 2005
    #1
  2. Anex

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    This is called batch processing I think. You can use a Macro do it, but I am not sure how you would go about it. You can buy Macro software but I am not sure if it will do what you want.
     
    amazingtrade, Apr 15, 2005
    #2
  3. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    Batch processing would be to process the whole file at once as it processes all the samples one at a time from a matrix, I want it to operate on discreet time frames.
     
    Anex, Apr 15, 2005
    #3
  4. Anex

    MartinC Trainee tea boy

    Joined:
    Aug 27, 2003
    Messages:
    995
    Likes Received:
    0
    Location:
    Southampton
    I don't use Matlab (..yet - I really ought to learn to use it), but what you're proposing doesn't sound especially complicated, but possibly I'm missing something?

    You presumably read the data section of one of your files into an array right? Then all you need is a loop that does something like:

    1 Set start index of array i=0
    2 Start with array index i and then keep the next 511 points, rejecting the rest
    3 Process this array subset however you want
    4 Check does i = array size - 512? If yes job done if not goto 5
    5 Increment i to i + 1
    6 Goto 2

    I don't suppose there's any fancy name for the above, other than to say it's a "loop".
     
    MartinC, Apr 15, 2005
    #4
  5. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    Ahhh! I didn't put in the 'if i= size x' line, that might work actually, thanks.
    Once that works I need to get rid of the damn loops and vectorize the whole thing. Realtime in Matlab is a recipe for disaster.
     
    Anex, Apr 15, 2005
    #5
  6. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    Hmmm I can't visualize how to structure the loop properly, probably cause I've been staring at it for too long

    Heres what I have:

    close all;
    clear all;
    clc;

    [input1, fs] = wavread('e:\Documents and Settings\User\My Documents\A Docs\Work\Year 3\Final Project\Solo\mogwaiLC');%Wave file input
    h=wavread('e:\Documents and Settings\User\My Documents\A Docs\Work\Year 3\Final Project\Solo\impulse\Left Ear\30LC.wav');%impulse
    lo = 1; ----Start of operating range
    hi = 512; -----End of operating range

    if signal_length >= hi
    work = input1(lo:hi); --------variable with data range in

    % while sqrt((work).^2) > 0; --------commented out stuff to use later
    %out = conv(a,y); --------commented out stuff to use later

    out = out + work; --------move the data from the range variable to the output variable (which should eventually contain the full reconstructed wave file

    lo = lo + 512; --------move lo to the start of the next 512 samples
    hi = hi + 512; --------move hi
    end
    figure
    plot(out);

    % wavwrite(y, fs, 'test.wav');

    This doesn't work, it runs the first 512 points ok but then stops as I can't think what the check should be before going back to the beginning, or even how to get to the beginning of loops without using goto (my programming is bad at best :) ). At the moment all it is meant to do is reconstruct the input matrix 512 samples at a time.
     
    Last edited by a moderator: Apr 15, 2005
    Anex, Apr 15, 2005
    #6
  7. Anex

    Paul Ranson

    Joined:
    Sep 4, 2003
    Messages:
    1,602
    Likes Received:
    0
    Location:
    An octopus's garden.
    I don't understand most of that. Do you not have a manual?

    Code:
    while  hi < signal_length
       work = input1(lo:hi)
       out = out + work
       lo = lo + 512
       hi = hi + 512
    end
    if lo < signal_length
       work = input1(lo:signal_length)
       out = out + work
    end
    It all looks a bit yucky to me.

    Paul
     
    Paul Ranson, Apr 15, 2005
    #7
  8. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    There is a help file but I don't know what you would call what I'm trying to do so I'm struggling to find anything useful.

    Matlab code generally is yucky, it quite often ends up without counter arguments for loops which is where I am now, I could send it back to the beginning by adding a load of unnecessary variables but thats pointless.
    Part of the problem is I am trying to make it work in real time at some point so I'm trying to avoid taking any array lengths as much as possible. All I want the matlab script to know is the 512 data points I tell it exist at that instance. I think. I should have used C.
     
    Anex, Apr 15, 2005
    #8
  9. Anex

    Paul Ranson

    Joined:
    Sep 4, 2003
    Messages:
    1,602
    Likes Received:
    0
    Location:
    An octopus's garden.
    The first line should be 'less than or equal', sorry.

    Paul
     
    Paul Ranson, Apr 16, 2005
    #9
  10. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    I tried putting those in, it still refuses to run the loop, it does the same as my code above (although with less mess, thanks :) ). It will plot the first 512 points in the output, and it increments hi and low right through the full length of the wave file array, but it won't do anything else to the output, I only ever get the first 512 points in 'out'. I'm pretty stumped now
     
    Anex, Apr 16, 2005
    #10
  11. Anex

    Paul Ranson

    Joined:
    Sep 4, 2003
    Messages:
    1,602
    Likes Received:
    0
    Location:
    An octopus's garden.
    What makes you think that 'out = out + work' will extend out rather than adding each member of out to work?

    Paul
     
    Paul Ranson, Apr 16, 2005
    #11
  12. Anex

    Anex Thermionic

    Joined:
    Feb 18, 2005
    Messages:
    1,434
    Likes Received:
    0
    Location:
    London
    Don't quite get you sorry? Why would it add it to work if it is out = ? Or do you mean why would it tag it on the end? Actually I think that may be it, it gives a strange output, it could just be adding the sample points on top of each other so it never gets any longer than 512. Hmmmm, I'll go and take a look at that.
    Thanks for the help with this, its really useful.
     
    Anex, Apr 16, 2005
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.