mat_filt_plot.m

来自「FPGA开发光盘各章节实例的设计工程与源码」· M 代码 · 共 51 行

M
51
字号
%-----------------------算法的matlab仿真----------------------%
%           f1=150;                                                             %
%           f2=330;                                                             %
%           fs=1000;                                                            %
%           fir_coef=0.5;                                                      %
%           i=3.1415926;                                                     %    
%           dets=1/fs;                                                          %
%           fp=fir_coef*fs/2;                                                 %    
%--------------------------------------------------------------------%

disp('%--------滤波算法的 Matlab 仿真结果-------%');

indata_plot;

fid=fopen('filter.vec','r');
[data_in]=fscanf(fid,'%d',[1,inf]);
fclose(fid);

fir_coef=0.5;
fs=1000;
dets=1/fs;
%-----------------------低通滤波----------------------%
b=fir1(15,fir_coef);
b32767=b*32767*0.5;
for j=16:161
    y(j-15)=0;
    for k=1:16
        y(j-15)=y(j-15)+b32767(k)*data_in(j-k+1);
    end;
end;
%-------------绘制滤波后的时域和频域图---------%
t=0:145;
t=t*dets;
subplot(2,2,3);
plot(t,y*2/32767/1024,'-r');
axis([0,0.1,-2,2])
title ('滤波后的时域图','fontsize',8);
xlabel ('时间t(秒)','fontsize',8);
ylabel ('幅度y','fontsize',8);

subplot(2,2,4);
stem(abs(fft(y*2/32767/1024)),'*r');
axis([0,80,0,80])
title  ('滤波后的频域图','fontsize',8);
xlabel ('频率(赫兹)','fontsize',8);
ylabel ('幅度Y','fontsize',8);




        

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?