```Dear Jamila,

> Dear Witaya,
> data.
> I'd like to know if you can do the steps that your specified using
> masbar toolbox (SPM)?
> For example, how to apply the band-pass filter? or how to reverse the
> gain of the filter at the middle of the band?
> Jamila
I sorry that I did not work with Marsbar for my band-pass filtering, but
I read the data and saved
in a 4D matrix, and then operated on the matrix.

When you design a filter, you will have the magnitude response (in dB)
of the filter.

Gain = |H(frequency of interest)|

Since

dB = 20 log (Gain)

Gain = 10^(dB/20).

Normally, after filtering, to correct the magnitude of the filtered
signal, we do

Filtered Signal * (1/Gain)

but if you do zero-phase filtering, the magnitude correction will be

Filtered Signal * (1/(Gain^2)).

Below is my previous following answer:

> The voxel value means outside the brain are close to zeros while in
> the brain are not.
> SPM will generate a mask based on that.
>
> You have to be careful about the filter if it is a zero-phase filter
> or not!
> And what is the gain of the filter at the signal of interest or the
> middle of the band?
> The filtered data need to be corrected!  In Matlab, the filter will be
> applied twice
> for the zero-phase filtering, i.e., the filtered signals are filtered
> twice, I think.
> Thus, the the gain correction must be squared!
>
> It seems that you are working in Matlab.  So why don't you do
> everything with a Matlab 4D matrix
> and then export the 4D matrix to a series of 3D img files.
>
> Below is the quote of my answer about how to export the 3D (you can
> modify it for 4D using sprintf)
>
>> Since you work in matlab or can use matlab imread,
>> you can write the data out as below
>>
>> ===========
>>
>> % assume you saved the 3D data matrix, anatdata, in dicom orientation
>> (R --> L, A --> P, I --> S)  ***
>> data_size = [size(anatdata,1) size(anatdata,2) size(anatdata,3)];
>>
>> % write img file
>> file_name_w = 'anatdata.img';% Analyze file name;using sprintf for
>> the 4-D loop
>> fid_w = fopen(file_name_w,'w');
>> I = zeros(data_size(1),data_size(2));
>> for i = 1:data_size(3)
>>   I(:,:) = anatdata(:,:,i);
>>   I2 = fliplr(I);
>>   fwrite(fid_w,I2,'int16');% ? precision: 'double' , 'float32'  (you
>> may need 'int16(round(your_data))')
>> end
>> fclose(fid_w);
>> delete anatdata.mat
>> ==========
>>
>> and then edit/create the hdr with spm99.
>>
>> > I have found a program that will apply a band-pass filter, but the
>> resulting values in the image files are on the order of -10 to 10,
>> which then SPM> will not estimate the model because I believe they
>> are below the default signal threshold of SPM.
>>
>> > Thanks again for the help,
>>

I hope this helps.

Sincerely,

Witaya Sungkarat

>
> On Sep 18, 2008, at 8:10 PM, Witaya Sungkarat wrote:
>
>> Rachel,
>>
>> You may want to:
>>
>> 1) compute the means of the time-series
>> 2) detrend the time-series
>> 3) apply the band-pass filter
>> 4) reverse the gain of the filter at the middle of the band or
>>     at the frequency of interest to the filtered time-series
>> 5) add the means back.
>>
>> Cheers,
>>
>> Witaya Sungkarat
>>
>>> We are working on analyzing our first set of resting state data and
>>> it appears that the consensus is that the data needs to be bandpass
>>> filtered.  We created a filter in matlab using the signal processing
>>> toolbox.  What do we need to do to our preprocessed data before we
>>> apply the filter?
>>>
>>> Any help is appreciated.
>>>
>>> Thanks
>>> Rachel
```