代码
%% 使用带通FIR数字滤波器产生宽带白噪声
%% 参数设置
fs=2000; % 采样频率
f1=100; % 最小截止频率
f2=500; % 最大截止频率
N=128; % 滤波器阶数
L=10000; % 采样点数
t=(0:L-1)/fs; % 时间序列
f=(0:L/2)*fs/L; % 频率序列
%% 信号的产生和滤波
b=fir1(N,[f1,f2]/(fs/2)); % 使用fir1函数设计FIR滤波器
x=randn(1,L); % 产生均值为0方差为1的高斯白噪声作为BPF输入
y=filter(b,1,x); % 白噪声通过BPF
%% 频谱分析
X=fft(x); % 原始信号频谱分析
X1=abs(X/L);
X2=X1(1:L/2+1); % 单边谱
X2(2:end-1)=2*X2(2:end-1);
Y=fft(y); % 滤波后信号频谱分析
Y1=abs(Y/L);
Y2=Y1(1:L/2+1); % 单边谱
Y2(2:end-1)=2*Y2(2:end-1);
%% 作图
figure(1);
subplot(211);
plot(t,x);
xlabel('t/s');
ylabel('Amplitude');
ylim([-4,4]);
title('原始信号时域波形图');
subplot(212);
plot(f,X2);
xlabel('f/Hz');
ylabel('Amplitude');
title('原始信号频谱图');
figure(2);
subplot(211);
plot(t,y);
xlabel('t/s');
ylabel('Amplitude');
ylim([-4,4]);
title('滤波后信号时域波形图');
subplot(212);
plot(f,Y2);
xlabel('f/Hz');
ylabel('Amplitude');
title('滤波后信号频谱图');
仿真结果