简体   繁体   English

在MATLAB中设计窄带通滤波器

[英]Designing a narrow bandpass filter in MATLAB

I'm working on signal filtering in MATLAB. 我正在MATLAB中进行信号滤波。 I wrote a signal with 3 different frequencies: 我用3种不同的频率写了一个信号:

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);

信号y

Now I want to extract the 50Hz signal by bandpass window filtering using a Hanning window. 现在我想使用汉宁窗口通过带通窗口滤波提取50Hz信号。
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: 之后,我使用filter进行filter如下所示:

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? 为什么这个滤波器无法提取50Hz信号?
  • I'm doing something wrong in this simulation? 我在这个模拟中做错了什么?
  • How can I filter out the 50Hz signal? 如何滤除50Hz信号?

what is the best sample rate for 50Hz signal? 50Hz信号的最佳采样率是多少? 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. 在现实世界中,如平衡系统,主信号约为20Hz,环境噪声太大,我的解决方案过滤不能给出正确的答案。 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 ? 如果我的采样率是8000Hz并且我只能缓冲20000个采样 ,那么如何设计一个窄带通滤波器呢?

So, I Solve problem by decrease sample rate and increase sample data by this code: ( as Matt was Said ) 因此,我通过降低采样率并通过此代码增加样本数据来解决问题:(如Matt所说)

Fs = 1000;                    % Sampling frequency
T = 1/Fs;                     % Sample time
L = 60000;                     % Length of signal
t = (0:L-1)*T;                % Time vector

for j=1:20

 r1 = 5 + (1000-5).*rand(1,1);
 r2 = 5 + (1000-5).*rand(1,1);

y = 10*sin(2*pi*14.8*t) + r1*sin(2*pi*14.2*t) +  r2*sin(2*pi*15.5*t) + 1.1*rand(size(t));


yfilter = filter(Hd.Numerator,1,y);
max(yfilter(40000:50000))

end

my filter is KAISER ( FIR Badpass filter ) : 我的过滤器是KAISER(FIR Badpass过滤器):

Fs = 1000;  % Sampling Frequency

Fstop1 = 14.2;            % First Stopband Frequency
Fpass1 = 14.6;            % First Passband Frequency
Fpass2 = 15;              % Second Passband Frequency
Fstop2 = 15.2;            % Second Stopband Frequency
Dstop1 = 1e-06;           % First Stopband Attenuation
Dpass  = 0.057501127785;  % Passband Ripple
Dstop2 = 1e-06;           % Second Stopband Attenuation
flag   = 'scale';         % Sampling Flag

% Calculate the order from the parameters using KAISERORD.
[N,Wn,BETA,TYPE] = kaiserord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 ...
                             1 0], [Dstop1 Dpass Dstop2]);

% Calculate the coefficients using the FIR1 function.
b  = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag);
Hd = dfilt.dffir(b);

and filter amplitude for 20 iteration and random noise signal is : 滤波幅度为20次迭代,随机噪声信号为:

max(yfilter(40000:50000))

10.01
10.02
10.01
10.00
10.01
10.03
10.01
10.02
....

that is a great result for me, and filtered signal is : 对我来说这是一个很好的结果,过滤后的信号是: 过滤信号

but there is some problem : 但是有一些问题:

1- my sample data length is 60000 bytes, in other hand by sampling rate at 1000Hz, I wait for 60 Seconds for gathering data, and that is too long time!!! 1-我的样本数据长度是60000字节,另一方面是1000Hz的采样率,我等待60秒收集数据,这太长时间了! when i decrease sample data length to about 3000 samples, filtered result is so bad because of number of filter's coefficients is about 4097. how can i filter my signal when it's length is 3000 samples and my filter's coefficients is about 4097 bytes? 当我将样本数据长度减少到大约3000个样本时,滤波结果是如此糟糕,因为滤波器系数的数量大约是4097.当长度为3000个样本且我的滤波器系数大约为4097字节时,如何过滤我的信号? when i decrease filter's coefficients , filtered signal result is so noisy. 当我减小滤波器的系数时,滤波后的信号结果是如此嘈杂。

2- what is the best sample rate fo 15 Hz signal? 2- 15 Hz信号的最佳采样率是多少?

thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM