×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

filtering in the frequency domain

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)


 

RE: filtering in the frequency domain

(OP)
Hi Greg.

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

filter() works on time domain data, not frequency domain.  The firpm() function designs a FIR filter to be used with your original time domain data.  I suppose applying it in the frequency domain is effectively modifying the time response rather than the frequency response of your data.  Interesting nevertheless.

- Steve

RE: filtering in the frequency domain

So just to close the loop for original poster.  Assuming it is an FIR filter.  Then we presume the filter length is 7 seconds on each side of 0 based on symtpoms reported (does that square with the filter length and sample rate?).  Then when we perform convolution of the signal with the FIR we need to start 7 seconds after the beginning of the signal and step 7 seconds before the end of the data, otherwise the filter extends to a region in time where there is no signal.

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

RE: filtering in the frequency domain

(OP)
Sompting guy - Thankyou!

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

You might think about whether a window is required depending on the characteristics of your original signal.

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

RE: filtering in the frequency domain

tjakeman:

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close