- Minor changes

git-svn-id: http://moon:8086/svn/vhdl/trunk@220 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2009-01-10 19:22:25 +00:00
parent 170a65237b
commit 9c45912627
2 changed files with 52 additions and 25 deletions
+23 -8
View File
@@ -2,7 +2,7 @@
function tb_results()
fa = 100.0;
R = TEXTREAD('ratio.txt');
N = 3;
N = TEXTREAD('nstages.txt');;
M = 1;
fa_dec = fa/R
N_pfir = 63;
@@ -12,18 +12,27 @@ Q_out_dec = TEXTREAD('q_dec.txt')';
I_out_fir = TEXTREAD('i_fir.txt')';
Q_out_fir = TEXTREAD('q_fir.txt')';
I_out_fir = I_out_fir(1:2:length(I_out_fir));
Q_out_fir = Q_out_fir(1:2:length(Q_out_fir));
N_dec = length(I_out_dec)-2*N_pfir;
N_fft_dec = N_dec
N_fft2_dec = N_fft_dec/2;
fft_y2_fir = 2/N_fft_dec*abs(fft(I_out_fir(2*N_pfir+1:N_fft_dec+2*N_pfir).*hann(N_fft_dec)'));
N_fir = length(I_out_fir)-2*N_pfir;
N_fft_fir = N_fir
N_fft2_fir = N_fft_fir/2;
fft_y2_fir = 2/N_fft_fir*abs(fft(I_out_fir(2*N_pfir+1:N_fft_fir+2*N_pfir).*hann(N_fft_fir)'));
pfir_b = sinc(0.2*(-(N_pfir-1)/2:1:(N_pfir)/2));
pfir_b = pfir_b/sum(pfir_b).*blackman(N_pfir)';
I_out_dec = I_out_dec;
Q_out_dec = Q_out_dec;
fft_y2_dec = 2/N_fft_dec*abs(fft(I_out_dec(2*N_pfir+1:N_fft_dec+2*N_pfir).*hann(N_fft_dec)'));
f = (1:N_fft_dec)/N_fft_dec;
g = (R*M)^N;
H = abs(sin(pi*M.*f)./sin(pi.*f/R)).^N;
H = max(fft_y2_fir(1:2))*H ./ g;
wavwrite(0.45*[I_out_fir'-mean(I_out_fir) Q_out_fir'-mean(Q_out_fir)], 8000, 16, 'iq_cfir.wav');
wavwrite(0.45*[I_out_dec'-mean(I_out_dec) Q_out_dec'-mean(Q_out_dec)], 8000, 16, 'iq.wav');
@@ -36,8 +45,14 @@ figure;
cic_plot(M, N, R);
figure;
plot(fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(fft_y2_fir(1:N_fft2_dec+1)), '-', fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(fft_y2_dec(1:N_fft2_dec+1)), '-');
legend('CFIR', 'no CFIR');
subplot(2,1,1)
plot(fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(fft_y2_dec(1:N_fft2_dec+1)), '-', fa/(R*N_fft_dec)*(0:N_fft2_dec),20*log10(H(1:N_fft2_dec+1)), 'r-');
legend('CIC', 'Droop');
xlabel('MHz');
grid;
subplot(2,1,2)
plot(fa/(2*R*N_fft_fir)*(0:N_fft2_fir),20*log10(fft_y2_fir(1:N_fft2_fir+1)), '-');
legend('CFIR');
xlabel('MHz');
grid;
+29 -17
View File
@@ -306,8 +306,6 @@ BEGIN
rfgen_q_out_f <= to_real(rfgen_dout_q);
tb : PROCESS
file RESULT_FREQ: text open write_mode is "ratio.txt";
variable L: line;
BEGIN
@@ -315,8 +313,6 @@ BEGIN
wait for 4*PERIOD;
rst <= '0';
fprint(RESULT_FREQ, L,"%s\n", natural'image(cic_ratio));
wait for 2*PERIOD;
-------------------------------------------
-- Program gains
@@ -353,6 +349,21 @@ BEGIN
wait;
END PROCESS;
tb_param : PROCESS
file RESULT_R: text open write_mode is "ratio.txt";
file RESULT_N: text open write_mode is "nstages.txt";
variable L: line;
BEGIN
-- Wait 100 ns for global reset to finish
wait until rising_edge(clk) and rst = '0';
fprint(RESULT_R, L,"%s\n", natural'image(cic_ratio));
fprint(RESULT_N, L,"%s\n", natural'image(cic_nstages));
wait;
END PROCESS;
tb_fo : PROCESS(clk)
file RESULT_Ii: text open write_mode is "i_in.txt";
file RESULT_Qi: text open write_mode is "q_in.txt";
@@ -363,21 +374,22 @@ BEGIN
variable L: line;
BEGIN
if rising_edge(clk) and fileout_enable = '1' then
if ddc_din_vld = '1' then
fprint(RESULT_Ii, L,"%s\n", REAL'image(to_real(rfgen_dout_i)));
fprint(RESULT_Qi, L,"%s\n", REAL'image(to_real(rfgen_dout_q)));
end if;
if ddc_dout_vld = '1' then
fprint(RESULT_Ifir, L,"%s\n", REAL'image(to_real(ddc_dout_i)));
fprint(RESULT_Qfir, L,"%s\n", REAL'image(to_real(ddc_dout_q)));
end if;
if ddc_dec_vld = '1' then
fprint(RESULT_Idec, L,"%s\n", REAL'image(to_real(ddc_dec_i)));
fprint(RESULT_Qdec, L,"%s\n", REAL'image(to_real(ddc_dec_q)));
if rising_edge(clk) then
if fileout_enable = '1' then
if ddc_din_vld = '1' then
fprint(RESULT_Ii, L,"%s\n", REAL'image(to_real(rfgen_dout_i)));
fprint(RESULT_Qi, L,"%s\n", REAL'image(to_real(rfgen_dout_q)));
end if;
if ddc_dout_vld = '1' then
fprint(RESULT_Ifir, L,"%s\n", REAL'image(to_real(ddc_dout_i)));
fprint(RESULT_Qfir, L,"%s\n", REAL'image(to_real(ddc_dout_q)));
end if;
if ddc_dec_vld = '1' then
fprint(RESULT_Idec, L,"%s\n", REAL'image(to_real(ddc_dec_i)));
fprint(RESULT_Qdec, L,"%s\n", REAL'image(to_real(ddc_dec_q)));
end if;
end if;
end if;
END PROCESS;
END;