当前位置:网站首页>Implementation of FIR filter based on FPGA (1) - using fir1 function design
Implementation of FIR filter based on FPGA (1) - using fir1 function design
2022-08-08 13:33:00 【nanyou scumbag】
文章目录
前言
在FPGAOr other hardware platforms according to the required structure design to meet the requirementsFIR滤波器,The key is to design the unit impulse response of the filter,或者说是FIRThe weighting coefficients of the delay units at all levels of the filter,This step is herematlabimplemented in the design,So the first thing to do is how to be therematlabThe unit impulse response of the filter that meets the requirements is designed.本篇文章采用fir1The function design filter related parameters.
一、函数功能
matlab中的fir1函数可以设计低通、带通、高通、Bandstop and other types of strictly linear phaseFIR滤波器,fir1The function adopts the window function design method.
fir1The form of the function
b=fir1(n,wn)
b=fir1(n,wn,'ftype')
b=fir1(n,wn,'ftype',window)
b=fir1(...,'noscale')
The meaning of each parameter expression is as follows
- b:返回的FIRFilter unit impulse response,The impulse response is even symmetric,长度为n+1
- n:滤波器的阶数,The designed filter length is n+1
- wn:滤波器的截止频率,wn的取值范围为0<wn<Fs/2(Fs为采样频率),
- ftype:Make sure the design is low pass(low)、高通(high)、带阻(stop)、带通滤波器(bandpass),当wn是一个数值,Then the cutoff frequency is expressed as wnlow-pass or high-pass filter,取决于ftype的选择;当wnare two numbers,Then it represents a band-stop or band-pass filter;如果wnis a vector of numbers,则表示根据ftypeThe value of , designs filters with multiple passband or stopband ranges,ftype为DC-1,Indicates that the first frequency band of the design is the passband,ftype为DC-0,Indicates that the first frequency band of the design is the stopband
- window:Specifies the window function to use,默认为Hamming海明窗,There are also commonly used Hanning windows(Hanning)、Brackman window(Blackman)、凯塞窗(Kaiser),可以在matlab中输入help window command to view the names of various window functions
- noscale:Specifies whether to normalize the magnitude of the filter
二、Simple case of functions
To design a normalized cutoff frequency of 0.5,阶数为13Hamming window low-pass filter
b=fir1(13,0.5)
h=20*log(abs(fft(b)))/log(10)
plot(h)
The unit impulse response of the filter and the amplitude-frequency response diagram of the filter can be obtained
三、采用fir1A case of function for filter design
eg:Hamming windows are used,The design lengths are respectively41low pass(截止频率为200Hz)、高通(截止频率为200Hz)、带通(通带为200-400Hz)、带阻(阻带为200-400Hz的滤波器),采样频率为2000Hz,Plot the impulse response and the amplitude-frequency response
N=41; %滤波器长度
fs=2000; %采样频率
%Eigenfrequency of various filters
fc_lpf=200;
fc_hpf=200;
fp_bandpass=[200 400];
fc_stop=[200 400];
%at half the sampling frequency,Normalize the frequencies
wn_lpf=fc_lpf*2/fs;
wn_hpf=fc_hpf*2/fs;
wn_bandpass=fp_bandpass*2/fs;
wn_stop=fc_stop*2/fs;
%采用fir1函数设计FIR滤波器
b_lpf=fir1(N-1,wn_lpf);
b_hpf=fir1(N-1,wn_hpf,'high');
b_bandpass=fir1(N-1,wn_bandpass,'bandpass');
b_stop=fir1(N-1,wn_stop,'stop');
%Find the magnitude-frequency response of the filter
m_lpf=20*log(abs(fft(b_lpf)))/log(10);
m_hpf=20*log(abs(fft(b_hpf)))/log(10);
m_bandpass=20*log(abs(fft(b_bandpass)))/log(10);
m_stop=20*log(abs(fft(b_stop)))/log(10);
%Set the abscissa unit of the amplitude-frequency response to Hz
x_f=[0:(fs/length(m_lpf)):fs/2];
%Plot the unit impulse response
subplot(421);
stem(b_lpf);xlabel('n');ylabel('h(n)');title('Unity impulse response of the low pass filter');
subplot(423);
stem(b_hpf);xlabel('n');ylabel('h(n)');title('Unity impulse response of the high pass filter');
subplot(425);
stem(b_bandpass);xlabel('n');ylabel('h(n)');title('Unity impulse response of the bandpass filter');
subplot(427);
stem(b_stop);xlabel('n');ylabel('h(n)');title('Unity impulse response of the bandstop filter');
%Plot the amplitude-frequency response curve
subplot(422);
plot(x_f,m_lpf(1:length(x_f)));xlabel('频率(Hz)');ylabel('幅度(dB)');title('Amplitude-frequency response of a low-pass filter');
subplot(424);
plot(x_f,m_hpf(1:length(x_f)));xlabel('频率(Hz)');ylabel('幅度(dB)');title('Amplitude-frequency response of a high-pass filter');
subplot(426);
plot(x_f,m_bandpass(1:length(x_f)));xlabel('频率(Hz)');ylabel('幅度(dB)');title('Amplitude-frequency response of a bandpass filter');
subplot(428);
plot(x_f,m_stop(1:length(x_f)));xlabel('频率(Hz)');ylabel('幅度(dB)');title('Amplitude-frequency response of a band-stop filter');
四、Comparison of the performance of various window functions
Rectangular windows have the narrowest transition band,But its side lobe peak is the highest,Stopband attenuation is minimal,compared to the Hanning window,The transition zone of the Hamming window is the same as that of the Hanning window,But its side lobe peak is smaller,And the stopband attenuation is greater,So the performance is better than the Hanning window;When the Kaiser window function is usedβ取7.856时,compared to the Blackman window,表现出了更好的性能
eg:Various window functions are used,The cut-off frequencies are respectively designed as 200Hz、采样频率为2000Hz的FIR低通滤波器,滤波器长度为81阶,And draw the amplitude frequency response curve of each filter
N=81; %滤波器长度
fs=2000; %采样频率
fc=200; %低通滤波器的截止频率
%Generate various window functions
w_rect=rectwin(N)';
w_hann=hann(N)';
w_hamm=hamming(N)';
w_blac=blackman(N)';
w_kais=kaiser(N,7.856)';
%采用fir1函数设计FIR滤波器
b_rect=fir1(N-1,fc*2/fs,w_rect);
b_hann=fir1(N-1,fc*2/fs,w_hann);
b_hamm=fir1(N-1,fc*2/fs,w_hamm);
b_blac=fir1(N-1,fc*2/fs,w_blac);
b_kais=fir1(N-1,fc*2/fs,w_kais);
%Find the magnitude-frequency response of the filter
m_rect=20*log(abs(fft(b_rect,512)))/log(10);
m_hann=20*log(abs(fft(b_hann,512)))/log(10);
m_hamm=20*log(abs(fft(b_hamm,512)))/log(10);
m_blac=20*log(abs(fft(b_blac,512)))/log(10);
m_kais=20*log(abs(fft(b_kais,512)))/log(10);
%Set the abscissa unit of the amplitude-frequency response to Hz
x_f=[0:(fs/length(m_rect)):fs/2];
%Only the amplitude-frequency response of the positive frequency part is displayed
m1=m_rect(1:length(x_f));
m2=m_hann(1:length(x_f));
m3=m_hamm(1:length(x_f));
m4=m_blac(1:length(x_f));
m5=m_kais(1:length(x_f));
%Plot the amplitude-frequency response curve
plot(x_f,m1,'.',x_f,m2,'*',x_f,m3,'x',x_f,m4,'--',x_f,m5,'-');
xlabel('频率(Hz)');ylabel('幅度(dB)');
legend('矩形窗','汉宁窗','海明窗','Brackman window','凯塞窗');
grid;
从仿真结果看,The Kaiser window function has better performance under the same filter order,在设计的200Hzat the cutoff frequency,Amplitude decay is -6.4dB,滤波器的3dBThe bandwidth is actually approx184.3Hz
总结
本篇文章是FPGA设计FIRThe first part of the filter article,虽然matlab自带的Filter Design & AnalysisFilters can be designed directly using the graphical interface,But there are often times when writing filters in code can solve problems more flexibly.
边栏推荐
猜你喜欢
【C语言】自定义类型详解:结构体、枚举、联合
C language small project - complete code of minesweeper game (recursive expansion + selection mark)
2022-08-05
深析C语言的灵魂 -- 指针
Jenkins - 持续集成介绍(1)
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
基于FPGA的FIR滤波器的实现(1)—采用fir1函数设计
MySQL database storage series (5) the InnoDB storage format
【C语言】文件相关操作
The use of string function, character function, memory function and its analog implementation
随机推荐
Three classic topics in C language: three-step flip method, Young's matrix, and tossing and dividing method
The maximum validity period of an SSL certificate is 13 months. Is it necessary to apply for multiple years at a time?
In-depth analysis of the soul of C language -- pointer
服务器配置——Linux系统安装Redis
Program Environment and Preprocessing
处理器的调试接口
Pointer and array written test questions analysis
哈佛大学砸场子:DALL-E 2只是「粘合怪」,生成正确率只有22%
程序环境和预处理
又一个千亿市场,冰淇淋也成了创新试验田
The most complete JVM performance tuning in history: thread + subsystem + class loading + memory allocation + garbage collection
What is the IP SSL certificate, how to apply for?
北京 北京超大旧货二手市场开集了,上千种产品随便选,来的人还真不少
textarea 禁止拖拽
TS+Hooks二次封装antd Modal,实现可拖拽
xxd命令(反编译、二进制文件转十六进制文件)
logistic回归模型—基于R
changes not staged for commit 解决办法
C语言小项目 -- 通讯录(静态版+动态版+文件版)
牛 plus,多层嵌套动态 JSON 该如何解析总结