06-22-2009 12:23 PM
I am using visual studio 2005 C#, Measurement Studio 8.6, NI DAQ USB-6008 The problem I'm having is filtering the input ( I'm not sure what to set the sampling frequency at or the lower and upper cutoff or which order ther filter should be.) If I were to build this as a circuit I can use my resistor and capacitor values to get my cutoffs.
Questions:
1) How do I set the filter values?
2) Am I plotting this to the waveform graph properly?
3) My raw voltage in is getting about 10mv of noise?
4) Does this Daq 6008 have enough resolution to get sense a clean signal after filtering?
I acquire the voltage from a pre-amplified pressure sensor .5v = 0mmg and 4v = 300mmg. I then want to filter the signal with a Butterworth Bandpass Filter then Plot the filtered signal.
Here is my code:
//Declare filter
ButterworthBandpassFilter FilterCh3 = new ButterworthBandpassFilter(2,60,.3,10);
//I create the task in a button click event and start it.
TaskPressureSensors = new Task();// string[] device = DaqSystem.Local.Devices;
TaskPressureSensors.AIChannels.CreateVoltageChannel(device[0].ToString() + "/Ai0", "channel0", AITerminalConfiguration.Rse, 1.55, 1.65, AIVoltageUnits.Volts);
TaskPressureSensors.Timing.ConfigureSampleClock("",1000, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);
TaskPressureSensors.Control(TaskAction.Verify);
TaskPressureSensors.Stream.ReadOverwriteMode = ReadOverwriteMode.OverwriteUnreadSamples;
TaskPressureSensors.Stream.ReadRelativeTo = ReadRelativeTo.MostRecentSample;
SensorReader = new AnalogSingleChannelReader(TaskPressureSensors.Stream);
TaskPressureSensors.Control(TaskAction.Start);
//I create a Method and read in raw data and filter it and reference both raw and filtered signals.
private void PressureSensorData(ref double[] psd, ref double[] rdo)
{
pressuresensordata = SensorReader.ReadMultiSample(50);
rdo = pressuresensordata;
cfilterarray = FilterCh3.FilterData(pressuresensordata);
psd = cfilterarray;
}
//This method is to sweep through the waveform graph and detect the peaks.
private void SweepChart12(double value, double RAwValue)
{x1 = ((lastX1 + 1) % Asize);//Asize =800
plotdata1[x1] = value;
plotRaw[x1] = RAwValue;
xyCursor2.XPosition = x1;
waveformGraph2.PlotY(plotRaw);
waveformGraph1.PlotY(plotdata1);
peakdetector1.Reset(.04, 3, PeakPolarity.Peaks);
peakdetector1.Detect(plotdata1, true, out AmplitudesPeak1, out LocationsPeak1, out SecondDervitivesPeak1);
lastX1 = x1;
}
Then in a timer tick event I call the two methods.
PressureSensorData(ref ACOUT, ref DCOUT);
SweepChart12(ACOUT[0], DCOUT[0]);
06-25-2009 04:26 PM
jsheridan,
1) How do I set the filter values?
When you call the ButterworthBandpassFilter constructor, the parameters allow you to set the values of the filter. For example, in your code, this was your call "new ButterworthBandpassFilter(2,60,.3,10);". This means that this is a second order filter, with a sampling frequency of 60, a low frequency cutoff of .3 and a upper frequency cutoff of 10. You can see this information if you put your cursor on the "ButterworthBandpassFilter" constructor and press F1
2) Am I plotting this to the waveform graph properly?
It looks like you are. What does your graph look like?
3) My raw voltage in is getting about 10mv of noise?
The finest accuracy you can get is 37.5 mV on this device (when you have your voltage range set to -1..1V), so 10mV of noise is expected. Unfortunately if you want to reduce this noise, you will need a better data acquisition card.
4) Does this Daq 6008 have enough resolution to get sense a clean signal after filtering?
I'm not sure what you mean. You can filter the signal however you want in software, and that should be independent of the device you are using.
The code looks good. Is it able to run properly or is it not behaving as you expected?
06-29-2009 07:56 AM
06-30-2009 05:26 PM
Unfortunately I don't have a lot of experience with filtering, so I don't know how much I can help you with designing the actual filter for your system, but I can provide you with some information that may be helpful.
First, here is a link to information about the specific Butterworth filter that we are implementing: http://en.wikipedia.org/wiki/Butterworth_filter
You also were wondering what your sampling rate should be. According to Nyquist's theorem , your sampling rate should be at least twice the frequency of your signal, so try something at least twice your frequency and see if you are getting something that you expect. You should try the same thing with your high and low frequency cutoffs. Selecting those are dependant on what you are trying to filter and why you are filtering. What happens when you run that code? Does your signal not look as you expect?