当前位置:网站首页>Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
2022-06-26 13:06:00 【On the way】
Catalog
introduction
Some time ago , Wrote a Direct type FIR Filter implementation Of Verilog Program :
Digital signal processing —— Direct type FIR Filter design (1)
Digital signal processing —— Direct type FIR Filter design (2)
Recently, I want to write another linear phase type FIR Filter structure Verilog Program . After planning the design idea , Ready to start implementing , When preparing to generate four types of linear phase filter tap coefficients , I suddenly found a frequently used function fir1、fir2 It can only produce Ⅰ、Ⅱ type FIR filter . Later, I simply stopped to study all MATLAB It can be used to generate linear phase FIR Filter function . Write it all down here , To record , For a rainy day .
1、FIR Linear phase filter
To put it simply FIR Basic points of linear phase filter :
- Limited length
- Phase linearity in passband ( The group delay is constant )
- The length is N, Order number is N-1
- With strange / Even symmetry property
The picture below is MATLAB Screenshot of my own summary in the editor ( I'm too lazy to type )

Nonsense ,3,2,1 Code up ~
2、Ⅰ type FIR filter
2.1、 low pass filter
%% ---- ---- ---- Ⅰ type Linear phase FIR filter ( Lowpass ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |----------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 4e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% Low pass filter parameter index
Fc_LP = 1e6; % Cut off frequency Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% I type FIR Design
% -1- low pass filter
% Uniform parameters
Order_1_FIP_LP = 32; % Ⅰ type FIR Low pass filter order
% -1.1- fir1 Realization
WINDOW_GAUSS_1_FIR_LP = gausswin(Order_1_FIP_LP+1,3); % Gauss window α=3
% fir1 function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fir1 = fir1(Order_1_FIP_LP,2*Fc_LP/fs,"low",WINDOW_GAUSS_1_FIR_LP,"scale");
S_1_FIR_LP_fir1_OUT = filter(H_1_FIR_LP_fir1,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fir1,'filled','b')
axis tight
title('fir1 function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fir1,1)
title('fir1 function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fir1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('I type FIR low pass filter (fir1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fir1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fir1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- fir2 Realization
WINDOW_BLACKMAN_1_FIR_LP = blackman(Order_1_FIP_LP+1,"symmetric"); % Blackman window
% fir2 function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fir2 = fir2(Order_1_FIP_LP,[0 2*Fc_LP/fs 2*Fc_LP/fs 1],[1 1 0 0],WINDOW_BLACKMAN_1_FIR_LP);
S_1_FIR_LP_fir2_OUT = filter(H_1_FIR_LP_fir2,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fir2,'filled','b')
axis tight
title('fir2 function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fir2,1)
title('fir2 function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fir2_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (fir2 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fir2_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fir2 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.3- firls Realization
% firls function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_firls = firls(Order_1_FIP_LP,[0 2*Fc_LP/fs 2*Fc_LP/fs 1],[1 1 0 0],[10,1000]);
S_1_FIR_LP_firls_OUT = filter(H_1_FIR_LP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_firls,1)
title('firls function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.4- firpm Realization
% firpm function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_firpm = firpm(Order_1_FIP_LP,[0 2*Fc_LP/fs 4*Fc_LP/fs 1],[1 1 0 0],[10,1000]);
S_1_FIR_LP_firpm_OUT = filter(H_1_FIR_LP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_firpm,1)
title('firpm function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.5- fircls Realization
% fircls function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fircls = fircls(Order_1_FIP_LP,[0 2*Fc_LP/fs 1],[1 0],[1.01,0.01],[0.99,-0.01]);
S_1_FIR_LP_fircls_OUT = filter(H_1_FIR_LP_fircls,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fircls,'filled','b')
axis tight
title('fircls function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fircls,1)
title('fircls function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fircls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (fircls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fircls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fircls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.6- fircls1 Realization
% fircls1 function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fircls1 = fircls1(Order_1_FIP_LP,2*Fc_LP/fs,0.01,0.001);
S_1_FIR_LP_fircls1_OUT = filter(H_1_FIR_LP_fircls1,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fircls1,'filled','b')
axis tight
title('fircls1 function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fircls1,1)
title('fircls1 function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fircls1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (fircls1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fircls1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fircls1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.7- rcosdesign Realization
% rcosdesign function Design Ⅰ type FIR low pass filter
% This filter cannot accurately control the cut-off frequency , It is often used in shaping filter design , Not used in typical four filter designs
H_1_FIR_LP_rcosdesign = rcosdesign(0.2,8,4,"sqrt");
figure;
stem(H_1_FIR_LP_rcosdesign,'filled','b')
axis tight
title('rcosdesign function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_rcosdesign,1)
title('rcosdesign function Design Ⅰ type FIR low pass filter Frequency response curve ')
% -1.8- cfirpm Realization
% cfirpm function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_cfirpm = cfirpm(Order_1_FIP_LP,[0 2*Fc_LP/fs 4*Fc_LP/fs 1],[1 1 0 0],[10,1000],"even");
S_1_FIR_LP_cfirpm_OUT = filter(H_1_FIR_LP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
2.2、 Bandpass filter
%% ---- ---- ---- Ⅰ type Linear phase FIR filter ( Bandpass ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 3e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% Band pass filter parameter index
Fc_1_BP = 1.5e6; % Cut off frequency 1 Company :Hz
Fc_2_BP = 4.5e6; % Cut off frequency 1 Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% I type FIR Design
% -1- Bandpass filter
% Uniform parameters
Order_1_FIP_BP = 32; % Ⅰ type FIR Bandpass filter order
% -1.1- fir1 Realization
WINDOW_GAUSS_1_FIR_BP = gausswin(Order_1_FIP_BP+1,3); % Gauss window α=3
% fir1 function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_fir1 = fir1(Order_1_FIP_BP,[2*Fc_1_BP/fs 2*Fc_2_BP/fs],"bandpass",WINDOW_GAUSS_1_FIR_BP,"scale");
S_1_FIR_BP_fir1_OUT = filter(H_1_FIR_BP_fir1,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_fir1,'filled','b')
axis tight
title('fir1 function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_fir1,1)
title('fir1 function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_fir1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (fir1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_fir1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (fir1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- fir2 Realization
WINDOW_BLACKMAN_1_FIR_BP = blackman(Order_1_FIP_BP+1,"symmetric"); % Blackman window
% fir2 function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_fir2 = fir2(Order_1_FIP_BP,[0 2*Fc_1_BP/fs 2*Fc_2_BP/fs 1],[0 1 1 0],WINDOW_BLACKMAN_1_FIR_BP);
S_1_FIR_BP_fir2_OUT = filter(H_1_FIR_BP_fir2,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_fir2,'filled','b')
axis tight
title('fir2 function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_fir2,1)
title('fir2 function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_fir2_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (fir2 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_fir2_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (fir2 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.3- firls Realization
% firls function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_firls = firls(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[1,100,1]);
S_1_FIR_BP_firls_OUT = filter(H_1_FIR_BP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_firls,1)
title('firls function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.4- firpm Realization
% firpm function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_firpm = firpm(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[30,100,10]);
S_1_FIR_BP_firpm_OUT = filter(H_1_FIR_BP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_firpm,1)
title('firpm function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.5- fircls Realization
% fircls function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_fircls = fircls(Order_1_FIP_BP,[0 2*Fc_1_BP/fs 2*Fc_2_BP/fs 1],[0 1 0],[0.001,1.01,0.01],[-0.001,0.99,-0.01]);
S_1_FIR_BP_fircls_OUT = filter(H_1_FIR_BP_fircls,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_fircls,'filled','b')
axis tight
title('fircls function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_fircls,1)
title('fircls function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_fircls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (fircls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_fircls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (fircls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.6- cfirpm Realization
% cfirpm function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_cfirpm = cfirpm(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[30,100,10],"even");
S_1_FIR_BP_cfirpm_OUT = filter(H_1_FIR_BP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
2.3、 Band stop filter
%% ---- ---- ---- Ⅰ type Linear phase FIR filter ( Band stop ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 3e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% Parameters of band stop filter
Fc_1_BS = 1.5e6; % Cut off frequency 1 Company :Hz
Fc_2_BS = 4.5e6; % Cut off frequency 1 Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% I type FIR Design
% -1- Band stop filter
% Uniform parameters
Order_1_FIP_BS = 32; % Ⅰ type FIR Band stop filter order
% -1.1- fir1 Realization
WINDOW_GAUSS_1_FIR_BS = gausswin(Order_1_FIP_BS+1,3); % Gauss window α=3
% fir1 function Design Ⅰ type FIR Band stop filter
H_1_FIR_BS_fir1 = fir1(Order_1_FIP_BS,[2*Fc_1_BS/fs 2*Fc_2_BS/fs],"stop",WINDOW_GAUSS_1_FIR_BS,"scale");
S_1_FIR_BS_fir1_OUT = filter(H_1_FIR_BS_fir1,1,S_VERIFY);
figure;
stem(H_1_FIR_BS_fir1,'filled','b')
axis tight
title('fir1 function Design Ⅰ type FIR Band stop filter Impulse response ')
figure;
freqz(H_1_FIR_BS_fir1,1)
title('fir1 function Design Ⅰ type FIR Band stop filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BS_fir1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('I type FIR Band stop filter (fir1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BS_fir1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Band stop filter (fir1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- fir2 Realization
WINDOW_BLACKMAN_1_FIR_BS = blackman(Order_1_FIP_BS+1,"symmetric"); % Blackman window
% fir2 function Design Ⅰ type FIR Band stop filter
H_1_FIR_BS_fir2 = fir2(Order_1_FIP_BS,[0 2*Fc_1_BS/fs 2*Fc_2_BS/fs 1],[1 0 0 1],WINDOW_BLACKMAN_1_FIR_BS);
S_1_FIR_BS_fir2_OUT = filter(H_1_FIR_BS_fir2,1,S_VERIFY);
figure;
stem(H_1_FIR_BS_fir2,'filled','b')
axis tight
title('fir2 function Design Ⅰ type FIR Band stop filter Impulse response ')
figure;
freqz(H_1_FIR_BS_fir2,1)
title('fir2 function Design Ⅰ type FIR Band stop filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BS_fir2_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Band stop filter (fir2 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BS_fir2_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Band stop filter (fir2 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.3- firls Realization
% firls function Design Ⅰ type FIR Band stop filter
H_1_FIR_BS_firls = firls(Order_1_FIP_BS,[0 1.5*Fc_1_BS/fs 2*Fc_1_BS/fs 1.9*Fc_2_BS/fs 2*Fc_2_BS/fs 1],[1 1 0 0 1 1],[100,1,100]);
S_1_FIR_BS_firls_OUT = filter(H_1_FIR_BS_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_BS_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR Band stop filter Impulse response ')
figure;
freqz(H_1_FIR_BS_firls,1)
title('firls function Design Ⅰ type FIR Band stop filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BS_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Band stop filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BS_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Band stop filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.4- firpm Realization
% firpm function Design Ⅰ type FIR Band stop filter
H_1_FIR_BS_firpm = firpm(Order_1_FIP_BS,[0 1.5*Fc_1_BS/fs 2*Fc_1_BS/fs 1.9*Fc_2_BS/fs 2*Fc_2_BS/fs 1],[1 1 0 0 1 1],[1,100,1]);
S_1_FIR_BS_firpm_OUT = filter(H_1_FIR_BS_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BS_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR Band stop filter Impulse response ')
figure;
freqz(H_1_FIR_BS_firpm,1)
title('firpm function Design Ⅰ type FIR Band stop filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BS_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Band stop filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BS_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Band stop filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.5- fircls Realization
% fircls function Design Ⅰ type FIR Band stop filter
H_1_FIR_BS_fircls = fircls(Order_1_FIP_BS,[0 2*Fc_1_BS/fs 2*Fc_2_BS/fs 1],[1 0 1],[1.001,0.01,1.01],[0.999,-0.01,0.99]);
S_1_FIR_BS_fircls_OUT = filter(H_1_FIR_BS_fircls,1,S_VERIFY);
figure;
stem(H_1_FIR_BS_fircls,'filled','b')
axis tight
title('fircls function Design Ⅰ type FIR Band stop filter Impulse response ')
figure;
freqz(H_1_FIR_BS_fircls,1)
title('fircls function Design Ⅰ type FIR Band stop filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BS_fircls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Band stop filter (fircls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BS_fircls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Band stop filter (fircls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.6- cfirpm Realization
% cfirpm function Design Ⅰ type FIR Band stop filter
H_1_FIR_BS_cfirpm = cfirpm(Order_1_FIP_BS,[0 1.5*Fc_1_BS/fs 2*Fc_1_BS/fs 1.9*Fc_2_BS/fs 2*Fc_2_BS/fs 1],[1 1 0 0 1 1],[1,1000,1],"even");
S_1_FIR_BS_cfirpm_OUT = filter(H_1_FIR_BS_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BS_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR Band stop filter Impulse response ')
figure;
freqz(H_1_FIR_BS_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR Band stop filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BS_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Band stop filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BS_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Band stop filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
2.4、 High pass filter
%% ---- ---- ---- Ⅰ type Linear phase FIR filter ( qualcomm ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 4e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% High pass filter parameter index
Fc_HP = 1e6; % Cut off frequency Company :Hz
% Band pass filter parameter index
% High pass filter parameter index
% Parameters of band stop filter
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% I type FIR Design
% -1- High pass filter
% Uniform parameters
Order_1_FIP_HP = 32; % Ⅰ type FIR High pass filter order
% -1.1- fir1 Realization
WINDOW_GAUSS_1_FIR_HP = gausswin(Order_1_FIP_HP+1,3); % Gauss window α=3
% fir1 function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_fir1 = fir1(Order_1_FIP_HP,2*Fc_HP/fs,"high",WINDOW_GAUSS_1_FIR_HP,"scale");
S_1_FIR_HP_fir1_OUT = filter(H_1_FIR_HP_fir1,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_fir1,'filled','b')
axis tight
title('fir1 function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_fir1,1)
title('fir1 function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_fir1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('I type FIR High pass filter (fir1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_fir1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (fir1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- fir2 Realization
WINDOW_BLACKMAN_1_FIR_HP = blackman(Order_1_FIP_HP+1,"symmetric"); % Blackman window
% fir2 function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_fir2 = fir2(Order_1_FIP_HP,[0 2*Fc_HP/fs 2*Fc_HP/fs 1],[0 0 1 1],WINDOW_BLACKMAN_1_FIR_HP);
S_1_FIR_HP_fir2_OUT = filter(H_1_FIR_HP_fir2,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_fir2,'filled','b')
axis tight
title('fir2 function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_fir2,1)
title('fir2 function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_fir2_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (fir2 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_fir2_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (fir2 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.3- firls Realization
% firls function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_firls = firls(Order_1_FIP_HP,[0 2*Fc_HP/fs 2*Fc_HP/fs 1],[0 0 1 1],[10,1000]);
S_1_FIR_HP_firls_OUT = filter(H_1_FIR_HP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_firls,1)
title('firls function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.4- firpm Realization
% firpm function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_firpm = firpm(Order_1_FIP_HP,[0 2*Fc_HP/fs 4*Fc_HP/fs 1],[0 0 1 1],[10,1000]);
S_1_FIR_HP_firpm_OUT = filter(H_1_FIR_HP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_firpm,1)
title('firpm function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.5- fircls Realization
% fircls function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_fircls = fircls(Order_1_FIP_HP,[0 2*Fc_HP/fs 1],[0 1],[0.01,1.01],[-0.01,0.99]);
S_1_FIR_HP_fircls_OUT = filter(H_1_FIR_HP_fircls,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_fircls,'filled','b')
axis tight
title('fircls function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_fircls,1)
title('fircls function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_fircls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (fircls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_fircls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (fircls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.6- fircls1 Realization
% fircls1 function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_fircls1 = fircls1(Order_1_FIP_HP,2*Fc_HP/fs,0.01,0.001,"high");
S_1_FIR_HP_fircls1_OUT = filter(H_1_FIR_HP_fircls1,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_fircls1,'filled','b')
axis tight
title('fircls1 function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_fircls1,1)
title('fircls1 function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_fircls1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (fircls1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_fircls1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (fircls1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.7- cfirpm Realization
% cfirpm function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_cfirpm = cfirpm(Order_1_FIP_HP,[0 2*Fc_HP/fs 4*Fc_HP/fs 1],[0 0 1 1],[10,1000],"even");
S_1_FIR_HP_cfirpm_OUT = filter(H_1_FIR_HP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
3、Ⅱ type FIR filter
3.1、 low pass filter
2.1 Low pass filter in section , Change the order to odd number ,rcosdesign Function this type is not available .
Specifically :
%% ---- ---- ---- Ⅱ type Linear phase FIR filter ( Lowpass ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 4e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% Low pass filter parameter index
Fc_LP = 1e6; % Cut off frequency Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% FIR Design
% -1- low pass filter
% Uniform parameters
Order_1_FIP_LP = 31; % Ⅰ type FIR Low pass filter order
% -1.1- fir1 Realization
WINDOW_GAUSS_1_FIR_LP = gausswin(Order_1_FIP_LP+1,3); % Gauss window α=3
% fir1 function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fir1 = fir1(Order_1_FIP_LP,2*Fc_LP/fs,"low",WINDOW_GAUSS_1_FIR_LP,"scale");
S_1_FIR_LP_fir1_OUT = filter(H_1_FIR_LP_fir1,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fir1,'filled','b')
axis tight
title('fir1 function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fir1,1)
title('fir1 function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fir1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('I type FIR low pass filter (fir1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fir1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fir1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- fir2 Realization
WINDOW_BLACKMAN_1_FIR_LP = blackman(Order_1_FIP_LP+1,"symmetric"); % Blackman window
% fir2 function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fir2 = fir2(Order_1_FIP_LP,[0 2*Fc_LP/fs 2*Fc_LP/fs 1],[1 1 0 0],WINDOW_BLACKMAN_1_FIR_LP);
S_1_FIR_LP_fir2_OUT = filter(H_1_FIR_LP_fir2,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fir2,'filled','b')
axis tight
title('fir2 function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fir2,1)
title('fir2 function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fir2_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (fir2 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fir2_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fir2 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.3- firls Realization
% firls function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_firls = firls(Order_1_FIP_LP,[0 2*Fc_LP/fs 2*Fc_LP/fs 1],[1 1 0 0],[10,1000]);
S_1_FIR_LP_firls_OUT = filter(H_1_FIR_LP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_firls,1)
title('firls function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.4- firpm Realization
% firpm function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_firpm = firpm(Order_1_FIP_LP,[0 2*Fc_LP/fs 4*Fc_LP/fs 1],[1 1 0 0],[10,1000]);
S_1_FIR_LP_firpm_OUT = filter(H_1_FIR_LP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_firpm,1)
title('firpm function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.5- fircls Realization
% fircls function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fircls = fircls(Order_1_FIP_LP,[0 2*Fc_LP/fs 1],[1 0],[1.01,0.01],[0.99,-0.01]);
S_1_FIR_LP_fircls_OUT = filter(H_1_FIR_LP_fircls,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fircls,'filled','b')
axis tight
title('fircls function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fircls,1)
title('fircls function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fircls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (fircls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fircls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fircls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.6- fircls1 Realization
% fircls1 function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_fircls1 = fircls1(Order_1_FIP_LP,2*Fc_LP/fs,0.01,0.001);
S_1_FIR_LP_fircls1_OUT = filter(H_1_FIR_LP_fircls1,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_fircls1,'filled','b')
axis tight
title('fircls1 function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_fircls1,1)
title('fircls1 function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_fircls1_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (fircls1 Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_fircls1_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (fircls1 Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.8- cfirpm Realization
% cfirpm function Design Ⅰ type FIR low pass filter
H_1_FIR_LP_cfirpm = cfirpm(Order_1_FIP_LP,[0 2*Fc_LP/fs 4*Fc_LP/fs 1],[1 1 0 0],[10,1000],"even");
S_1_FIR_LP_cfirpm_OUT = filter(H_1_FIR_LP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_LP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR low pass filter Impulse response ')
figure;
freqz(H_1_FIR_LP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR low pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_LP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR low pass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_LP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR low pass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
3.2、 Bandpass filter
take 2.2 The order in the section can be changed to an odd number , No more detailed codes are posted here .
4、Ⅲ type FIR filter
4.1、 Bandpass filter
%% ---- ---- ---- Ⅲ type Linear phase FIR filter ( Bandpass ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 2.5e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% Band pass filter parameter index
Fc_1_BP = 2e6; % Cut off frequency 1 Company :Hz
Fc_2_BP = 3e6; % Cut off frequency 1 Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% FIR Design
% -1- Bandpass filter
% Uniform parameters
Order_1_FIP_BP = 32; % Ⅰ type FIR Bandpass filter order
% -1.1- firls Realization
% firls function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_firls = firls(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[1,100,1],"hilbert");
S_1_FIR_BP_firls_OUT = filter(H_1_FIR_BP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_firls,1)
title('firls function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- firpm Realization
% firpm function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_firpm = firpm(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[30,100,10],"hilbert");
S_1_FIR_BP_firpm_OUT = filter(H_1_FIR_BP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_firpm,1)
title('firpm function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- cfirpm Realization
% cfirpm function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_cfirpm = cfirpm(Order_1_FIP_BP,[2*Fc_1_BP/fs 2*Fc_2_BP/fs],@hilbfilt);
S_1_FIR_BP_cfirpm_OUT = filter(H_1_FIR_BP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
5、Ⅳ type FIR filter
5.1、 High pass filter
%% ---- ---- ---- Ⅳ type Linear phase FIR filter ( qualcomm ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 2.5e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% High pass filter parameter index
Fc_1_HP = 1e6; % Stopband cut-off frequency 1 Company :Hz
Fc_2_HP = 3.8e6; % Passband cut-off frequency 1 Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% Ⅳ type FIR Design
% -1- High pass filter
% Uniform parameters
Order_1_FIP_HP = 31; % Ⅰ type FIR High pass filter order
% -1.1- firls Realization
% firls function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_firls = firls(Order_1_FIP_HP,[0 2*Fc_1_HP/fs 2*Fc_2_HP/fs 1],[0 0 1 1],[100,1],"hilbert");
S_1_FIR_HP_firls_OUT = filter(H_1_FIR_HP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_firls,1)
title('firls function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- firpm Realization
% firpm function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_firpm = firpm(Order_1_FIP_HP,[0 2*Fc_1_HP/fs 2*Fc_2_HP/fs 1],[0 0 1 1],[100,1],"hilbert");
S_1_FIR_HP_firpm_OUT = filter(H_1_FIR_HP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_firpm,1)
title('firpm function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- cfirpm Realization
% cfirpm function Design Ⅰ type FIR High pass filter
H_1_FIR_HP_cfirpm = cfirpm(Order_1_FIP_HP,[2*Fc_1_HP/fs 0.99],@hilbfilt);
S_1_FIR_HP_cfirpm_OUT = filter(H_1_FIR_HP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_HP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR High pass filter Impulse response ')
figure;
freqz(H_1_FIR_HP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR High pass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_HP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR High pass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_HP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR High pass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
5.2、 Bandpass filter
%% ---- ---- ---- Ⅳ type Linear phase FIR filter ( Bandpass ) Design Research ---- ---- ----
% Author : Xu Y. B.(CSDN ID : On the road , We're on our way )
% MATLAB RELEASE : 2022a
% summary :
% ---- Linear phase FIR filter species ----
% | type | Order parity | Length parity | symmetry | Feature limitations | Description of available functions |
% |------------------------------------------------------------------------------------------------------------------------|
% | Ⅰ | accidentally | p. | accidentally | nothing |fir1、fir2、firls、firpm、fircls、fircls1、rcosdesign、cfirpm|
% | Ⅱ | p. | accidentally | accidentally | qualcomm 、 Band stop cannot be designed | fir1、fir2、firls、firpm、fircls、fircls1、cfirpm |
% | Ⅲ | accidentally | p. | p. | Only bandpass filters can be designed | firls、firpm、cfirpm |
% | Ⅳ | p. | accidentally | p. | Lowpass 、 Band stop cannot be designed | firls、firpm、cfirpm |
% Ref:
% [1] Qianling et al , Digital signal processing . 2018: Electronic industry press .
% [2] https://ww2.mathworks.cn/help/signal/ug/fir-filter-design.html
%% CLEAR
clc;
clearvars;
close all;
set(0,'defaultfigurecolor','w')
%% Parameter setting area
% system parameter
fs = 10e6; % Sampling rate Company :Hz
f1 = 10e3; % Verify the signal frequency 1 Company :Hz
f2 = 2.5e6; % Verify the signal frequency 2 Company :Hz
A1 = 1; % Verify signal amplitude 1 Company :V
A2 = 2; % Verify signal amplitude 1 Company :V
N = 8192; % Verify signal length
% Band pass filter parameter index
Fc_1_BP = 1e6; % Cut off frequency 1 Company :Hz
Fc_2_BP = 3.8e6; % Cut off frequency 1 Company :Hz
%% Verify signal generation
t = (0:N-1)/fs;
S_VERIFY = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t);
figure;
subplot(211)
plot(t*1e6,S_VERIFY,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title(' Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_VERIFY)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title(' Bilateral amplitude spectrum ')
%% FIR Design
% -1- Bandpass filter
% Uniform parameters
Order_1_FIP_BP = 31; % Ⅰ type FIR Bandpass filter order
% -1.1- firls Realization
% firls function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_firls = firls(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[1,100,1],"hilbert");
S_1_FIR_BP_firls_OUT = filter(H_1_FIR_BP_firls,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_firls,'filled','b')
axis tight
title('firls function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_firls,1)
title('firls function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_firls_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (firls Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_firls_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (firls Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- firpm Realization
% firpm function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_firpm = firpm(Order_1_FIP_BP,[0 1.5*Fc_1_BP/fs 2*Fc_1_BP/fs 1.9*Fc_2_BP/fs 2*Fc_2_BP/fs 1],[0 0 1 1 0 0],[30,100,10],"hilbert");
S_1_FIR_BP_firpm_OUT = filter(H_1_FIR_BP_firpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_firpm,'filled','b')
axis tight
title('firpm function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_firpm,1)
title('firpm function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_firpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (firpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_firpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (firpm Function design ) Output after filtering Bilateral amplitude spectrum ')
% -1.2- cfirpm Realization
% cfirpm function Design Ⅰ type FIR Bandpass filter
H_1_FIR_BP_cfirpm = cfirpm(Order_1_FIP_BP,[2*Fc_1_BP/fs 2*Fc_2_BP/fs],@hilbfilt);
S_1_FIR_BP_cfirpm_OUT = filter(H_1_FIR_BP_cfirpm,1,S_VERIFY);
figure;
stem(H_1_FIR_BP_cfirpm,'filled','b')
axis tight
title('cfirpm function Design Ⅰ type FIR Bandpass filter Impulse response ')
figure;
freqz(H_1_FIR_BP_cfirpm,1)
title('cfirpm function Design Ⅰ type FIR Bandpass filter Frequency response curve ')
figure;
subplot(211)
plot(t*1e6,S_1_FIR_BP_cfirpm_OUT,'b')
axis tight
xlabel(' Time / Microsecond ')
ylabel(' Range /V')
title('Ⅰ type FIR Bandpass filter (cfirpm Function design ) Output after filtering Time domain waveform ')
subplot(212)
plot(linspace(-fs/2,fs/2,N)/1e6,abs(fftshift(fft(S_1_FIR_BP_cfirpm_OUT)))/N*2,'r')
axis tight
xlabel(' frequency / Megahertz ')
ylabel(' Range /V')
title('I type FIR Bandpass filter (cfirpm Function design ) Output after filtering Bilateral amplitude spectrum ')
If you have any questions, you can leave a message in the comment area , See and reply ~~
边栏推荐
猜你喜欢

机组实践实验8——使用CMStudio设计基于基本模型机微程序指令(1)

5月产品升级观察站

Don't mess with full_ Case and parallel_ CASE

自动化测试的局限性你知道吗?

国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?

倍福PLC实现绝对值编码器原点断电保持---bias的使用

Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control

倍福NC轴状态转移图解析

P2393 yyy loves Maths II

Stream learning record
随机推荐
Electron official docs series: Distribution
Stream learning record
HDU 3555 Bomb
[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3
HDU1724[辛普森公式求积分]Ellipse
MySQL 自定义函数时:This function has none of DETERMINISTIC, NO SQL 解决方案
机组实践实验8——使用CMStudio设计基于基本模型机微程序指令(1)
. Net Maui performance improvement
Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
RSS rendering of solo blog system failed
【网络是怎么连接的】第二章(下):一个网络包的接收
UVa11582 [快速幂]Colossal Fibonacci Numbers!
Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"
中国剩余定理模板题 互质与非互质
processing 随机生成线动画
机器学习笔记 - 时间序列的季节性
Electron official docs series: Development
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
The El form item contains two inputs. Verify the two inputs
Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control