⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fir_script.m

📁 浮点fir设计工具
💻 M
字号:
%       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. 
% 
%  User: WangQian 
%  Machine: A2D3DF917F70473 (i1586, Windows XP Service Pack 2, 5.01.2600) 
%  Date: Mon May 12 10:45:42 2008 
% 

%Deleting all Accel_TestVector_*.txt files
Accel_DeleteTestVector( 'C:\AccelDSP\AccelWork\FIR\FixedPointC\Accel_TestVector_*.txt' );

quantize( 'open' );
global AccelVerifyFixedPoint;
AccelVerifyFixedPoint = 1;
AccelTestVectorIndex = 1;
Accel_ac_output_port_outdatabuf_1_Buffer = zeros( 200, 1 );
Accel_ac_input_port_indatabuf_1_Buffer = zeros( 200, 1 );
%       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
quantize( 'close' );
for n = 1:NUMSAMPS
    % Call function targeted to hardware
    ac_input_port_indatabuf_1 = indata(n);
    ac_output_port_outdatabuf_1 = fir( ac_input_port_indatabuf_1 );
	Accel_ac_input_port_indatabuf_1_Buffer( AccelTestVectorIndex, 1 ) = ac_input_port_indatabuf_1;
	Accel_ac_output_port_outdatabuf_1_Buffer( AccelTestVectorIndex, 1 ) = ac_output_port_outdatabuf_1;
	AccelTestVectorIndex = AccelTestVectorIndex + 1;
    outdata(n) = ac_output_port_outdatabuf_1;
end
fir;
quantize( 'append' );
Accel_WriteTestVector( 't', quantizer( 'fixed', 'wrap', 'floor', [26, 20] ), Accel_ac_output_port_outdatabuf_1_Buffer, 'C:\AccelDSP\AccelWork\FIR\FixedPointC\Accel_TestVector_outdatabuf' );
Accel_WriteTestVector( 't', quantizer( 'fixed', 'wrap', 'floor', [12, 8] ), Accel_ac_input_port_indatabuf_1_Buffer, 'C:\AccelDSP\AccelWork\FIR\FixedPointC\Accel_TestVector_indatabuf' );
% 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' );
quantize( 'close' );

⌨️ 快捷键说明

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