ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Matlab: Cogent & External Devices Friederike Schüür 18th March 2010.

Slides:



Advertisements
Similar presentations
EE:450 – Computer Networks
Advertisements

1 Application Software Course Simulink By: Mahdi Akbari 2010.
What’s New in Fireware XTM
1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizards Guide to PHP by David Lash.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
So far Binary numbers Logic gates Digital circuits process data using gates – Half and full adder Data storage – Electronic memory – Magnetic memory –
Making the System Operational
XFEL 2D Pixel Clock and Control System Train Builder Meeting, DESY 22 October 2009 Martin Postranecky, Matt Warren, Matthew Wing.
NGS computation services: API's,
Chapter 9 Bootloader.
Yokogawa Network Solutions Presents:
Computer Organization, Bus Structure
Hard Disk Drives Chapter 7.
Mehdi Naghavi Spring 1386 Operating Systems Mehdi Naghavi Spring 1386.
Suite Suite 2 TPF Software – Overview Binary Editor Remote Scripts zTREX Add-Ins & Project Integration with Source Control Manager.
I/O Organization popo.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
1 Operating Systems Input/Output Management. 2 What is the I/O System A collection of devices that different sub- systems of a computer use to communicate.
§4.4 Input and Output Devices
Slide 5-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 5 5 Device Management.
Copyright © Open Text Corporation. All rights reserved. Slide 1 Automatic Routing With Captaris FaxPress and FaxPress Premier Darin McGinnes Sales Engineer.
1 1 Mechanical Design and Production Dept, Faculty of Engineering, Zagazig University, Egypt. Mechanical Design and Production Dept, Faculty of Engineering,
CIMCO Integration Software Products
1 SEDIT & S/REXX SEDIT and S/REXX Mainframe-caliber tools for UNIX Offered by Treehouse Software, Inc.
Spring 2014 RMS/EOC Proctor Caching Training. Agenda 2 Proctor caching overview Downloading & installing Cache test content.
DAQmx下多點(Multi-channels)訊號量測
Button Input: On/off state change Living with the Lab Gerald Recktenwald Portland State University
COMP1214 Systems & Platforms: Operating Systems Concepts Dr. Yvonne Howard – Rikki Prince – 1.
Computer Architecture
INPUT-OUTPUT ORGANIZATION
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Executional Architecture
1 How Do I Order From.decimal? Rev 05/04/09 This instructional training document may be updated at anytime. Please visit and check the.
IBM PC Controlled Keypunch Stan Paddock Computer History Museum January 25, 2008.
School Census Summer 2011 Headlines Version Jim Haywood Product Manager for Statutory Returns.
Network Operations & administration CS 4592 Lecture 15 Instructor: Ibrahim Tariq.
1  1998 Morgan Kaufmann Publishers Interfacing Processors and Peripherals.
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
Chapter 8 Improving the User Interface
Input and Output CS 215 Lecture #20.
Serial I/O - Programmable Communication Interface
MEG Experiments Stimulation and Recording Setup Educational Seminar Institute for Biomagnetism and Biosignalanalysis February 8th, 2005.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Electronics and Networks: Dumb things with Wires Week 2: Serial Overview Jonah Brucker-Cohen Matthew Karau Monday 10am - 12pm Trinity College Dublin MSc.
Serial Communications Standards (Partly Excerpted from Simpl Primer) Cabling Configuration Protocol.
INPUT-OUTPUT ORGANIZATION
INPUT/OUTPUT ARCHITECTURE By Truc Truong. Input Devices Keyboard Keyboard Mouse Mouse Scanner Scanner CD-Rom CD-Rom Game Controller Game Controller.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
Computers in Surveying SVY2301 / E4006 Automated Surveying.
AS Computing F451 F451 Data Transmission. What data is transmitted? Phone SMS Radio TV Internet.
Computer Sensing and Control How is binary related to what we are trying to accomplish in electronics? The PC GadgetMaster II uses binary to communicate.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
MICROPROCESSOR INPUT/OUTPUT
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
Control of (some) External Devices using MatLab/Cogent Steffan Kennett,
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Effective Programming Tips for Cogent Session 10, Christian Kaul MATLAB for Cognitive Neuroscience.
1 October 26, 2006ME 6405 MechatronicsSerial Communication Interface Brian Guerriero Jon Rogers Robert Thiets.
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
Unit 1 Lecture 4.
IT3002 Computer Architecture
1 Chapter Overview Modems The Internet and Web Browsers.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Operating Systems (CS 340 D)
Serial I/O and Data Communication.
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Computer Organization and Design
COMPUTER PERIPHERALS AND INTERFACES
Presentation transcript:

ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Matlab: Cogent & External Devices Friederike Schüür 18th March 2010 Course Material: Cogent Software:

ICN Matlab for Cognitive Neuroscience 2009 /10 – Presenting Stimuli with Cogent Initialising expt. variables start_cogent Run experiment - load premade stimulus files - create new stimuli - trial loop: - present stimuli - get user responses - save data as you go - save final data & close files stop_cogent Configuration of devices Basic script overview: recap In the previous sessions we covered: General structure of cogent scrips Presentation of stimuli Visual Sound Registration of keyboard & mouse events Logging & saving of data Communication with external devices!

ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Todays lecture: Ext. devices Using a button box Synchronization with external devices MRI scanner Check sound or display synchronization Sending triggers to: TMS EEG serial port... parallel port... Configuration of devices + some cogent commands General Usage:

4 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Whats a serial port? A serial port is a serial communication interface. Information transfers in or out one bit at a time. Largely obsolete in modern computers (too bad for us...). Diagrammatic oscilloscope trace of voltage levels for an uppercase ASCII K character with 1 start bit, 8 data bits, and one stop bit (RS-232).

5 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Configuration of the serial port Configuration : config_serial(port, baudrate, parity, stopbits, bytesize) port: - COM port number (1,2,3,4, etc.) baudrate: - (110, 300, 600,..., , ) parity: - (0 = none, 1 = odd, 2 = even, 3 = mark, 4 = space) stopbits: - (0 = 1, 1 = 1.5, 2 = 2) bytesize: - (4 bits, 8 bits) Default setting: config_serial(1, 9600, 0, 0, 8) which is used if config_serial is used without input arguments.

6 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Jargon of the serial port config_serial(port, baudrate, parity, stopbits, bytesize) port: Number of the serial port youre going to use. baudrate: Number of symbols transmitted per second (similar to bit rate). parity: Simple form of error detection in data transmission. E.g. if you choose even parity, then parity bit set to 1 is nr. of 1s is odd in data transmission making number of transmitted 1s even. If nr. of transmitted 1s then odd: error! (mark parity = bit always 1, space parity = bit always 0). stopbits: Allow receiving signal hardware to detect the end of a character. bytesize: Number of bits per byte. Default setting: config_serial(1, 9600, 0, 0, 8) which is used if config_serial is used without input arguments.

ICN Matlab for Cognitive Neuroscience 09 /10: Recording, logging & saving with Cogent readserialbytes(port) reads all bytes arriving at serial port 1 & empties the buffer (clearserialbytes(port)) logserialbytes(port) logs & time stamps all serial bytes that have been read by last readserialbytes. Saved in a logfile if configuered. clearserialbytes(port) empties the buffer for serial port number Serial port: button box

ICN Matlab for Cognitive Neuroscience 09 /10: Recording, logging & saving with Cogent waitserialbyte(port, time, b) waits a time (time in ms) for a serial byte with value b to arrive at serial port number port. Executes readserialbytes and logserialbytes. All serial bytes are logged, and the buffer is emptied. If time time elapsed before b has arrived, then the script continues. Serial port: button box [k t n] = getserialbyte(port) returns values and times of serial bytes read by readserialbytes

9 ICN Matlab for Cognitive Neuroscience 09 /10: Recording, logging & saving with Cogent %Correct %defining variables trial_no = 10; trial_dur = 15000; clearserialbytes(1); %empty buffer for p = 1:trial_no; wait(trial_dur) % allow some time to pass readserialbytes(1); [k t n] = getserialbytes(1); % update & extract bytes keys(p).k = k; keys(p).t = t; end; Example: button box Loop round 10 x 15sec trials, get button presses Depends on specific button box, usually: 0, 1, 2, 4, 6.

10 ICN Matlab for Cognitive Neuroscience 09 /10: Recording, logging & saving with Cogent Incoming pulses generated by the external device can be used for synchronization. The stimulus computer waits until the signal is registered. Commands used for this operation are: clearserialbytes(1) waitserialbytes(1,inf, byte_to_wait_for). Once the byte_to_wait_for has been received, the script continues. Example: Synchronization Ensure that stimulus computer & external device are in synchrony.

11 ICN Matlab for Cognitive Neuroscience 09 /10: Recording, logging & saving with Cogent Depends on serial port (getslice reads serial port) use code available at: [slices, times] = getslice( port ) % returns most recent slice number with time stamps. logslice %transfers scanner slices read by getslice to the log file [s, t] = waitslice( port, n ) %waits forever for MRI slice n or greater, returns actual slice number and time stamp. Example: Synchronization with the FIL MRI scanner.

12 ICN Matlab for Cognitive Neuroscience 09 /10: Recording, logging & saving with Cogent Serial port can also send signals to other devices, e.g. oscilloscopes. For this, you need a special cable (see Cogent user manuals for instructions or ask Martin! ). You can generate a signal using: cgsignal (port, signal) Signal = signal code (0/1/2/3/4 etc.) or sendserialbytes (port, byte) byte needs to be between 0 – 255. Example: Sound or Display Check sound or display synchronization

13 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Whats a parallel port? Interface for connecting peripherals. Transmits particular amounts of bits (e.g. 8) in parallel at the same time. Problems with accessing the parallel port: For security reasons, accessing is parallel port is blocked on most newer computers. However, you can open up the ports by e.g. using Userport which is included in the cogent download. UserPort.sys is a driver that gives access to the I/O Ports. Needs to be installed once on each computer you use.

14 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Essential links For.dll files for parallel port communication: For problems with I/O access:

15 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Configuration of the parallel port Parallel ports usually have decimal addresses: e.g. 888, 632, or 956. Configuration: startportb(port) e.g. starportb(888) Note: startportb might not be necessary, depending on your parallel port access (the one exception for configuration... !) Controlling parallel port input: k = inportb(port) Returns decimal values of bytes arriving at port port. Controlling parallel port output: outportb(port, num). Send the number num to specified port. Num between

16 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Sending triggers to TMS / EEG Use outportb(port,num); wait(t_ms); outportb(port,0); to send a t_ms long pulse. If parallel port of stimulus computer (sending) is connected to an EEG setup (receiving) then num determines the pulse ID in an EEG trace. If particular bits sent by the parallel port send pulses to different external devices, e.g. to trigger data recording or a TMS machine, then num will determine which device receives the trigger. This allows triggering multiple devices from within a Matlab Cogent Script. Check carefully for delays! Problems in the past!

17 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Use outportb(port,num); wait(t_ms); outportb(port,0); num is a number between 0 and 255. Its meaning is clear once its transformed into binary code. e.g. 4 corresponds to 100 send bit 2 with this command, you would send a pulse to the devices connected to bit 2 (note, count from right, the first zero corresponds to bit 0). This way you can send pulses to one or multiple devices at the same time. Sending triggers to TMS / EEG

18 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Use outportb(port,num); wait(t_ms); outportb(port,0); Bit 0 to TMS machine 1 Bit 1 TMS machine 2 Bit 2 trigger DAQ computer Example: paired pulse TMS

19 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices % Trigger TMS 1000ms after stimulus presentation. Start data recording after % 100ms before TMS trigger TMS.dly = 1000; TMS.intl = 2; TMS.pre_rec = 100; % Define times cgdrawsprite(1,0,0,0); % draw stimulus in buffer cgflip(0,0,0); % present stimulus t_present = time; % get time of stimulus presentation waituntil(t_present + TMS.dly - TMS.pre_rec); %wait until start recording outportb(888,4);wait(1);outportn(888,0); %start recording (4 = 100b) Example: paired pulse TMS

20 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices waituntil(t_present + TMS.dly); %wait until first TMS pulse outportb(888,2);wait(1);outportn(888,0); %1st TMS pulse (2 = 10b) waituntil(t_present + TMS.dly + TMS.intvl); %wait until 2nd TMS pulse outportb(888,1);wait(1);outportn(888,0); %2nd TMS pulse ( 1 = 1b) Important: Use waituntil (not wait) otherwise timing inaccuracies. Example: paired pulse TMS

21 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Not with the commands introduced … Use the Matlab Data Acquisition Toolbox. Very flexible use of parallel & serial ports and other interfaces. More advanced communication

22 ICN Matlab for Cognitive Neuroscience 2009 /10 – Matlab: Cogent & External devices Next session: Sam Schwartzkopf about alternatives to Cogent for stimulus presentation: Psychophysics toolbox. Thats it for this time...