📄 fir321_tb.m
字号:
%---------------------------------------------------------------------------------------------------------
%
% THIS IS A WIZARD GENERATED FILE. DO NOT EDIT THIS FILE!
%
%---------------------------------------------------------------------------------------------------------
% Test Bench For fir321_mlab Function
% Inpulse Stimulation
clear
data_type=1;
data_width= 16;
switch data_type
case 1
%set max for signed
max_data = 2^(data_width-1)-1;
case 2
%set max for unsigned
max_data = 2^data_width-1;
end
h=[1150 -1304 -3632 -4293 -2173 2794 9445 15742 19562 19562 15742 9445 2794 -2173 -4293 -3632 -1304 1150 0 ];
Inp = zeros(300,1);
Inp(1)=max_data;
%Impulse Response Plotting
figure(1);
output = fir321_mlab(Inp',h);
sz = size(output);
max_x = max(sz);
xline = linspace (0, max_x - 1, max_x);
plot (xline, output,'r');
title ('Time Display of Impulse Response');
grid on;
zoom on;
outfile1 = fopen('imp_in.txt','w');
fprintf(outfile1, '%d\n', Inp);
fclose(outfile1);
outfile1 = fopen('m_Inpulse_out.txt','w');
fprintf(outfile1, '%d\n', output);
fclose(outfile1);
% Frequency Domain Plotting
to_plot = output;
figure(2);
freqdat = fft(to_plot);
absdat = abs(freqdat);
maxdat = max (absdat);
logdat = 20*log10(absdat);
sz = size(to_plot);
numpts = max(sz);
freq_res = 1/numpts;
xline = linspace (0, ( (1/2)- freq_res ), round(numpts/2) );
plot (xline, logdat(1: round(numpts/2) ), 'b');
title ('Frequency Display of Impulse Response');
grid on;
zoom on;
xlabel ('Frequency');
ylabel ('Magnitude - dB');
% Step Stimulation
clear
data_type=1;
data_width= 16;
switch data_type
case 1
%set max for signed
max_data = 2^(data_width-1)-1;
case 2
%set max for unsigned
max_data = 2^data_width-1;
end
step= zeros(300,1);
for i=1:280
step(i) = max_data;
end;
h=[1150 -1304 -3632 -4293 -2173 2794 9445 15742 19562 19562 15742 9445 2794 -2173 -4293 -3632 -1304 1150 0 ];
%step Response Plotting
figure(3);
output = fir321_mlab(step',h);
sz = size(output);
max_x = max(sz);
xline = linspace (0, max_x - 1, max_x);
plot (xline, output,'r');
title ('Time Display of Step Response');
grid on;
zoom on;
outfile2 = fopen('step_in.txt','w');
fprintf(outfile2, '%d\n', step);
fclose(outfile2);
outfile2 = fopen('m_Step_out.txt','w');
fprintf(outfile2, '%d\n', output);
fclose(outfile2);
% Frequency Domain Plotting
to_plot = output;
figure(4);
freqdat = fft(to_plot);
absdat = abs(freqdat);
maxdat = max (absdat);
logdat = 20*log10(absdat);
sz = size(to_plot);
numpts = max(sz);
freq_res = 1/numpts;
xline = linspace (0, ( (1/2)- freq_res ), round(numpts/2) );
plot (xline, logdat(1: round(numpts/2) ), 'b');
title ('Frequency Display of Step Response');
grid on;
zoom on;
xlabel ('Frequency');
ylabel ('Magnitude - dB');
% Ramdom Input
clear
data_type=1;
data_width= 16;
random = round((rand(1, 100)-0.5)*(2^data_width-2)-1);
% Make Input Integer
h=[1150 -1304 -3632 -4293 -2173 2794 9445 15742 19562 19562 15742 9445 2794 -2173 -4293 -3632 -1304 1150 0 ];
int_random = round(random);
%Input overflow check
switch data_type
case 1
%set max/min for signed
max_data = 2^(data_width-1)-1;
min_data = -max_data;
case 2
%set max/min for unsigned
max_data = 2^data_width-1;
min_data = 0;
end
% Saturating Input Value
a_in = find (int_random > max_data);
b_in = find (int_random < min_data);
if (~isempty(a_in)|~isempty(b_in))
lenax = length (a_in);
lenbx = length (b_in);
for i = 1:lenax
int_random(a_in(i)) = max_data;
end
for i = 1:lenbx
int_random(b_in(i)) = min_data;
end
end
%Random Response Plotting
figure(5);
output = fir321_mlab(int_random,h);
sz = size(output);
max_x = max(sz);
xline = linspace (0, max_x - 1, max_x);
plot (xline, output,'r');
title ('Time Display of random Response');
grid on;
zoom on;
outfile3 = fopen('rand_in.txt','w');
fprintf(outfile3, '%d\n', int_random);
fclose(outfile3);
outfile3 = fopen('m_Random_out.txt','w');
fprintf(outfile3, '%d\n', output);
fclose(outfile3);
% Frequency Domain Plotting
to_plot = output;
figure(6);
freqdat = fft(to_plot);
absdat = abs(freqdat);
maxdat = max(absdat);
logdat = 20*log10(absdat);
sz = size(to_plot);
numpts = max(sz);
freq_res = 1/numpts;
xline = linspace (0, ( (1/2)- freq_res ), round(numpts/2) );
plot (xline, logdat(1: round(numpts/2) ), 'b');
title ('Frequency Display of Random Response');
grid on;
zoom on;
xlabel ('Frequency');
ylabel ('Magnitude - dB');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -