I'm working on signal filtering in MATLAB. I wrote a signal with 3 different frequencies:
Fs = 8000; %// Sampling frequency
T = 1/Fs; %// Sample time
L = 16000; %// Length of signal
t = (0:L-1)*T; %// Time vector
y = 40*sin(2*pi*50*t) + 500*sin(2*pi*51*t) + 500*sin(2*pi*49*t);
Now I want to extract the 50Hz signal by bandpass window filtering using a Hanning window.
Here is my code to design the filter:
function Hd = HannFilter1
Fs = 8000; %// Sampling Frequency
N = 4096; %// Order
Fc1 = 49.5; %// First Cutoff Frequency
Fc2 = 50.5; %// Second Cutoff Frequency
flag = 'scale'; %// Sampling Flag
win = hann(N+1);
b = fir1(N, [Fc1 Fc2]/(Fs/2), 'bandpass', win, flag);
Hd = dfilt.dffir(b);
After that, I do filtering using filter like this:
yfilter = filter(Hd.Numerator,1,y);
NFFT = 2^nextpow2(L);
Y = fft(yfilter,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
figure;
subplot(2,1,1);
plot(yfilter);
subplot(2,1,2);
plot(f,2*abs(Y(1:NFFT/2+1)))
- Why is this filter unable to extract the 50Hz signal?
- I'm doing something wrong in this simulation?
- How can I filter out the 50Hz signal?
what is the best sample rate for 50Hz signal? and very important question! in real world, like balancing system, the main signal is about 20Hz and environment is very too noisy and filtering by my solution does not give a correct answer. in this case,how can i use or choose the best filtering algorithm?
if my sample rate be 8000Hz and I can buffered only 20000 samples, how can Designing a narrow bandpass filter?



fvtool(Hd). You will see that your filter is approx. -1dB @ 49Hz and 51Hz which is probably not what you want. - Matt