multichannelsystems / McsUsbNet_Examples

C#, Python and Matlab code examples to interact with the McsUsbNet.dll
BSD 2-Clause "Simplified" License
7 stars 2 forks source link

setup hardware filtering on MEA2100 using matlab #8

Closed gchassink closed 2 years ago

gchassink commented 2 years ago

Hi this not a bug, but more of question. I am trying to get control over the built in filters of the MEA2100 device. I am not sure which function class to use and what route to take to activate butterworth filtering: CMeaFeedbackFunctionNet Class e.g. FeedbackSetMkFilter() or device.ButterworthFilterHighPassNet (numCoefSets, order, sampleRate, cutoffFrequency, scale)? or filterDevice=CFilterConfigurationNet()?

the CHM documentation does give a lot of hints there. Or maybe I don't understand how to interpret the documentation.

kind regards Gerco

armwal commented 2 years ago

Hi Gerco,

this depends on your use case... There are two hardware filters on the MEA2100, one on the headstage that can be used to filter the acquired electrode data, and one on the IFB that filters the datastream to the DSP. Let me know which one you want to use and we can send you some example code.

Kind regards Armin

gchassink commented 2 years ago

Hi Armin,

Yes good point,

As I understand the headstage hardware filter is analog not? From the manual:

“Hardware Filter Settings While the MEA2100-System in principle can measure DC signals, this is for most purposes very impractical, as the baseline would constantly drift. Therefore, the system is equipped with software configured hardware filters. By default, a second order high pass filter with a cut off frequency of 1 Hz is used to prevent a baseline drift. The upper cut off frequency is 3.3 kHz. It is possible to change the settings of these filters without modification of firmware or hardware. “ @. And the one IFB is a digital one where you can set butterworth, Chebyshef etc? @. Actually we normally modify only the second one, assuming the first one remains what it is if left untouched. But it might be good to have at least a report for the log of the experiment of also the filter setting of the headstage. But recently we got interested in local field potentials and therefore unfiltered signals become more interesting to us as well.

So short answer : We prefer to have at least access to the IFB filter settings but if not too difficult we would also like to have access to the headstage filter.

Gerco

From: armwal @.> Sent: dinsdag 10 mei 2022 14:59 To: multichannelsystems/McsUsbNet_Examples @.> Cc: Hassink, Gerco (UT-TNW) @.>; Author @.> Subject: Re: [multichannelsystems/McsUsbNet_Examples] setup hardware filtering on MEA2100 using matlab (Issue #8)

Hi Gerco,

this depends on your use case... There are two hardware filters on the MEA2100, one on the headstage that can be used to filter the acquired electrode data, and one on the IFB that filters the datastream to the DSP. Let me know which one you want to use and we can send you some example code.

Kind regards Armin

— Reply to this email directly, view it on GitHubhttps://github.com/multichannelsystems/McsUsbNet_Examples/issues/8#issuecomment-1122356623, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AYVFLOJEFTKWK54HMWKUERDVJJMP3ANCNFSM5VOVLDIQ. You are receiving this because you authored the thread.Message ID: @.**@.>>

armwal commented 2 years ago

Hi Gerco,

actually both filters are digital filters and are applied after analog-digital conversion. The DSP only come into play if you are interested in real-time feedback experiments, so I think changing the (digital) filter on the headstage is what you want to do. The recommended way to do this is with our MCS Filter Config Tool: https://www.multichannelsystems.com/software/mcs-filter-config

This tool sets Butterworth low pass filters and Bessel high pass filters for the headstage. Would this be sufficient for you?

Kind regards Armin

gchassink commented 2 years ago

Hi Armin,

Indeed MCS-filter-config works well enough as a basic filtering in combination with our matlabscript, since we can always apply additional filtering offline using matlab functions on the recorded raw signal from the MEA-device. What would be nice then is to have a “getFilterSettings” function to log the current filter settings of the headstage (and maybe also for other filters that might be in the data line) in our recorded data file, to be able to make sure that the right head stage filter settings were used at the time of the experiment. We have e.g. discovered that if we run a MC-rack instance and subsequently close the MC-rack, but do not reboot MEA2100 and run the Matlab script directly after, that parameters like filtersettings and stimulation settings are still in the MEA2100 memory. Since we probably run the different software alternately, depending on our needs, we want to prevent the likelihood of errors like these future, and more importantly, to be able to detect them at least.

Gerco

From: armwal @.> Sent: donderdag 12 mei 2022 11:17 To: multichannelsystems/McsUsbNet_Examples @.> Cc: Hassink, Gerco (UT-TNW) @.>; Author @.> Subject: Re: [multichannelsystems/McsUsbNet_Examples] setup hardware filtering on MEA2100 using matlab (Issue #8)

Hi Gerco,

actually both filters are digital filters and are applied after analog-digital conversion. The DSP only come into play if you are interested in real-time feedback experiments, so I think changing the (digital) filter on the headstage is what you want to do. The recommended way to do this is with our MCS Filter Config Tool: https://www.multichannelsystems.com/software/mcs-filter-config

This tool sets Butterworth low pass filters and Bessel high pass filters for the headstage. Would this be sufficient for you?

Kind regards Armin

— Reply to this email directly, view it on GitHubhttps://github.com/multichannelsystems/McsUsbNet_Examples/issues/8#issuecomment-1124732555, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AYVFLOI3XEM74HH3J5HOQVTVJTEAFANCNFSM5VOVLDIQ. You are receiving this because you authored the thread.Message ID: @.**@.>>

armwal commented 2 years ago

Hi Gerco,

correct, filters are set on the firmware level and typically not reset when a software closes, so they stick around until you reboot the device.

you can use the GetFilterProperties function of the CMcsUsbDacqNet class to retrieve the current filter settings. Typically, you would invoke this from the meaDevice object that you are using for data acquisition:

filters = meaDevice.GetFilterProperties(Mcs.Usb.DacqGroupChannelEnumNet.HeadstageElectrodeGroup);

This returns an array of CFilterPropertyNet objects that describe the headstage filters for the electrode data. You can read out other filters using other entries of the DacqGroupChannelEnumNet enum.

Kind regards, Armin

gchassink commented 2 years ago

Thanks Armin, This works. I can read from 3 filters (1-3) 2 and 3 being the software filters programmable via the MCS filterconfiguration tool and filter 1 seems to be a lowpass hardware filter:

The filters are initially of the Bessel type. However as soon as change the Lowpass cut-off frequency to something else than 3500, it changes to butterworth. If I change it back to 3500 it remains butterworth until I do a clear coefficients. This does not happen to the highpass filter it remains of the Bessel type. I am not sure if it is just the name or also the real filter and if this would have serious consequences (I am not filter expert). But seems a bit strange to me.

Kind regards, Gerco

From: armwal @.> Sent: maandag 16 mei 2022 17:24 To: multichannelsystems/McsUsbNet_Examples @.> Cc: Hassink, Gerco (UT-TNW) @.>; Author @.> Subject: Re: [multichannelsystems/McsUsbNet_Examples] setup hardware filtering on MEA2100 using matlab (Issue #8)

Hi Gerco,

correct, filters are set on the firmware level and typically not reset when a software closes, so they stick around until you reboot the device.

you can use the GetFilterProperties function of the CMcsUsbDacqNet class to retrieve the current filter settings. Typically, you would invoke this from the meaDevice object that you are using for data acquisition:

filters = meaDevice.GetFilterProperties(Mcs.Usb.DacqGroupChannelEnumNet.HeadstageElectrodeGroup);

This returns an array of CFilterPropertyNet objects that describe the headstage filters for the electrode data. You can read out other filters using other entries of the DacqGroupChannelEnumNet enum.

Kind regards, Armin

— Reply to this email directly, view it on GitHubhttps://github.com/multichannelsystems/McsUsbNet_Examples/issues/8#issuecomment-1127811628, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AYVFLOPKHMGC4XWXUDJH243VKJSANANCNFSM5VOVLDIQ. You are receiving this because you authored the thread.Message ID: @.**@.>>

armwal commented 2 years ago

Hi Gerco,

thanks for bringing this up! We've had a closer look at the code of the McsFilterConfig tool because this behaviour doesn't sound correct, and there is indeed a bug in the tool!

Currently, when you set a lowpass filter with the Filter Config tool, it creates filter coefficients for a Bessel filter and writes them to the firmware, but it labels it as a Butterworth filter. So the lowpass filter is always a Bessel filter, but it's got the wrong name and identifies as a Butterworth filter. Fortunately this is only cosmetic, because only the coefficients are relevant for the actual filtering.

Please ignore the "Butterworth" label at the moment when you use the Filter Config tool, this is wrong and we are working on an update for the tool that fixes this in the near future.

Kind regards and thanks! Armin

gchassink commented 2 years ago

Ok that is solved for the timebeing then, thanks till next time

From: armwal @.> Sent: donderdag 19 mei 2022 14:54 To: multichannelsystems/McsUsbNet_Examples @.> Cc: Hassink, Gerco (UT-TNW) @.>; Author @.> Subject: Re: [multichannelsystems/McsUsbNet_Examples] setup hardware filtering on MEA2100 using matlab (Issue #8)

Hi Gerco,

thanks for bringing this up! We've had a closer look at the code of the McsFilterConfig tool because this behaviour doesn't sound correct, and there is indeed a bug in the tool!

Currently, when you set a lowpass filter with the Filter Config tool, it creates filter coefficients for a Bessel filter and writes them to the firmware, but it labels it as a Butterworth filter. So the lowpass filter is always a Bessel filter, but it's got the wrong name and identifies as a Butterworth filter. Fortunately this is only cosmetic, because only the coefficients are relevant for the actual filtering.

Please ignore the "Butterworth" label at the moment when you use the Filter Config tool, this is wrong and we are working on an update for the tool that fixes this in the near future.

Kind regards and thanks! Armin

— Reply to this email directly, view it on GitHubhttps://github.com/multichannelsystems/McsUsbNet_Examples/issues/8#issuecomment-1131653063, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AYVFLOIUID4EZTPOGK7EIB3VKY2X3ANCNFSM5VOVLDIQ. You are receiving this because you authored the thread.Message ID: @.**@.>>