Path: news.mathworks.com!not-for-mail
From: "Dias Papas" <dias_papas@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Low pass filtering
Date: Sat, 7 Nov 2009 20:08:02 +0000 (UTC)
Organization: auth
Lines: 48
Message-ID: <hd4k31$7b7$1@fred.mathworks.com>
Reply-To: "Dias Papas" <dias_papas@mathworks.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257624482 7527 172.30.248.35 (7 Nov 2009 20:08:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 7 Nov 2009 20:08:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 955492
Xref: news.mathworks.com comp.soft-sys.matlab:583259


I am new in signal processing and I want to filter some time series.
I searched and I found the below code.
It seems to work but I am not sure if it works properly.
And I have two questions.

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'?

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.

If I am in completely wrong thought, please tell me.

The code:

fs = 300;
n = 0:1/fs:0.2;
x = cos(2*pi*30*n) + cos(2*pi*50*n) + sin(2*pi*60*n);
wc = pi*40 / (fs/2);
N = 21;
n = 0:1:N-1;
hd = ideal_lp(wc,N);
w_tet = (boxcar(N))';
h = hd.*w_tet;
y = filter(h,1,x);

fr = 0:0.01:pi;
X = freqz(x,1,fr);
H = freqz(h,1,fr);
Y = freqz(y,1,fr);

figure (1)
subplot(311)
plot(fr,abs(X)); axis([0 3.5 0 40])
subplot(312)
plot(fr,abs(H)); axis([0 3.5 0 2])
subplot(313)
plot(fr,abs(Y)); axis([0 3.5 0 40])

figure (2)
subplot(311)
plot(x)
subplot(312)
plot(h)
subplot(313)
plot(y)


Thanks veeeery much
Dias