fir_script.m

来自「浮点fir设计工具」· M 代码 · 共 81 行

M
81
字号
%       AccelDSP 9.1.00 build 868 Production, compiled Feb 16 2007 
% 
%    THIS IS UNPUBLISHED, LICENSED SOFTWARE THAT IS THE CONFIDENTIAL 
%        AND PROPRIETARY PROPERTY OF XILINX OR ITS LICENSORS 
% 
%      Copyright(c) Xilinx, Inc., 2000-2007, All Rights Reserved. 
%   Reproduction or reuse, in any form, without the explicit written 
%          consent of Xilinx, Inc., is strictly prohibited. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Description : General FIR filter design                                     %
%%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all

% Define constants
NUMTAPS = 16;    % Filter order
NUMSAMPS = 200;  % Number of input vectors
Fs = 44100;      % Sampling frequency in Hz
Fc = 2000;       % Filter cutoff frequency in Hz
SINEFREQ = 1000; % Input sine frequency in Hz

Wn = 2*Fc/Fs;

% To generate and save new coefficients, uncomment
% the following two commands.  Verify -floatingpoint
% must be re-run to update the coefficients before
% generating new hardware.
%
%coeff = FIR1(NUMTAPS-1,Wn,'low'); % Can be low or high
%save coefficients.txt coeff -ascii

% Create input data
data = 5 * sin( 2 * pi * [1:NUMSAMPS] / (Fs/SINEFREQ));
noise = 2*(rand(1,NUMSAMPS)-0.5);

indata = data + noise;

% Apply filter to each input sample
for n = 1:NUMSAMPS
    
  % Call function targeted to hardware
  outdata(n) = fir(indata(n));
  
end

% Plot input signal components
figure(1);
subplot(2,1,1);
plot(data);
axis([1 NUMSAMPS -6 6]);
title(['Input = ',num2str(SINEFREQ),' Hz']);
subplot(2,1,2);
plot(noise);
axis([1 NUMSAMPS -6 6]);
title('Noise');

% Plot input and output of filter
figure(2);
subplot(2,1,1);
plot(indata);
axis([1 NUMSAMPS -6 6]);
title('Combined Input');
subplot(2,1,2);
plot(outdata);
axis([1 NUMSAMPS -6 6]);
title('Filtered Output');

% Plot PSD of input and output
figure(3);
[Pin,Hin]=aw_psd(indata,NUMSAMPS,Fs);
[Pout,Hout]=aw_psd(outdata,NUMSAMPS,Fs);
hold off
plot(Hin,10*log10(Pin))
hold on
plot(Hout,10*log10(Pout),'r')
grid on
title('Input and Output PSD');
legend('Input','Output');

⌨️ 快捷键说明

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