Forums

how to design LPF given i/p signal its sampling freq, reqiured o/p, in MATLAB

Started by "T.E Ravi" February 16, 2009
Hai everyone,
I have an i/p signal x = 1 +0.5* sin(pi*t) where t = [0:0.01:5], basically a signal sampled at 100 Hz. I need to filter out the d.c. component i.e. get 1 as a constant output so for
which I have to design a low pass filter.
 
can any one tel me how to design low pass filter in MATLAB
 
Thank you
--- In m..., "T.E Ravi" wrote:
>
> Hai everyone,
> I have an i/p signal x = 1 +0.5* sin(pi*t) where t = [0:0.01:5],
basically a signal sampled at 100 Hz. I need to filter out the d.c.
component i.e. get 1 as a constant output so for
> which I have to design a low pass filter.
>  
> can any one tel me how to design low pass filter in MATLAB
>  
> Thank you
>
Here is what I found with a quick Google. At
http://www.physics.uq.edu.au

% Low pass filter with fir1
%
nP; % Order 50 !!
Wn=0.4; % Cut-off at normalized frequency 0.4 (digital frequency
0.4*pi)
b=fir1(n,Wn) % defaults to lowpass filter
[H,q]=freqz(b,1,512); % Note a=[1]
mags(H); % Magnitude response
plot(q,mag,'.');
title(' fir1 filter, orderP, Wn=0.4*pi');
xlabel('Digital Frequency (rad/sample)');
ylabel(' Magnitude Response');

The coefficient vector b then needs to be convolved with the input
vector to get the filtered output.

Regards,

Steve
hai every one,
First of all thanks for all your quick response
 
t=0:0.05:5;X=1+sin(pi*t); plot(t,X)
Since ,the required o/p is 1(in time domain).
I thought if i should get the o/p as 1, the LP filter coefficients had to be designed
in such a way so as to get the reqiured o/p as 1.
i multiplied with x(t) and y(t) with u(t) [step function]
 x(t)=[1+sin(pi*t)]u(t) ; y(t)=u(t)
I took Laplace transform to get Transfer function
to obtain the transfer function in MATLAB
>> H=tf([1 0 pi.*pi],[1 pi pi.*pi])
 
Transfer function:
     s^2 + 9.87
--------------------
s^2 + 3.142 s + 9.87
 
>> [B,A]=tfdata(H,'v')
B     1.0000         0    9.8696

A     1.0000    3.1416    9.8696
>> Y=filter(B,A,X);plot(t,Y)
i didn't get the required o/p which is 1. instead Y is obtained a constant 0 and at the near end of 5 some fluctuations are also seen.
Can anybody give any hint and correct me if i am wrong.
Thanks in advance.

--- On Tue, 17/2/09, stevezsuzska wrote:

From: stevezsuzska
Subject: [matlab] Re: how to design LPF given i/p signal its sampling freq, reqiured o/p, in MATLAB
To: m...
Date: Tuesday, 17 February, 2009, 10:30 AM

--- In matlab@yahoogroups. com, "T.E Ravi" wrote:
>
> Hai everyone,
> I have an i/p signal x = 1 +0.5* sin(pi*t) where t = [0:0.01:5],
basically a signal sampled at 100 Hz. I need to filter out the d.c.
component i.e. get 1 as a constant output so for
> which I have to design a low pass filter.
>  
> can any one tel me how to design low pass filter in MATLAB
>  
> Thank you
>
Here is what I found with a quick Google. At
http://www.physics. uq.edu.au

% Low pass filter with fir1
%
nP; % Order 50 !!
Wn=0.4; % Cut-off at normalized frequency 0.4 (digital frequency
0.4*pi)
b=fir1(n,Wn) % defaults to lowpass filter
[H,q]=freqz( b,1,512); % Note a=[1]
mags(H); % Magnitude response
plot(q,mag,' .');
title(' fir1 filter, orderP, Wn=0.4*pi');
xlabel('Digital Frequency (rad/sample) ');
ylabel(' Magnitude Response');

The coefficient vector b then needs to be convolved with the input
vector to get the filtered output.

Regards,

Steve
If you want to remove DC from your 100hz signal why do you expect the output after filtering to be1?
You can filter out DC component by simply doing:
y = x-mean(x);

i.e. for a signal of length N
y(n) = x(n) - {x(n)+x(n-1)=..x(0)}/N

mean(x) is your dc component, in case you need that.

-Sachin

________________________________
From: T.E Ravi
To: m...
Sent: Tuesday, February 17, 2009 8:53:46 PM
Subject: [matlab] Re: how to design LPF given i/p signal its sampling freq, reqiured o/p, in MATLAB
hai every one,
First of all thanks for all your quick response

t=0:0.05:5;X= 1+sin(pi* t); plot(t,X)
Since ,the required o/p is 1(in time domain).
I thought if i should get the o/p as 1, the LP filter coefficients had to be designed
in such a way so as to get the reqiured o/p as 1.
i multiplied with x(t) and y(t) with u(t) [step function]
x(t)=[1+sin( pi*t)]u(t) ; y(t)=u(t)
I took Laplace transform to get Transfer function
to obtain the transfer function in MATLAB
>> H=tf([1 0 pi.*pi],[1 pi pi.*pi])

Transfer function:
s^2 + 9.87
------------ --------
s^2 + 3.142 s + 9.87

>> [B,A]=tfdata( H,'v')
B 1.0000 0 9.8696

A 1.0000 3.1416 9.8696
>> Y=filter(B,A, X);plot(t, Y)
i didn't get the required o/p which is 1. instead Y is obtained a constant 0 and at the near end of 5 some fluctuations are also seen.
Can anybody give any hint and correct me if i am wrong.
Thanks in advance.

--- On Tue, 17/2/09, stevezsuzska wrote:

From: stevezsuzska
Subject: [matlab] Re: how to design LPF given i/p signal its sampling freq, reqiured o/p, in MATLAB
To: matlab@yahoogroups. com
Date: Tuesday, 17 February, 2009, 10:30 AM

--- In matlab@yahoogroups. com, "T.E Ravi" wrote:
>
> Hai everyone,
> I have an i/p signal x = 1 +0.5* sin(pi*t) where t = [0:0.01:5],
basically a signal sampled at 100 Hz. I need to filter out the d.c.
component i.e. get 1 as a constant output so for
> which I have to design a low pass filter.
>  
> can any one tel me how to design low pass filter in MATLAB
>  
> Thank you
>
Here is what I found with a quick Google. At
http://www.physics. uq.edu.au

% Low pass filter with fir1
%
nP; % Order 50 !!
Wn=0.4; % Cut-off at normalized frequency 0.4 (digital frequency
0.4*pi)
b=fir1(n,Wn) % defaults to lowpass filter
[H,q]=freqz( b,1,512); % Note a=[1]
mags(H); % Magnitude response
plot(q,mag,' .');
title(' fir1 filter, orderP, Wn=0.4*pi');
xlabel('Digital Frequency (rad/sample) ');
ylabel(' Magnitude Response');

The coefficient vector b then needs to be convolved with the input
vector to get the filtered output.

Regards,

Steve