#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    18
    Rep Power
    0

    Unhappy Waveform cross correlation


    Dear friends
    I have plenty of waveforms in a folder that I want to correlate them with "sac_wfcc" command(which I've put in my bin).the problem is that I should corelate any two of the waveforms in this folder but this command correlates just the first waveform(MRD.SPZ.IR.1) with the others.names of my waveforms:

    MRD.SPZ.IR.1 MRD.SPZ.IR.15 MRD.SPZ.IR.20 MRD.SPZ.IR.26 MRD.SPZ.IR.6
    MRD.SPZ.IR.10 MRD.SPZ.IR.16 MRD.SPZ.IR.21 MRD.SPZ.IR.27 MRD.SPZ.IR.7
    MRD.SPZ.IR.11 MRD.SPZ.IR.17 MRD.SPZ.IR.22 MRD.SPZ.IR.28 MRD.SPZ.IR.8
    MRD.SPZ.IR.12 MRD.SPZ.IR.18 MRD.SPZ.IR.23 MRD.SPZ.IR.3 MRD.SPZ.IR.9
    MRD.SPZ.IR.13 MRD.SPZ.IR.19 MRD.SPZ.IR.24 MRD.SPZ.IR.4
    MRD.SPZ.IR.14 MRD.SPZ.IR.2 MRD.SPZ.IR.25 MRD.SPZ.IR.5

    this is what gives cc coefficient and delay time:
    $ saclst a f *Z.IR* | sac_wfcc -D-0.5/1.5/1

    Any Help?or idea?
    p.s:I write in bash.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Not sure what you mean by correlate? And what with what, precisely? By 'any two' do you mean randomly or two selected by the user/you?

    I presume the commands you show end up producing an output on a per-input file basis and you want to compare the outputs of the two specifed files.

    Does the saclst do anything special or does it just list file names from the supplied mask/filter and options?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    18
    Rep Power
    0

    Smile


    waveforms are like signals and sac_wfcc computes the similarity of two waveforms.the output:
    MRD.SPZ.IR.10 63.4398 1.0000
    MRD.SPZ.IR.11 16.5487 0.5350
    MRD.SPZ.IR.12 80.6102 0.5431
    MRD.SPZ.IR.13 68.5435 0.4346
    MRD.SPZ.IR.14 48.0505 0.4855
    MRD.SPZ.IR.15 105.2338 0.4871
    MRD.SPZ.IR.16 71.1340 0.6130
    MRD.SPZ.IR.17 65.3172 0.3128
    MRD.SPZ.IR.18 67.3169 0.4093
    MRD.SPZ.IR.19 67.2312 0.3114
    MRD.SPZ.IR.2 30.7471 0.6094

    1st column:waveform name, 2nd:delay time, 3rd:cc coefficient

    $saclst t1 f *Z.IR* | sac_wfcc -D-0.5/1.5/1
    saclst: lists the header (t1) of the given files(waveforms) and in sac_wfcc uses this header

    I want to execute the command for every two waveforms (pairwisely) and the output should be sth like this:
    waveform1 waveform2 delay time cc

    the process:
    1- correlate 1st waveform withe rest
    2- correlate 2nd waveform with the rest
    .......n- correlate (n)nd waveform with the rest
    How can I write the loop?
    I hope it is more clarified now

    Originally Posted by SimonJM
    Not sure what you mean by correlate? And what with what, precisely? By 'any two' do you mean randomly or two selected by the user/you?

    I presume the commands you show end up producing an output on a per-input file basis and you want to compare the outputs of the two specifed files.

    Does the saclst do anything special or does it just list file names from the supplied mask/filter and options?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Ok, we may be geting there ...
    In essence you have a set of files that are wavefroms.
    For each of these files you wish to 'correlate' some data (produced with the saclst command) with all the other files/waveforms.
    From what I can gather the sac_wfcc command takes an arbitrary list of files to process, thus what you look to need to do is arrange things so that it just gets two filenames. The first of those is obvious - it will be the name of the file in the list that we are currently looking at. The second name will be another name from that list of waveform files (excluding the 'current' one).

    You could have a loop within a loop, each of which would be running listing commands (ls and/or saclst) to provide the inforrmation to pass on to the sac_wfcc command.

    Or you could saclst all the files, redirect that output to a temporary file and parse that file each time - still a bit of overhead but probably less that nested uses of saclst.

    With this method the main issue is avoiding issues with each loop reading from stdin. Don't have *nix available to me at the moment, but might have a bash (pun intended!) a bit later.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Decided that since I had no idea what forms of output the saclst produces, etc. I'd take the easy way out:
    Code:
    #!/bin/bash
    
    for first in $(ls -1 *.IR.*)
    do
      echo "Processing $first"
      for second in $(ls -1 *.IR.* | grep -v "^${first}$")
      do
        echo "  run: saclst t1 f \"$first\" \"$second\" | sac_wfcc -D-0.5/1.5/1"
      done
    done
    No idea if that will do what you want!
    Last edited by SimonJM; November 27th, 2013 at 09:37 AM.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    18
    Rep Power
    0

    Thumbs up


    Dear Simon
    Thanks a lot. Your code was so useful.I just changed the run line to:
    saclst t0 f $first $second | sac_wfcc -D-0.5/1.5/1
    because the command had an error(unable to open) with saclst t1 f \"$first\" \"$second\"

    Thanks for your Help

    Originally Posted by SimonJM
    Decided that since I had no idea what forms of output the saclst produces, etc. I'd take the easy way out:
    Code:
    #!/bin/bash
    
    for first in $(ls -1 *.IR.*)
    do
      echo "Processing $first"
      for second in $(ls -1 *.IR.* | grep -v "^${first}$")
      do
        echo "  run: saclst t1 f \"$first\" \"$second\" | sac_wfcc -D-0.5/1.5/1"
      done
    done
    No idea if that will do what you want!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Glad it was useful - the \"s were for surrounding the file names with quotes (and escaping them was needed as they were imbedded inside quotes that formed the output from the echo.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo