First, I was wrong with my speculation that the r-squared formula would be off by a division by "n".
The formula is OK (it's just the squared version of Pearson's product-moment correlation coefficient).
The following regression is also correct.
However, there is an error when calculating the intersection between the regression line with the -60 dB line.
Your code is:
rt = round(abs(60/slope(1))-yintercept);
This works if yintercept is (very close to) zero (as it is in the nice picture above. But in the general case (and in my case), yintercept is a non-negligible negative value and the resulting reverberation time is wrong.
The correct line would be:
rt = -(yintercept + 60)/slope;
As I said, the regression is correct, however it could be written a little more compactly like this:
1) Can you please provide the original formula for the "r-squared" you used?
It seems to be related to the squared "sample Pearson correlation coefficient" but I think it could be off by a division by "n".
I searched in some statistics books and on the web and the problem is there are many different definitions of "r-squared".
2) By default, your function discards the first 50 ms of the result of the "cumulative r-squared". Is this a value you found by experience? In which situations would you suggest different values?
@Kevin: Thanks for your response and for the adaptation of your code!
Just for the records: I was also running Matlab on Linux and I did have problems sending binary zeros.
I didn't try it on other operating systems.
I didn't try other strange characters either, just binary zeros and plain ASCII letters and punctuation.
I had a similar problem when I wanted to send strings which contained binary zeros (\0) as separators.
This didn't work with writeBytes() because the binary zero was interpreted as end-of-string.
Also, when I analyzed the IP traffic with wireshark, I saw that sometimes (strangely not always) an IP packet was sent for every single character of my message-string, which seemed quite inefficient to me.
@Geoffry Akien--I'm not able to duplicate your 2nd error (the one with jtcp_version01), so I'm not sure what to say about that. Your 1st error is really mysterious: a failed jtcp_request_connection() on my machine results in a "connect timed out" error, but the message you get says "Read timed out". I don't know the inner workings of Java well enough to understand why it should be attempting a read operation when you are requesting a connection, so I'm afraid I'm not going to be able to offer you any help here.
I want to use port 502 (I can't change this), but your code formally does not allow the user of ports <1025. I have a device which works just fine using tcpip in the instrument toolbox, but I was hoping to get rid of the dependency by using your code.
Naively changing this limit and using 2012bx64 on W7E I get the following:
>> j = jtcp('REQUEST', '10.10.10.4', 502)
Error using jtcp>jtcp_request_connection (line 293)
Java exception occurred:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
Error in jtcp (line 230)
jTcpObj = jtcp_request_connection(host,port,timeout,serialize);
...but using the same approach with jtcp_version01 seems to work initially:
>> j = jtcp_version01('REQUEST', '10.10.10.4', 502)
socket: [1x1 java.net.Socket]
inputStream: [1x1 java.net.SocketInputStream]
dataInputStream: [1x1 java.io.DataInputStream]
outputStream: [1x1 java.net.SocketOutputStream]
dataOutputStream: [0 java.io.DataOutputStream]
...but then sending something gives this error:
jtcp_version01('WRITE', j, int8(c))
Error using jtcp_version01>jtcp_write (line 384)
Java exception occurred:
java.net.SocketException: Software caused connection abort: socket
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.DataOutputStream.write(Unknown Source)
Error in jtcp_version01 (line 258)
...although closing the connection seems to work without complaint.
Zack, Psychtoolbox already contains a TCP/IP UDP interface, which i use to control neurophysiology amplifiers (has a client / server mode and serialisation of variables etc). We also interface with an eyelink eye tracker, but that has its own network code. The problems you'll have to deal with is synchronisation, how will you ensure accurate timing between psychtoolbox and the eye tracker?
I am currently trying to link up a mac laptop that will be presenting a stimulus in MATLAB (psychtoolbox), to a PC that has eye tracking software (that can be controlled by MATLAB). Is there an easy way to achieve this using jtcp?
I greatly appreciate your help.