|
Hi,
I want to filter a time series with a FIR window technique and I programmed the below code.
It works but I am not sure if it works properly.
Question: I use the filter command in the space domain with the coefficient h.
So i do the filtering in the space domain. Is there any way to do the filtering in the frequency domain with H?
Also can you tell me if it works properly?
The code:
wp = 0.2*pi;
ws = 0.3*pi;
tr_width = ws - wp
M = ceil(6.6*pi/tr_width) + 1
wc = (ws+wp)/2; %cut off frequency
hd = ideal_lp(wc,M); % ideal impulse response
w_ham = (hamming(M))'; % window
h = hd .* w_ham; % impulse response
fr = 0:0.001:pi; %step
H = freqz(h,1,fr); % filter frequency response
x = randn(100,1); % data: discrete time serie
X = freqz(x,1,fr); % data frequency response
y = filter(h,1,x); % output
Y = freqz(y,1,fr); % output data frequency response
% Plot
figure (1)
subplot(121)
plot(fr,abs(H))
title('Frequency response H'); xlabel('frequency in radians')
subplot(122)
semilogy(fr,abs(H))
title('Frequency response H'); xlabel('frequency in radians')
figure(2)
plot(x)
title('Data in space domain')
figure (3)
plot(fr,abs(X))
title('Data in frequency domain')
figure (4)
plot(fr,abs(Y))
title('Output in frequency domain')
figure (5)
plot(y)
title('Output in space domain')
figure (6)
plot(fr,abs(YY))
title('Output in frequency domain')
figure (7)
plot(yy)
title('Output in space domain')
Thanks very much
Dias
|