Kubke Lab:Research/ABR/Notebook/2013/11/05
Hearing development in barn owls | Main project page Previous entry Next entry |
General Entries
Personal EntriesFabianaReading the binary files
Andy says it is an intel file - over skype trying to figure out the structure so we can read it - extracting info from abr.h and abr_4_mac.c According to andy need to Read the first 1128 bytes then read the next 1000 2-byte int skip 52 read next 1000 points, and so on rawData = file("189L0A.ABR", "rb") a <- readBin(rawData,integer(),file.info("189L0A.ABR")$size,size = 2) #size2 says integer is 2 bytes close(rawData) plot(a) plot(a, ylim = c(-500,500)) #at the begining there is 564points that correspond to the header #If I clean up the header plot(a[562:2565], type="line") str(a) b<-seq(1,length(a), 2) c<-seq(2,length(a),2) plot(a[b]) plot(a[c]) aclean<-a[562:2565] head(aclean) head(aclean[b]) head(aclean[c]) plot(aclean[b], xlim=c(0,1000)) plot(aclean[c], xlim=c(0,1000)) Extracting info from log file
<html> <body> <h1>Trying to extract info from the log files</h1> <p>Filename: “419L76.ABR.log”</p> <p>This is what the notepad shows:</p> <p>Owl Date Time Clock_kHz n_reps freq version 419 05/30/93 14:22:22 50 25 5000 5.30 Comment line: Luxman -43 Auxkl B norm 100 valium used Channel 0 data, only</p> <p>delay 0 -160 -100 -180 -140</p> <p>I want to extract [1:7] -> headers [8:14] -> info rest -> comment line tail -> delays</p> <pre><code class="r">logfile <- read.delim2("419L76.ABR.log", sep = "\t", header = T) head(logfile) </code></pre> <pre><code>## Owl
</code></pre> <pre><code class="r">str(logfile) </code></pre> <pre><code>## 'data.frame': 9 obs. of 7 variables:
</code></pre> <p>I get a funny looking table</p> <pre><code class="r">loghead <- read.table("419L76.ABR.log", header = T, sep = "\t", nrows = 1, skip = 0) </code></pre> <p>This gets me the descriptor - still need to get the other rows</p> <pre><code class="r">loghead <- read.table("419L76.ABR.log", header = T, sep = "\t", nrows = 1, skip = 0) loganaesth <- read.table("419L76.ABR.log", sep = "\t", nrows = 1, skip = 2) logtail <- read.table("419L76.ABR.log", sep = "\t", col.names = "Owl", nrows = 20, skip = 3) print(loghead) </code></pre> <pre><code>## Owl Date Time Clock_kHz n_reps freq version
</code></pre> <pre><code class="r">print(loganaesth) </code></pre> <pre><code>## V1 V2
</code></pre> <pre><code class="r">print(logtail) </code></pre> <pre><code>## Owl
</code></pre> <p>Data file 419L76.ABR.txt read.table gives me an error that there is a mismatch betweeen columns and column names - but read.delim2 seems to solve the problem, although it creates a last column x with NAs (which is probably what is generating the problem in hte first place.)</p> <pre><code class="r">data <- read.delim2("419L76.ABR.txt", sep = "\t", header = T) head(data) </code></pre> <pre><code>## msec left right spont bin.0 bin.1 bin.2 bin.3 bin.4 sdev_l sdev_r
</code></pre> <p>returns 5 columns of bin.[0:4] - which probably correspond to the 5 delays in the log file. </p> </body> </html> AndyABR.H header fileFollowing file is from the ABR.H header file that was used for the original files. File layout is probably: <Master_Header><Sub_Structure><1000 2-byte INT><Sub_Structure><1000 2-byte INT> ... This structure needs to be confirmed.
typedef struct { short freq; /* frequency in Hz */ short amp; /* amplitude in D/A units */ short dur; /* duration in clock ticks */ short rise_fall; /* rise_fall in clock ticks */ } SIGNAL; // 8 bytes typedef struct { SIGNAL carrier; SIGNAL envelope; } STIMULUS; typedef struct { short left_delay; /* microseconds to left onset */ short right_delay; /* microseconds to right onset */ short rep_shorterval; /* interval in millseconds */ } TIMING; //6 bytes typedef struct { short clock; /* clock frequency in kHz */ short max_size; /* maximum size of each array */ short channels; /* 1 for carrier only, 2 for carrier & envelope */ } DA_INFO; //6 bytes typedef struct { short clock; /* in kHz */ short size; /* number of elements (per channel) */ short channels; /* number of channels */ short avg_reps; /* number of reps making up the average */ } AD_INFO; //8 bytes typedef struct { char date[12]; char time[12]; char owl_id[12]; char exp_id[12]; char comments[80]; short depth; short version; char side; short num_chan; short num_tests; short gain; char extra_room[1024-(12+12+12+12+80+2+2+1+2+2+2)];/* Add two more to correct CHAR */ // char extra_room[1024-(12+12+12+12+80+2+2+1)];/* Add two more to correct CHAR */ } HEADER_INFO, EXPERIMENT_HEADER; // Bytes 1024 typedef struct /**** THE MASTER STRUCTURE ****/ { HEADER_INFO header; //1024 STIMULUS left; // 16 STIMULUS right; // 16 TIMING delay; // 6 DA_INFO output; // 6 AD_INFO input; // 8 } EXPERIMENT; // 1076 bytes
{ STIMULUS left; // 16 STIMULUS right; // 16 TIMING delay; // 6 DA_INFO output; // 6 AD_INFO input; // 8 } EXPERIMENT_INFO; // 52 bytes Oris
|