威望0
积分7946
贡献0
在线时间763 小时
UID1
注册时间2021-4-14
最后登录2024-11-21
管理员
- UID
- 1
- 威望
- 0
- 积分
- 7946
- 贡献
- 0
- 注册时间
- 2021-4-14
- 最后登录
- 2024-11-21
- 在线时间
- 763 小时
|
clear clc;
close all;
time = 1:1000;
fre1 = 50;
fre2 = 500;
fs = 8000;
sin_signal1 = sin(2*pi*fre1*time/fs);
sin_signal2 = sin(2*pi*fre2*time/fs);
sin_signal = sin_signal1 + sin_signal2;
figure(1);
plot(sin_signal1);
title("单音信号1的时域图");
figure(2);
plot(sin_signal2);
title("单音信号2的时域图");
figure(3);
plot(sin_signal);
title("双音信号的时域图");
figure(4);
plot(abs(fft(sin_signal1)));
title("单音信号1的频域图");
figure(5);
plot(abs(fft(sin_signal2)));
title("单音信号2的频域图");
figure(6);
plot(abs(fft(sin_signal)));
title("双音信号的频域图");
Fs = 8000; % Sampling Frequency
N = 128; % Order
Fc1 = 30; % First Cutoff Frequency
Fc2 = 60; % Second Cutoff Frequency
flag = 'scale'; % Sampling Flag
Beta = 0.5; % Window Parameter
% Create the window vector for the design algorithm.
win = kaiser(N+1, Beta);
% Calculate the coefficients using the FIR1 function.
filter_lowpass = fir1(N, [Fc1 Fc2]/(Fs/2), 'bandpass', win, flag);
[H,w]=freqz(filter_lowpass);
Hf=abs(H); %取幅度值实部
% [A1,PS]=mapminmax(Hf)
Hx=angle(H); %取相位值对应相位角
figure(9)
plot(w*fs/(2*pi),20*log10(Hf)) %幅值变换为分贝单位
title('离散系统幅频特性曲线')
% figure(8)
% plot(w*fs/(2*pi),Hx)
% title('离散系统相频特性曲线')
% figure(7);
% freqz(filter_lowpass);
% title("滤波器频域响应图");
% sin_signal_filter = filter(filter_lowpass, 1, sin_signal);
% figure(8);
% plot(sin_signal_filter);
% title("滤波之后时域图");
% figure(9);
% plot(abs(fft(sin_signal_filter)));
% title("滤波之后频域图");
% |
|