Denoising Instructions

 

(Updated 09/19/2011)

(Includes sqdDenoise 4.1.1, checkForDeadChannels)

This MATLAB routine is designed to provide a generic tool for denoising MEG160 data. It uses the TSPCA and SNS techniques developed by de Cheveigné and Simon, with user-selectable input parameters. For most users the default parameters should work adequately, however. Details on the two techniques can be found at TSPCA and SNS.


Differences since version 4.0.1:

Better compatibility with low memory computers and older versions of Matlab.

Denoising can also be performed based on 3 additional vibrational reference channels.



Installation Guide

Download and unzip the following in your MATLAB directory


        sqdproject3.0beta.zip

        denoise.zip


You will also need to make sure that the unzipped directories are added to your MATLAB path.

This is most easily done by clicking on MATLAB’s File menu and selecting the Set Path item. Then click the Add Folder button and select the directory:


denoise (located in your MATLAB directory where you unzipped it).


Now do the same for the directory


sqdproject3.0beta (also in your MATLAB directory where you unzipped it)


Then click the Save button. You are now finished installing.



Denoising Guide

Checking for Dead Channels

Before denoising a file, you must first determine whether there are individual channels that are dead or saturating for long periods of time. Running checkForDeadChannels will automatically do this for you and report what channels are dead or saturating, and when.


To run this script, simply type

>> checkForDeadChannels

at the MATLAB command prompt (do not type “>>—that’s the command prompt). You will then be prompted for which file to check.


The function will print to the interface a series of times at which there are dead or saturating channels. Typical output will look like this:

Checking for dead channels in file:

/Users/dbhertz/Documents/Matlab/data/R1277 Pinknoise (7.23.09)/R1277 Pinknoise 7.23.09 Run 2.sqd

Bad channels from 0 to 100 seconds: 55

Bad channels from 100 to 200 seconds: 55

Bad channels from 200 to 300 seconds: 55

Bad channels from 300 to 400 seconds: 55

Bad channels from 400 to 500 seconds: 55

Bad channels from 500 to 600 seconds: 55

Bad channels from 600 to 700 seconds: 55


Note that this will only tell you which channels are effectively dead. It will not tell you whether a channel is excessively noisy (and should therefore be excluded from analysis). It is important to still perform a visual inspection of the data using MEG160 in order to identify noisy channels.


Channels that are identified using checkForDeadChannels should be noted and MUST be included in the list of excluded channels (see below) when running sqdDenoise.


sqdDenoise

This is the function that actually performs the denoising. It can be called with 0, 3, 8 or 9 arguments. For typical users, using 0 arguments should suffice for most situations, but more advanced users may wish to specify more of the parameters of the denoising or who want to include the function in scripts.


0 arguments

Call the function by typing, at the command prompt:

>> sqdDenoise

1. Select the input source file using the pop-up window.

You will be prompted for three other arguments:

Enter the channels to be excluded from analysis (MEG number scheme), e.g. [55 79 125]:

At the prompt enter a list of channels to exclude from the noise reduction and instead set equal to zero for all times because they are dead or too noisy. The format of these channels is that they must be wrapped in square brackets: [a b c d]. The channels are numbered as in MEG160 so that the first channel number is 0. If a channel is dead but not included in this list, sqdDenoise will return an error.


Do you want saturating channel values set to zero? (yes or no):

At the prompt, enter either yes or no. yes means that saturating channels are set equal to zero for times at which they are saturating. no means that they are left at their saturating values. Having them set to zero may result in nicer looking magnetic field maps but at the expense of losing information about the saturation.


Enter the MEG trigger channel to which the presence of a saturating channel is written (e.g. 161):

At the prompt enter the trigger line (160-188) you wish to use to store the times when clipping channels are present. This trigger channel will be set whenever any sensor channel saturated (see above). Do not enter a trigger line that you use for your analysis, as the content of that line will be overwritten.


Do you want to use vibrational reference channels? (yes or no):

At the prompt enter either 'yes' or 'no' (without quotation marks). 'yes' indicates that vibrational reference sensors will be used for denoising purposes. 'no' indicates that they will not. For data taken at UMD since October 1 2010 it is recommended that users select 'yes'. For data taken elsewhere or prior to that date you MUST use 'no'.


The output file will be located in the same directory as the input file and will have the same name with the suffix ‘-Filtered’ appended.


3 arguments

If 3 input arguments are specified, they must be (in order):

sizeOfBlocks: size of the block which will be processed at a time. If 0 arguments are  specified, this argument defaults to 50,000, corresponding to 50s for 1kHz sample frequency.

shifts: the range of shifts by which the TSPCA time shift regression is allowed to move. If 0 arguments are specified this defaults to -50:50.

nearNeighbors: the number of nearest neighbors used for SNS filtering. If 0 arguments are specified this defaults to 10. If nearNeighbors is set equal to zero, sqdDenoise will not use SNS denoising.


The output file will be located in the same directory as the input file and will have the same name with the suffix ‘-Filtered’ appended.


An example of the syntax for use with 3 arguments is:

>> sqdDenoise(100000, -100:100, 8)

In this case the block size and time shifts used by TSPCA is be 10,000 and the range -100 to +100, respectively, and the number of near neighbors used by SNS is 8.



8 arguments

If 8 arguments are specified, they must be (in order):

sizeOfBlocks: see above

shifts: see above

nearNeighbors: see above

sourceFile: the complete path and filename of the input file.

excludedChannels: In the format [a b c d] this is a list of channels to exclude from noise reduction and which are set to zero. The numbering of channels follows the MEG160 convention (starting at 0). If a channel is dead and is not included in this list, sqdDenoise will return an error.

doWeZeroSaturatedChannels: This argument must be either 'yes' or 'no' (including quotation marks).  'yes' means that saturating channels are set equal to zero for times at which they are saturating. 'no' means that they are left at their saturating values.

channelForSaturatingChannels : This is the trigger line (160-188) you wish to use to store the times when clipping  channels are present. Do not enter a trigger line which you use for your analysis, as the content of that trigger line will be overwritten.

doWeUseVibrationalChannels: This argument must be either 'yes' or 'no'  (including quotation marks). 'yes' means that vibrational sensor channels will be used for denoising. 'no' means that they will not. For data taken at UMD since October 1  2010 it is advised that users use 'yes'. For data taken elsewhere or prior to this date you MUST use 'no'.


The output file will be located in the same directory as the input file and will have the same name with the suffix ‘-Filtered’ appended.


An example of the syntax for use with 8 arguments is:

>> sqdDenoise(25000,-50:50,10,'~/Documents/Matlab/test.sqd',[55], 'yes',160,'yes')


9 arguments

This allows the user to specify all parameters, including the path and name of the output file. This file name must end with ‘.sqd’.

If 9 arguments are specified, they must be (in order):

sizeOfBlocks: see above (under 3 arguments)

shifts: see above (under 3 arguments)

nearNeighbors: see above (under 3 arguments)

sourceFile: see above (under 8 arguments)

excludedChannels: see above (under 8 arguments)

setSaturatedChannelsToZero: see above (under 8 arguments)

channelForSaturatingChannels: see above (under 8 arguments)

doWeUseVibrationalChannels: see above (under 8 arguments)

outputFile: The complete path and filename of the output file.


An example of the syntax for 9 arguments is:

>> sqdDenoise(25000, -50:50, 10, '~/Documents/Matlab/test.sqd', [55],'yes',160,'yes','~/Documents/Matlab/test_output.sqd')


Notes

In general, using a smaller range of TSPCA shifts will make the denoising less aggressive. A larger range will make the denoising sensitive to overfitting (removing some signal instead of only noise). It is advisable to use symmetric ranges of shifts (e.g. -25:25, -30:30, etc.) although this is not a requirement.


The output of the function contains a list of parameters used and the time taken to run the routine.


Runtime will vary with your processor speed, but on a Mac Pro 2x2.8 Xeon, it takes approx. 7 minutes to process a 700 MB file.


Questions, Feedback, etc.

Any questions or issues regarding the use of this package should be directed to Jonathan Simon.