📄 fir_top_tb.m
字号:
%---------------------------------------------------------------------------------------------------------
%
% THIS IS A WIZARD GENERATED FILE. DO NOT EDIT THIS FILE!
%
%---------------------------------------------------------------------------------------------------------
% Test Bench For fir_top_mlab Function
% Inpulse Stimulation
clear
data_type=1;
data_width= 12;
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=[363 377 391 405 418 430 441 452 461 471 479 486 493 497 502 506 508 510 511 510 508 506 502 497 493 486 479 471 461 452 441 430 418 405 391 377 363 0 ];
Inp = zeros(300,1);
Inp(1)=max_data;
%Impulse Response Plotting
figure(1);
output = fir_top_mlab(Inp');
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= 12;
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=[363 377 391 405 418 430 441 452 461 471 479 486 493 497 502 506 508 510 511 510 508 506 502 497 493 486 479 471 461 452 441 430 418 405 391 377 363 0 ];
%step Response Plotting
figure(3);
output = fir_top_mlab(step');
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= 12;
random = round((rand(1, 100)-0.5)*(2^data_width-2)-1);
% Make Input Integer
h=[363 377 391 405 418 430 441 452 461 471 479 486 493 497 502 506 508 510 511 510 508 506 502 497 493 486 479 471 461 452 441 430 418 405 391 377 363 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 = fir_top_mlab(int_random);
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 + -