gpt4 book ai didi

matlab - 带通滤波器无法在 matlab 中过滤不需要的频率

转载 作者:行者123 更新时间:2023-12-02 03:16:37 24 4
gpt4 key购买 nike

我正在制作一个带通滤波器,我创建了一个基于正弦波的带有一些不需要的频率的信号:

Fs = 8e3; % Sampling Rate
fn = Fs/2; % Nyquist frequency
L = 1e3; % Length of signal
T = 1/Fs; % Sampling period
t = T*linspace(0,L,Fs); % Time domain

% Frequencies in Hz
f1 = 1500;
f2 = 700;
f3 = 2500;
f4 = 3500;

% Signal
x = 6*sin(2*pi*f1*t);

% Noise
noise = 3*sin(2*pi*f2*t)...
+ 2*sin(2*pi*f3*t)...
+ 1*sin(2*pi*f4*t);

x_noise = x + noise;

然后我创建了一个巴特沃斯带通滤波器:

[b,a] = butter(10,[1000 2000]/fn,'bandpass');

具有带通响应(带 freqz)的时频空间信号如下所示:

Fig. 1 Signal with corruption | Fig. 2 Frequency with bandpass response

我会从这里开始想,简单地做

xf = filter(b,a,x_noise);

会产生与原始信号非常相似的东西,但唉,我得到的是 really far from the filtered signal with a high response far from the bandpass .

我在这里做错了什么?

完整代码如下:

clear all
Fs = 8e3; % Sampling Rate
fn = Fs/2; % Nyquist frequency
L = 1e3; % Length of signal
T = 1/Fs; % Sampling period
t = T*linspace(0,L,Fs); % Time domain

% Frequencies in Hz
f1 = 1500;
f2 = 700;
f3 = 2500;
f4 = 3500;

% Signal
x = 6*sin(2*pi*f1*t);

% Noise
noise = 3*sin(2*pi*f2*t)...
+ 2*sin(2*pi*f3*t)...
+ 1*sin(2*pi*f4*t);

x_noise = x + noise;

subplot(221);
idx = 1:round(length(t)/30);
plot(t(idx),x(idx),t(idx),x_noise(idx));
xlabel('Time (s)'); ylabel('Signal Amplitudes');
legend('Original signal','Noisy signal');

% Frequency space
f = fn*linspace(0,1,L/2+1);
X = fft(x_noise)/L;

[b,a] = butter(10,[1000 2000]/fn,'bandpass');
h = abs(freqz(b,a,floor(L/2+1)));

subplot(222);
plot(f,abs(X(1:L/2+1)),f,h*max(abs(X)));
xlabel('Freq (Hz)'); ylabel('Frequency amplitudes');
legend('Fourier Transform of signal','Filter amplitude response');

% Filtered signal
xf = filter(b,a,x_noise);
subplot(223)
plot(t(idx),xf(idx));
xlabel('Time (s)'); ylabel('Signal Amplitudes');
legend('Filtered signal');

% Filtered in frequency space
Xf = abs(fft(xf)/L);
subplot(224);
plot(f,Xf(1:L/2+1),f,h*5e-6);
xlabel('Freq (Hz)'); ylabel('Frequency amplitudes');
legend('Fourier Transform of filtered signal','Bandpass');

最佳答案

你的时间变量 t 是错误的,例如 1/(t(2)-t(1)) 应该给 Fs 但它没有。

改为尝试:

t = T*(0:L-1);

关于matlab - 带通滤波器无法在 matlab 中过滤不需要的频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36672843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com