sampling rate and the filter output improvement

15 views (last 30 days)
Hello,
Sampling rate: I am working with acquiring pusle signals using microcontroller and sending them to the matlab with the serial communication.The plot with red in the attached file is the output signal of matlab for 1 second which is received from the microcontroller and the sampling rate used with the microcontroller for this is the 500Hz for this 1sec of pulse signal. I am confused with the sampling rate to be used for the filtering part in matlab.As the signal has been sampled at a rate of 500Hz at the microcontroller so what sampling should be used if a LPfiltering has to be done in the maltb for this 1sec interval pulse signal as when I used 100Hz it showign the signal adn when 500Hz is used there is no pulse signal.
Improving the fitler response: The signal (th red plot) in attached when analysed in the frequency domain is showing the max freq components below 2Hz So,I used a sampling rate of 100Hz with the following LPfilter
d = fdesign.lowpass('Fp,Fst,Ap,Ast',2,2.2,0.5,40,100);
Hd1 = design(d,'butter');
The filter is removing the unwanted frequency components but the filter output is delayed and also it not showing the remaining samples(it missign around 300 samples). Is there a way of overcoming this problem or is there is something changed needed with the filter design.

Accepted Answer

Wayne King
Wayne King on 19 Dec 2013
Edited: Wayne King on 19 Dec 2013
You definitely don't want 1.) -- We've talked about the sampling rate.
This looks like a pretty clean signal actually, what are you trying to accomplish?
d = fdesign.lowpass('Fp,Fst,Ap,Ast',5,10,1,40,500);
Hd = design(d);
% your signal is a in the .mat file
y = filtfilt(Hd.Numerator,1,a);
plot(y)
The above looks pretty good to me.
  2 Comments
Gova ReDDy
Gova ReDDy on 19 Dec 2013
Hi Wayne,can I know how to design the LP FIR filter with the similar characteristics or paramters as the above.
Wayne King
Wayne King on 19 Dec 2013
the above filter is FIR. It is an FIR equiripple filter. Did you mean IIR?

Sign in to comment.

More Answers (7)

kjetil87
kjetil87 on 18 Dec 2013
300 samples sounds about correct from fvtool. Try adding a trail of 300 zeros after your signal. Or get the filering method you use to also output the final conditions of the delays (ie Zf if you use filter)

Wayne King
Wayne King on 18 Dec 2013
I'm not quite understanding your post, but you have to use the sampling frequency in fdesign.lowpass().
If the data is sampled at 500 Hz, then you use 500 Hz in your filter design, not 100 Hz.
If you downsampled your data by a factor of five, then you would use 100 Hz.
  1 Comment
Gova ReDDy
Gova ReDDy on 18 Dec 2013
I mean the signal sampled at 500Hz at microcontroller is being transmitted to matlab through serial communication and in the matlab I want to apply the LPfilter so just want to know what should the sampling freq for this LPfitler in matlab.

Sign in to comment.


Wayne King
Wayne King on 18 Dec 2013
Edited: Wayne King on 18 Dec 2013
If the data is transmitted to MATLAB in digital form without applying additional sampling operators then the sample rate used in the filter must be 500 Hz.
It is exactly the same as if you read a .wav file into MATLAB. If the .wav file is generated using a sampling rate of Fs, then any filter design you do in MATLAB uses the same sampling rate.
  3 Comments
Wayne King
Wayne King on 18 Dec 2013
Do you want to lowpass at 2 Hz, is that your goal?
Gova ReDDy
Gova ReDDy on 18 Dec 2013
Yes and the pulse signal needed to fitler is attached in my first post.

Sign in to comment.


Gova ReDDy
Gova ReDDy on 19 Dec 2013
The sampling rate of 500Hz is not working in the matlab and this is the sampling rate which has been used on the microcontroller.The attached file has data and image here sampling rate shows plots of original,100Hz(red),500Hz(black) with the filter used as
1)sampling rate=100Hz
d = fdesign.lowpass('Fp,Fst,Ap,Ast',2,2.2,0.5,40,100); Hd1 = design(d,'butter');
2)sampling rate=500Hz
d = fdesign.lowpass('Fp,Fst,Ap,Ast',2,2.2,0.5,40,500);Hd1 = design(d,'butter');
Also need some improvements in the filter(butter) design as it is not properly filtering and the filter response is being delayed by some samples .
can some suggest a solution for the above.

Gova ReDDy
Gova ReDDy on 20 Dec 2013
Hi wayne,
It is giving error like this
Error using filtfilt>getCoeffsAndInitialConditions (line 149)
Data must have length more than 3 times filter order.
Error in filtfilt (line 67)
[b,a,zi,nfact,L] = getCoeffsAndInitialConditions(b,a,Npts);
When the frequency Fp=2.4 and Fst=3 are changed as I need to measure the pulse signal lying below 3Hz for my required heartbeat calculations as below is used like this
P=load('Noise_Pulse_signal.mat');
a2=P.a1(1:500,:);
d = fdesign.lowpass('Fp,Fst,Ap,Ast',2.4,3,1,40,500);
Hd1 = design(d);
output = filtfilt(Hd1.Numerator,1,a2);
plot(output,'-r');
Can I know how to solve this problem by designign a better LPfilter(FIR) to allow only the frequency in the signal below <2.4. thanks.

Wayne King
Wayne King on 20 Dec 2013
I'm not sure why you think you need to have such a low cutoff. Based on the data you provided early, 5 Hz seemed to work just fine.
You have to realize you are asking a lot out of a filter -- a stopband frequency only 0.6 Hz higher than the passband frequency --- that is going to be a very long filter - which is why you are getting problems with filtfilt()
You can try an IIR filter to see if that is short enough, but again, I'm not sure why you need to constrain your filter like that.
d = fdesign.lowpass('Fp,Fst,Ap,Ast',2.4,3,1,40,500);
Hd = design(d,'butter');
% just creating some data
x = randn(500,1);
y = filtfilt(Hd.sosMatrix,Hd.ScaleValues,x);
The above will work with only 500 points -- the IIR filter is much shorter.
  1 Comment
Gova ReDDy
Gova ReDDy on 20 Dec 2013
Edited: Gova ReDDy on 20 Dec 2013
Hi wayne,
you said I'm not sure why you think you need to have such a low cutoff. Based on the data you provided early, 5 Hz seemed to work just fine. The answer for this question is that I am designing pulsemeter which counts the hearbeat in the range of 40 to 144 BPM (BPM=f*60) so for the upper limit of hearbeat(BPM) I need to have a cutoff freq=2.4Hz(BPM=2.4*60)=144.
I am planning to use the Recursive least mean square algorithm in the adaptive flteirng algortihtm for the noise removal from the pulse signal.And for this I need FIR LPfilter I guess and I am not sure if a IIR filter can be used for the adpative filtering with RLMS.
Can you explain something about the above. Thanks.

Sign in to comment.


julyrbc bernaola campos
julyrbc bernaola campos on 28 Apr 2014
hello Gova I wanted to ask if you came out the filter in matlab using a microcontroller for I am also trying to do something but I just can not help poodria some doubts .. thanks

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!