matlab的滤波器仿真——低通滤波器与插值滤波器
项目里面有用到插值滤波器的场合,用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的滤波器仿真——低通滤波器与插值滤波器的更多相关文章
- MATLAB实现最优低通滤波器的函数
MATLAB实现最优低通滤波器的函数 % Fs --Data rate % Fpass --pass band % Fstop --Cutoff frequencies % Apass ...
- Matlab 瑞利信道仿真
转眼间三月都已经过去一半,一直找不到有什么可以写的,一直想等自己把LTE仿真平台搭好后,再以连载的形式记录下来.但是,后来一想,我必须先做好充分的铺垫,在这过程中也遇到了很多问题,及时留下点什么,也是 ...
- matlab之simulink仿真入门
Matlab Simulink仿真工具的应用 ****Simulink是一个用来对动态系统进行建模.仿真和分析的软件包.使用Simulink来建模.分析和仿真各种动态系统(包含连续系统.离散系统和混合 ...
- Matlab Robotics Toolbox 仿真计算:Kinematics, Dynamics, Trajectory Generation
1. 理论知识 理论知识请参考: 机器人学导论++(原书第3版)_(美)HLHN+J.CRAIG著++贠超等译 机器人学课程讲义(丁烨) 机器人学课程讲义(赵言正) 2. Matlab Robotic ...
- Matlab绘图基础——图形绘制的插值
interp1 %1-D data interpolation interpft %使用fft算法插值 %将原数据x转换到频率域,再逆转换回来更密集的数据采样点 spline %一 ...
- Matlab绘图基础——图形绘制的插值 以及 图像大小的重采样
使用说明:图形绘制时的插值 interp1 %1-D data interpolation interpft %使用fft算法插值 %将原数据x转换到频率域,再逆转换回来更密集的数据采样 ...
- 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., ...
- MATLAB——神经网络sim仿真函数
- Matlab 高斯_拉普拉斯滤波器处理医学图像
前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...
随机推荐
- oracle 锁表查询与解锁
查询锁住的表 SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,s.terminal, ...
- Windows下Nginx的安装与配置
Nginx ("engine x") 是一款高性能的,轻量级的HTTP Web 服务器 和 反向代理服务器及电子邮件 IMAP/POP3/SMTP 代理服务器. Nginx 是由俄 ...
- PEP 8
官方文档: PEP 8 :Style Guide for Python Code 部分翻译: http://www.blogjava.net/lincode/archive/2011/02/02/34 ...
- ubuntu更新命令点点滴滴
ubuntu更新命令点点滴滴 一些非root的更新命令: sudo: sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一 ...
- Todo List
Contest 11.13 2016ACM/ICPC亚洲区青岛站(5/13, solved 7/13) Training 11.06 2016年中国大学生程序设计竞赛(合肥)(solved 6/10) ...
- JavaScript中reduce()方法
原文 http://aotu.io/notes/2016/04/15/2016-04-14-js-reduce/ JavaScript中reduce()方法不完全指南 reduce() 方法接收 ...
- compile vim with lua & python support
vim在macosx 10.9默认没有带lua和python支持,因为装的有些插件是lua写的,有些是python写的,运行不起来,于是决定自己编译一个,下载vim源码,执行以下命令就可以编译vim: ...
- matchesSelector 匹配选择器表达式sizzle的实现
Sizzle.matchesSelector = function( node, expr ) { return Sizzle( expr, null, null, [node] ).leng ...
- o-sync-and-o-direct
https://lwn.net/Articles/457667/ https://lwn.net/Articles/457667/ https://lwn.net/Articles/457667/ h ...
- OSX unable to write 'random state'
openssl ca -gencrl -config ./config/openssl.cnf -out ./CA/crl/cacrl.pem -passin pass:'password' unab ...