## filtering in the frequency domain

## filtering in the frequency domain

(OP)

Hello, and firstly appologies, I am a novice matlab user.

I want to filter some frequencies from a time domain signal (filter out everything below say 7 Hz). I was expecting to:

FFT time signal to frequency domain

Apply filter to frequency domain signal

inverse FFT filtered signal back to time domain.

What is wrong with this approach? When I plot the results, it seems to have applied the filter to the time domain signal....

Many thanks, Tom

my .m file so far:

function Hd = tjfilter

Fs = 200; % Sampling frequency

T = 1/Fs; % Sample time

L = 16384; % Length of signal(no. of data lines)

t = (0:L-1)*T; % Time vector

a = load('response_to_z.txt');

t = a(:,1);

x = a(:,2);

figure(1)

plot(t,x)

X = fft(x);

N = 200; % Order

Fstop = 7; % Stopband Frequency

Fpass = 10; % Passband Frequency

Wstop = 1; % Stopband Weight

Wpass = 1; % Passband Weight

dens = 20; % Density Factor

% Calculate the coefficients using the FIRPM function.

b = firpm(N, [0 Fstop Fpass Fs/2]/(Fs/2), [0 0 1 1], [Wstop Wpass], ...

{dens});

Hd = dfilt.dffir(b);

Y=filter(Hd,X);

fv = [0:0.005:100];

figure(2)

plot(fv,X);

figure(3)

plot(fv,Y);

y = (ifft(Y));

figure(4)

plot(t,y)

I want to filter some frequencies from a time domain signal (filter out everything below say 7 Hz). I was expecting to:

FFT time signal to frequency domain

Apply filter to frequency domain signal

inverse FFT filtered signal back to time domain.

What is wrong with this approach? When I plot the results, it seems to have applied the filter to the time domain signal....

Many thanks, Tom

my .m file so far:

function Hd = tjfilter

Fs = 200; % Sampling frequency

T = 1/Fs; % Sample time

L = 16384; % Length of signal(no. of data lines)

t = (0:L-1)*T; % Time vector

a = load('response_to_z.txt');

t = a(:,1);

x = a(:,2);

figure(1)

plot(t,x)

X = fft(x);

N = 200; % Order

Fstop = 7; % Stopband Frequency

Fpass = 10; % Passband Frequency

Wstop = 1; % Stopband Weight

Wpass = 1; % Passband Weight

dens = 20; % Density Factor

% Calculate the coefficients using the FIRPM function.

b = firpm(N, [0 Fstop Fpass Fs/2]/(Fs/2), [0 0 1 1], [Wstop Wpass], ...

{dens});

Hd = dfilt.dffir(b);

Y=filter(Hd,X);

fv = [0:0.005:100];

figure(2)

plot(fv,X);

figure(3)

plot(fv,Y);

y = (ifft(Y));

figure(4)

plot(t,y)

## RE: filtering in the frequency domain

h

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: filtering in the frequency domain

I used the FDA tool to design my filter, then exported it in to my m.file. The filter seems to work ok, but rather than filtering out the first 7 Hz from my frequency domain signal, it filters the first and last 7 seconds from my time domain signal. I've mis understood something along the way...

## RE: filtering in the frequency domain

- Steve

## RE: filtering in the frequency domain

=====================================

Eng-tips forums: The best place on the web for engineering discussions.

## RE: filtering in the frequency domain

so filter must do the fft - filter - ifft for you.?

If I filter my time domain data, then fft, I can see that the first 7Hz have gone. This is what I wanted.

Many thanks everyone. New filter file:

function Hd = tjfilter

Fs = 200; % Sampling frequency

T = 1/Fs; % Sample time

L = 20000; % Length of signal(no. of data lines)

t = (0:L-1)*T; % Time vector

a = load('response_to_z.txt');

t = a(:,1);

x = a(:,2);

figure(1)

plot(t,x)

X = fft(x);

N = 500; % Order

Fstop = 7; % Stopband Frequency

Fpass = 10; % Passband Frequency

Wstop = 1; % Stopband Weight

Wpass = 1; % Passband Weight

dens = 20; % Density Factor

% Calculate the coefficients using the FIRPM function.

b = firpm(N, [0 Fstop Fpass Fs/2]/(Fs/2), [0 0 1 1], [Wstop Wpass], ...

{dens});

Hd = dfilt.dffir(b);

NFFT = 2^nextpow2(L);

r=filter(Hd,x);

figure(2)

plot(t,r);

fv = Fs/L*(0:((L/2)-1));

R = fft(r,NFFT)/L;

f = Fs/2*linspace(0,1,NFFT/2+1);

RA=2*abs(R(1:NFFT/2+1));

figure(10)

plot(f,RA);

## RE: filtering in the frequency domain

=====================================

Eng-tips forums: The best place on the web for engineering discussions.

## RE: filtering in the frequency domain

Filtering is done via convolution in the time domain. No fft/ifft required. The help page for filter() explains it all. Think of a filter as a glorified moving average, with unequal weights on each sample.

- Steve

## RE: filtering in the frequency domain

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?