FFT Filtering of signal

323 views Asked by At

I have a signal and I want extract frequencies beween 14 hz to 14.4hz. I use some band pass filter like butterworth but answer is not acceptable. And now I want to know how can I use FFT Filter to get my frequency. I write this code in matlab :

clc;
clear all;
load('SignalData2');
[n,c] = size(mydata2);
mydata1 = mydata2(1:n,1);
% my sample rate is 39500 or datalenth/4
fs = n/4;      % Sampling rate [Hz]
Ts = 1/fs;       % Sampling period [s]
fNy = fs / 2;    % Nyquist frequency [Hz]
noSamples = n;   % Number of samples
f = 0 : fs/noSamples : fs - fs/noSamples; % Frequency vector
figure;
subplot(2,2,1);
plot(mydata1);
x_fft = abs(fft(mydata1));
subplot(2,2,2);
plot(f,x_fft);
xlim([1 150]);
bw=0.2;      %Bandwisth
fc=pi*14.2;     %Center Frequency
L = n;       % sample number;
%Compute Hamming window
for nn=1:L
    hamm(nn)=(0.54-0.46*cos(2*pi*nn/L));
end
%Compute Filter
hsuup=(-(L-1)/2:(L-1)/2);
hideal1=hamm.*(2*(fc+bw)*(sin(2*(fc+bw)*hsuup/fs)./(2*(2*fc+bw)*hsuup/fs)));
hideal2=hamm.*(2*(fc-bw)*(sin(2*(fc-bw)*hsuup/fs)./(2*(2*fc+bw)*hsuup/fs)));
h_bpf=(hideal1-hideal2);
comp_sig_fft=fft(mydata1)'/L;
h_bpf_fft=fft(h_bpf) /L;
s100_fft=comp_sig_fft.*h_bpf_fft;
band_passed_signal=real(ifft(s100_fft));
subplot(2,2,3);
plot(band_passed_signal);
% 
x_fft = abs(fft(band_passed_signal));
subplot(2,2,4);
plot(f,x_fft);
xlim([1 150]);

and i upload signal file at this link : http://wikisend.com/download/428686/SignalData2.mat

but filter signal is NaN. is there any idea for solved this problem? Result Image : http://i58.tinypic.com/11ukn61.jpg

1

There are 1 answers

2
Iban Cereijo On

The result of fft(h_bpf) is NaN because you have one NaN value in the input h_bpf. This value was introduced by an expression like sin(x)/x, with x=0, when you compute hideal1 and hideal2

> find(isnan(hideal1))

ans =

       78443

Try to use the sinc function instead if you need such computations.