From 7bb287e3035005e9b116d3b5b2045061ee94d159 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 23 Mar 2021 15:08:51 +0000 Subject: [PATCH] - added git-svn-id: http://moon:8086/svn/vhdl/trunk@1495 cc03376c-175c-47c8-b038-4cd826a8556b --- lib/radio/ddc/ghdl/tb_results.m | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/radio/ddc/ghdl/tb_results.m diff --git a/lib/radio/ddc/ghdl/tb_results.m b/lib/radio/ddc/ghdl/tb_results.m new file mode 100644 index 0000000..df714b3 --- /dev/null +++ b/lib/radio/ddc/ghdl/tb_results.m @@ -0,0 +1,57 @@ +% Read data +function tb_results() +%fa = 100.0; +fa = textread('fa.txt')/1E6 +R = textread('ratio.txt'); +N = textread('nstages.txt');; +M = 1; +fa_dec = fa/R +N_pfir = 63; + +I_out_dec = textread('i_dec.txt')'; +Q_out_dec = textread('q_dec.txt')'; +I_out_fir = textread('i_fir.txt')'; +Q_out_fir = textread('q_fir.txt')'; + +N_dec = length(I_out_dec)-2*N_pfir; +N_fft_dec = N_dec +N_fft2_dec = N_fft_dec/2; + +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)')); + +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; + +[v, j] = max(fft_y2_dec(1:N_fft2_dec/2)) +H = v*H/H(j); + +audiowrite('iq.wav', 0.5*[I_out_dec' Q_out_dec'], 16000, 'BitsPerSample', 16); +audiowrite('iq_cfir.wav', 0.5*[I_out_fir' Q_out_fir'], 8000, 'BitsPerSample', 16); + +% Output +close all; + +plot(1:length(I_out_dec), I_out_dec, 1:length(Q_out_dec), Q_out_dec); grid; + +figure; +cic_plot(M, N, R); + +figure; +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; +