项目里面有用到插值滤波器的场合,用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. 2016年中国大学生程序设计竞赛(合肥)-重现赛1001 HDU 5961

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  2. 浏览器 HTTP 协议缓存机制详解

    最近在准备优化日志请求时遇到了一些令人疑惑的问题,比如为什么响应头里出现了两个 cache control.为什么明明设置了 no cache 却还是发请求,为什么多次访问时有时请求里带了 etag, ...

  3. SpringMVC中使用Cron表达式的定时器

    SpringMVC中使用Cron表达式的定时器 cron(定时策略)简要说明 顺序: 秒 分 时 日 月 星期 年份 (7个参数,空格隔开各个参数,年份非必须参数) 通配符: , 如果分钟位置为* 1 ...

  4. TableView分割线从顶端开始

    如果什么都不设置的话 分割线是从cell.textlabel处开始的 如果加上 [_myTableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0) ...

  5. 初识Java-分数录入系统

    package classTest; import java.util.Scanner; public class scoreArrangement { /**  * 选择界面(main)  */ p ...

  6. eclipse修改web项目部署路径

    Eclipse中用Tomcat发布的Web项目,更改其部署路径 我的Eclipse的工作目录是D:/workspace 先配置Tomcat 选择你的tomcat版本 点击next 这里先不要把项目添加 ...

  7. 为windows应用程序提供托盘图标

    1>包含头文件 #include "Shellapi.h"   2>相关结构体和函数:     NOTIFYICONDATA     WINSHELLAPI BOOL ...

  8. Linux破解root密码

    实验环境                 虚拟机软件:VMware Workstation                 操作系统:Read Hat Enteprise 6.3      1.破解r ...

  9. LeetCode-Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. public ...

  10. 如何用ABBYY FineReader识别图片中的文本

    ABBYY FineReader 12是一款OCR光学字符识别软件,能够快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索的文本,让电脑处理更具效率,摆脱从前的烦恼,告别耗时费力 ...