<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265257</link>
    <title>MATLAB Central Newsreader - Low pass filtering</title>
    <description>Feed for thread: Low pass filtering</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 07 Nov 2009 20:08:02 -0500</pubDate>
      <title>Low pass filtering</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265257#692926</link>
      <author>Dias Papas</author>
      <description>I am new in signal processing and I want to filter some time series.&lt;br&gt;
I searched and I found the below code.&lt;br&gt;
It seems to work but I am not sure if it works properly.&lt;br&gt;
And I have two questions.&lt;br&gt;
&lt;br&gt;
First: Why the first values of the output 'y' are close to 0? Is it correct? Wouldn't be more logic to be close to the input data 'x'?&lt;br&gt;
&lt;br&gt;
And the second one: How can I plot the input data 'X' in the frequency domain with values of Hz, so I will see the frequencies of 'X' and  easily decide the cut off frecuency.&lt;br&gt;
&lt;br&gt;
If I am in completely wrong thought, please tell me.&lt;br&gt;
&lt;br&gt;
The code:&lt;br&gt;
&lt;br&gt;
fs = 300;&lt;br&gt;
n = 0:1/fs:0.2;&lt;br&gt;
x = cos(2*pi*30*n) + cos(2*pi*50*n) + sin(2*pi*60*n);&lt;br&gt;
wc = pi*40 / (fs/2);&lt;br&gt;
N = 21;&lt;br&gt;
n = 0:1:N-1;&lt;br&gt;
hd = ideal_lp(wc,N);&lt;br&gt;
w_tet = (boxcar(N))';&lt;br&gt;
h = hd.*w_tet;&lt;br&gt;
y = filter(h,1,x);&lt;br&gt;
&lt;br&gt;
fr = 0:0.01:pi;&lt;br&gt;
X = freqz(x,1,fr);&lt;br&gt;
H = freqz(h,1,fr);&lt;br&gt;
Y = freqz(y,1,fr);&lt;br&gt;
&lt;br&gt;
figure (1)&lt;br&gt;
subplot(311)&lt;br&gt;
plot(fr,abs(X)); axis([0 3.5 0 40])&lt;br&gt;
subplot(312)&lt;br&gt;
plot(fr,abs(H)); axis([0 3.5 0 2])&lt;br&gt;
subplot(313)&lt;br&gt;
plot(fr,abs(Y)); axis([0 3.5 0 40])&lt;br&gt;
&lt;br&gt;
figure (2)&lt;br&gt;
subplot(311)&lt;br&gt;
plot(x)&lt;br&gt;
subplot(312)&lt;br&gt;
plot(h)&lt;br&gt;
subplot(313)&lt;br&gt;
plot(y)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thanks veeeery much&lt;br&gt;
Dias</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 21:25:02 -0500</pubDate>
      <title>Re: Low pass filtering</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265257#692932</link>
      <author>Wayne King</author>
      <description>&quot;Dias Papas&quot; &amp;lt;dias_papas@mathworks.com&amp;gt; wrote in message &amp;lt;hd4k31$7b7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I am new in signal processing and I want to filter some time series.&lt;br&gt;
&amp;gt; I searched and I found the below code.&lt;br&gt;
&amp;gt; It seems to work but I am not sure if it works properly.&lt;br&gt;
&amp;gt; And I have two questions.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; First: Why the first values of the output 'y' are close to 0? Is it correct? Wouldn't be more logic to be close to the input data 'x'?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And the second one: How can I plot the input data 'X' in the frequency domain with values of Hz, so I will see the frequencies of 'X' and  easily decide the cut off frecuency.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If I am in completely wrong thought, please tell me.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The code:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fs = 300;&lt;br&gt;
&amp;gt; n = 0:1/fs:0.2;&lt;br&gt;
&amp;gt; x = cos(2*pi*30*n) + cos(2*pi*50*n) + sin(2*pi*60*n);&lt;br&gt;
&amp;gt; wc = pi*40 / (fs/2);&lt;br&gt;
&amp;gt; N = 21;&lt;br&gt;
&amp;gt; n = 0:1:N-1;&lt;br&gt;
&amp;gt; hd = ideal_lp(wc,N);&lt;br&gt;
&amp;gt; w_tet = (boxcar(N))';&lt;br&gt;
&amp;gt; h = hd.*w_tet;&lt;br&gt;
&amp;gt; y = filter(h,1,x);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fr = 0:0.01:pi;&lt;br&gt;
&amp;gt; X = freqz(x,1,fr);&lt;br&gt;
&amp;gt; H = freqz(h,1,fr);&lt;br&gt;
&amp;gt; Y = freqz(y,1,fr);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figure (1)&lt;br&gt;
&amp;gt; subplot(311)&lt;br&gt;
&amp;gt; plot(fr,abs(X)); axis([0 3.5 0 40])&lt;br&gt;
&amp;gt; subplot(312)&lt;br&gt;
&amp;gt; plot(fr,abs(H)); axis([0 3.5 0 2])&lt;br&gt;
&amp;gt; subplot(313)&lt;br&gt;
&amp;gt; plot(fr,abs(Y)); axis([0 3.5 0 40])&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figure (2)&lt;br&gt;
&amp;gt; subplot(311)&lt;br&gt;
&amp;gt; plot(x)&lt;br&gt;
&amp;gt; subplot(312)&lt;br&gt;
&amp;gt; plot(h)&lt;br&gt;
&amp;gt; subplot(313)&lt;br&gt;
&amp;gt; plot(y)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks veeeery much&lt;br&gt;
&amp;gt; Dias&lt;br&gt;
&lt;br&gt;
Hi Dias, are you using R2009a or R2009b? If so and you have the Signal Processing Toolbox, how about using fdesign.lowpass? Using your signal, but lengthening it a bit (61 points is a pretty short signal).&lt;br&gt;
&lt;br&gt;
n = 0:1/fs:1;&lt;br&gt;
x = cos(2*pi*30*n) + cos(2*pi*50*n) + sin(2*pi*60*n);&lt;br&gt;
H = fdesign.lowpass('Fp,Fst,Ap,Ast',40,45,1,60,300); %passband 40 Hz,stop at 45&lt;br&gt;
% 1 dB passband ripple, 60 dB stopband attenuation, 300 Hz sampling frequency&lt;br&gt;
D = design(H,'equiripple'); % design filter--equiripple FIR design&lt;br&gt;
fvtool(D) %look at filter magnitude response&lt;br&gt;
y = filter(D,x); % Filter input signal&lt;br&gt;
&lt;br&gt;
If you look at the help for fdesign.lowpass you will see there are a number of specification strings you can use. A number of them let you specify the filter order. If you want to use the window method for example, you can specify:&lt;br&gt;
&lt;br&gt;
H = fdesign.lowpass('N,Fc',50,40,300); %filter order of 50, cutoff of 40 Hz, Fs=300&lt;br&gt;
designmethods(H) % designmethods() tell you what the valid design methods are&lt;br&gt;
% returns window in this case&lt;br&gt;
D = design(H,'window'); %window not necessary here--it's the only method&lt;br&gt;
y = filter(D,x); % filter input signal&lt;br&gt;
&lt;br&gt;
In terms of plotting the output iin the frequency domain, can I recommend you read the documentation on fft() and freqz()? If you want to plot the frequency response of your filter, calling freqz() with no output arguments and the proper sampling frequency will produce a plot for you. Alternatively, use two output arguments and plot the absolute value, absolute value squared, or the logarithm of the former as a function of the frequency vector.&lt;br&gt;
&lt;br&gt;
To look at the result of filtering your signal, I think you should spend some time reading the documentation for fft(), and or psd(). There a number of worked examples in the Matlab doc.&lt;br&gt;
&lt;br&gt;
Hope that helps,&lt;br&gt;
Wayne</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 23:56:02 -0500</pubDate>
      <title>Re: Low pass filtering</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265257#692941</link>
      <author>Dias Papas</author>
      <description>&quot;Wayne King&quot; &amp;lt;wmkingty@gmail.com&amp;gt; wrote in message &amp;lt;hd4oje$coj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Dias Papas&quot; &amp;lt;dias_papas@mathworks.com&amp;gt; wrote in message &amp;lt;hd4k31$7b7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I am new in signal processing and I want to filter some time series.&lt;br&gt;
&amp;gt; &amp;gt; I searched and I found the below code.&lt;br&gt;
&amp;gt; &amp;gt; It seems to work but I am not sure if it works properly.&lt;br&gt;
&amp;gt; &amp;gt; And I have two questions.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; First: Why the first values of the output 'y' are close to 0? Is it correct? Wouldn't be more logic to be close to the input data 'x'?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; And the second one: How can I plot the input data 'X' in the frequency domain with values of Hz, so I will see the frequencies of 'X' and  easily decide the cut off frecuency.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; If I am in completely wrong thought, please tell me.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The code:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; fs = 300;&lt;br&gt;
&amp;gt; &amp;gt; n = 0:1/fs:0.2;&lt;br&gt;
&amp;gt; &amp;gt; x = cos(2*pi*30*n) + cos(2*pi*50*n) + sin(2*pi*60*n);&lt;br&gt;
&amp;gt; &amp;gt; wc = pi*40 / (fs/2);&lt;br&gt;
&amp;gt; &amp;gt; N = 21;&lt;br&gt;
&amp;gt; &amp;gt; n = 0:1:N-1;&lt;br&gt;
&amp;gt; &amp;gt; hd = ideal_lp(wc,N);&lt;br&gt;
&amp;gt; &amp;gt; w_tet = (boxcar(N))';&lt;br&gt;
&amp;gt; &amp;gt; h = hd.*w_tet;&lt;br&gt;
&amp;gt; &amp;gt; y = filter(h,1,x);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; fr = 0:0.01:pi;&lt;br&gt;
&amp;gt; &amp;gt; X = freqz(x,1,fr);&lt;br&gt;
&amp;gt; &amp;gt; H = freqz(h,1,fr);&lt;br&gt;
&amp;gt; &amp;gt; Y = freqz(y,1,fr);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; figure (1)&lt;br&gt;
&amp;gt; &amp;gt; subplot(311)&lt;br&gt;
&amp;gt; &amp;gt; plot(fr,abs(X)); axis([0 3.5 0 40])&lt;br&gt;
&amp;gt; &amp;gt; subplot(312)&lt;br&gt;
&amp;gt; &amp;gt; plot(fr,abs(H)); axis([0 3.5 0 2])&lt;br&gt;
&amp;gt; &amp;gt; subplot(313)&lt;br&gt;
&amp;gt; &amp;gt; plot(fr,abs(Y)); axis([0 3.5 0 40])&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; figure (2)&lt;br&gt;
&amp;gt; &amp;gt; subplot(311)&lt;br&gt;
&amp;gt; &amp;gt; plot(x)&lt;br&gt;
&amp;gt; &amp;gt; subplot(312)&lt;br&gt;
&amp;gt; &amp;gt; plot(h)&lt;br&gt;
&amp;gt; &amp;gt; subplot(313)&lt;br&gt;
&amp;gt; &amp;gt; plot(y)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks veeeery much&lt;br&gt;
&amp;gt; &amp;gt; Dias&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi Dias, are you using R2009a or R2009b? If so and you have the Signal Processing Toolbox, how about using fdesign.lowpass? Using your signal, but lengthening it a bit (61 points is a pretty short signal).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; n = 0:1/fs:1;&lt;br&gt;
&amp;gt; x = cos(2*pi*30*n) + cos(2*pi*50*n) + sin(2*pi*60*n);&lt;br&gt;
&amp;gt; H = fdesign.lowpass('Fp,Fst,Ap,Ast',40,45,1,60,300); %passband 40 Hz,stop at 45&lt;br&gt;
&amp;gt; % 1 dB passband ripple, 60 dB stopband attenuation, 300 Hz sampling frequency&lt;br&gt;
&amp;gt; D = design(H,'equiripple'); % design filter--equiripple FIR design&lt;br&gt;
&amp;gt; fvtool(D) %look at filter magnitude response&lt;br&gt;
&amp;gt; y = filter(D,x); % Filter input signal&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you look at the help for fdesign.lowpass you will see there are a number of specification strings you can use. A number of them let you specify the filter order. If you want to use the window method for example, you can specify:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; H = fdesign.lowpass('N,Fc',50,40,300); %filter order of 50, cutoff of 40 Hz, Fs=300&lt;br&gt;
&amp;gt; designmethods(H) % designmethods() tell you what the valid design methods are&lt;br&gt;
&amp;gt; % returns window in this case&lt;br&gt;
&amp;gt; D = design(H,'window'); %window not necessary here--it's the only method&lt;br&gt;
&amp;gt; y = filter(D,x); % filter input signal&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; In terms of plotting the output iin the frequency domain, can I recommend you read the documentation on fft() and freqz()? If you want to plot the frequency response of your filter, calling freqz() with no output arguments and the proper sampling frequency will produce a plot for you. Alternatively, use two output arguments and plot the absolute value, absolute value squared, or the logarithm of the former as a function of the frequency vector.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; To look at the result of filtering your signal, I think you should spend some time reading the documentation for fft(), and or psd(). There a number of worked examples in the Matlab doc.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope that helps,&lt;br&gt;
&amp;gt; Wayne&lt;br&gt;
&lt;br&gt;
Wayne really thank you.&lt;br&gt;
Ill study what you ve tell me and if i hope i dont have any further question to bother you!</description>
    </item>
  </channel>
</rss>

