Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

filtering in the frequency domain

Status
Not open for further replies.

tjakeman

Mechanical
Oct 21, 2009
29
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)


 
Replies continue below

Recommended for you

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...
 
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
 
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.
 
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);
 
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.
 
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
 
Alternatively you can do it via spectrum shaping in the frequency domain, but that can have exciting repercussions when you ifft back to the time domain.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor