项目里面有用到插值滤波器的场合,用matlab做了前期的滤波器性能仿真,产生的滤波器系数保存下来输入到FPGA IP中使用即可。

下面是仿真的代码

 % clear all
close all Nx = ;
Tx = ;
nx = :Nx-;
x = sin(*pi**nx/Tx);
L = ;
% Ny = L * Nx;
% ny = :Ny-;
% yi = zeros(,Ny);
% yi(:L:Ny) = x;
% figure;
% stem(yi); Fst1 = 0.05;
Fp1 = 0.09;
Fp2 = 0.11;
Fst2 = 0.15;
Ast1 = ;
Ap = 0.01;
Ast2 = ;
% bandpass filter works well, try lowpass to check whether DC signal affects pm
% hband = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2);
hband = fdesign.lowpass('Fp,Fst,Ap,Ast',Fp2,Fst2,Ap,Ast2);
Hband = design(hband);
info(Hband); %show filter info Fp = 0.08 %pass band corner freq
Fst = 0.24 %stop band corner freq
Ap = 0.01; %pass band attenuation(dB)
Ast = 80.0; %stop band attenuation(dB)
h1 = fdesign.interpolator(L,'lowpass',Fp,Fst,Ap,Ast);
Href = design(h1);
info(Href); %show filter info
fvtool(Hband,,Href,); %show freq response
title('lowpass filter & interpolator filter');
legend('lowpass filter','interpolator filter'); % import sample_dara
a=dlmread('1.prn');%以字符形式打开文件
v1=a(:,); %16进制转化为10进制数,存储进v1矩阵
figure;
subplot(,,);
plot(v1);
v2 = filter(Hband,v1);
subplot(,,);
plot(v2);
y = filter(Href,v2);
subplot(,,);
plot(y);
% b=dlmread('2.prn');%以字符形式打开文件
% y=b(:,); %16进制转化为10进制数,存储进v1矩阵 fft_analysis_func(v2,//, );
legend('lowpass filter');
fft_analysis_func(y,*L//, );
legend('interpolator filter'); %axis([ - ]) %zoom-in to 25MHz
%generating the coe file
ref_filter = Hband.Numerator;
gen_coe_rad10(Hband.Numerator,'lowpass_filter_rad10.coe');
ref_filter = Href.Numerator;
gen_coe_rad10(Href.Numerator,'inter_filter_rad10.coe');

代码中用到了两个函数

function fft_analysis_func(x, fs, adc_width)

%The following program code plots the FFT spectrum of a desired test tone. Test tone based on coherent sampling criteria, and
%computes SNR, SINAD, THD and SFDR.
%This program is believed to be accurate and reliable. This program may get altered without prior notification.; %fid=fopen('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','r');
%numpt=input('Number of Points in FFT? ');
%fclk=input('Sampling Frequency (MHz)? ');
%numbit=input('ADC Resolution (bits)? '); % numpt=length(x);
numpt = ;
fclk=fs;
numbit=adc_width; v1 = x(:numpt); code=v1'; %Warning: ADC output may be clipping - reduce input amplitude
if (max(code)==2^numbit-1) | (min(code)==0)
disp('WARNING: ADC OUTPUT MAYBE CLIPPING - CHECK INPUT AMPLITUDE!');
end Dout=code;
Voltage=Dout./((2^numbit-1)/2)*(0.5); Doutw=(Dout').*blackmanharris(numpt); %add Minimum -term Blackman-Harris window
Dout_spect=fft(Doutw);
Dout_dB=*log10(abs(Dout_spect)); figure;
maxdB=max(Dout_dB(:numpt/)); %numpt points FFT result in numpt/ points spectrum %计算距离满量程的幅度差
max_voltage=max(Voltage);
delta_amplitude=*log10(max_voltage/0.5); %full scale voltage amplitude is .5v plot([:numpt/-].*fclk/numpt,Dout_dB(:numpt/)-maxdB+delta_amplitude);
% plot([:numpt-].*fclk/numpt,Dout_dB(:numpt)-maxdB+delta_amplitude);
grid on;
title('SINGLE TONE FFT PLOT');
xlabel('ANALOG INPUT FREQUENCY (MHz)');
ylabel('AMPLITUDE (dBfs)'); hold off;
function gen_coe_rad10(filt_num, fileName)
%max number of coefficients
num_coeffs = numel(filt_num)
fileId = fopen(fileName,'w');
%header if COE file
fprintf(fileId,'radix = 10;\n');
% first coefficient
fprintf(fileId,'coefdata = \n');
for i = : num_coeffs-
fprintf(fileId,'%8.9f,\n',filt_num(i));
end
% last coefficient
fprintf(fileId,'%8.9f;',filt_num(num_coeffs));
fclose(fileId);
end

仿真出的结果如下:

产生了用于滤波器的系数:

 radix = ;
coefdata =
-0.001219138,
-0.002838337,
-0.005111633,
-0.007197151,
-0.007796326,
-0.005351278,
0.001364815,
0.012476464,
0.026308774,
0.039101106,
0.045443072,
0.039549550,
0.017241585,
-0.021849408,
-0.072532419,
-0.123501332,
-0.158497326,
-0.159275461,
-0.109905781,
-0.001430991,
0.164384860,
0.373413481,
0.600371089,
0.812911647,
0.977825248,
1.067924092,
1.067924092,
0.977825248,
0.812911647,
0.600371089,
0.373413481,
0.164384860,
-0.001430991,
-0.109905781,
-0.159275461,
-0.158497326,
-0.123501332,
-0.072532419,
-0.021849408,
0.017241585,
0.039549550,
0.045443072,
0.039101106,
0.026308774,
0.012476464,
0.001364815,
-0.005351278,
-0.007796326,
-0.007197151,
-0.005111633,
-0.002838337,
-0.001219138;

matlab的滤波器仿真——低通滤波器与插值滤波器的更多相关文章

  1. MATLAB实现最优低通滤波器的函数

    MATLAB实现最优低通滤波器的函数 % Fs     --Data rate % Fpass  --pass band % Fstop  --Cutoff frequencies % Apass  ...

  2. Matlab 瑞利信道仿真

    转眼间三月都已经过去一半,一直找不到有什么可以写的,一直想等自己把LTE仿真平台搭好后,再以连载的形式记录下来.但是,后来一想,我必须先做好充分的铺垫,在这过程中也遇到了很多问题,及时留下点什么,也是 ...

  3. matlab之simulink仿真入门

    Matlab Simulink仿真工具的应用 ****Simulink是一个用来对动态系统进行建模.仿真和分析的软件包.使用Simulink来建模.分析和仿真各种动态系统(包含连续系统.离散系统和混合 ...

  4. Matlab Robotics Toolbox 仿真计算:Kinematics, Dynamics, Trajectory Generation

    1. 理论知识 理论知识请参考: 机器人学导论++(原书第3版)_(美)HLHN+J.CRAIG著++贠超等译 机器人学课程讲义(丁烨) 机器人学课程讲义(赵言正) 2. Matlab Robotic ...

  5. Matlab绘图基础——图形绘制的插值

    interp1   %1-D data interpolation interpft  %使用fft算法插值     %将原数据x转换到频率域,再逆转换回来更密集的数据采样点 spline    %一 ...

  6. Matlab绘图基础——图形绘制的插值  以及 图像大小的重采样

    使用说明:图形绘制时的插值 interp1   %1-D data interpolation interpft  %使用fft算法插值     %将原数据x转换到频率域,再逆转换回来更密集的数据采样 ...

  7. matlab 高阶(三)—— 插值(fft、)

    1. FFT 插值 y = interpft(x,n) y = [0, .5, 1., 1.5, 2., 1.5, 1., .5, 0, -.5, -1, -1.5, -2., -1.5, -1., ...

  8. MATLAB——神经网络sim仿真函数

  9. Matlab 高斯_拉普拉斯滤波器处理医学图像

    前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...

随机推荐

  1. ABAP下载txt文件

    IF NOT DOWN_F[] IS INITIAL.    CASE DOWN_MODE . "下载模式是放在所选路径下的.TXT文档中      WHEN 'X' .        CA ...

  2. handler和Timer的用法

    final Handler handler = new Handler(){public void handleMessage(Message msg){if (msg.what == 0x123){ ...

  3. Java中对数据库的查询和增加内容

    先添加jar包 查询数据库中的信息 加载访问驱动,com.mysql.jdbc.Driver--连接到库--写SQL语句 用while循环把表中的信息从第一条到最后一条打印出来,括号中的数字是代表数据 ...

  4. Linux crontab命令格式与详情例子

    基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...

  5. Android——播放器和图片轮播

    layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  6. ListView的item里面控件文本颜色修改

    @SuppressLint("InflateParams") @Override public View getChildView(int groupPosition, int c ...

  7. Linear Algebra lecture6 note

    Vector spaces and subspaces Column space of A solving Ax=b Null space of A   Vector space requiremen ...

  8. 浅谈声明与定义的区别 分类: C/C++ 2015-06-01 15:08 157人阅读 评论(4) 收藏

    以下代码使用平台是VS2012. 清楚明白声明与定义是一名合格的程序猿的基本要求. 本人认为,C++编码过程中谈及"声明"和"定义"是因为我们要使用一个变量.类 ...

  9. 在Visual Studio中设置多核并行编译

    VS是一款非常强大实用的IDE,是在Windows环境下学习编程的首选软件. 有些时候大一点的工程项目编译要耗时挺长时间,随便修改一下代码就可能要编译将近一分钟,甚至更多.即便在开启的增量编译的情况下 ...

  10. MYCAT 配置(转)

     server.xml配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mycat:se ...