diff --git a/tb_generation_5ndft.m b/tb_generation_5ndft.m new file mode 100644 index 0000000..de41ec2 --- /dev/null +++ b/tb_generation_5ndft.m @@ -0,0 +1,239 @@ +clear all; +clear; +close all; +rng(1); % random seed +global ns average quantization Q1 Q2 Q3 fs M D sb_nbr Apass Astop dens + +%% Parameter + +ns = 2e6; % Number of Sample +fs = 40e9; % Sampling Frequency +M = 20; % Polyphase factor +D = 8; % Decimator + +sb_nbr = 3; % Sub-band Number in OPFB : 1 -> M + +average = 0; % PSD smoothing : 0 = OFF ; 1 = ON +quantization = 1; % 0 = OFF ; 1 = ON + +Q1 = 6; % DG Quantization +Q2 = 8; % TAP Quantizantion +Q3 = 6; % PFB Quantization + +Apass = 0.25; % Passband Ripple (dB) +Astop = 50; % Stopband Attenuation (dB) +dens = 50; % Density Factor + +%% Input Signal + +bw = fs/M; % OPFB Output Bandwidth + +f1 = bw*(sb_nbr); +f2 = bw*(sb_nbr-0.625+0.25*mod(sb_nbr,M/gcd(M,D))); + +t = 0:1/fs:(ns-1)/fs; +sw1 = 1*sin(2*pi*f1*t); +sw2 = 1*sin(2*pi*f1*t); +noise = randn([1 ns]); +nsw = noise+sw1+sw2; + +% win = hanning(ns); +% if average == 0 +% [PSD, FREQ] = periodogram(nsw,win,ns,fs); +% else +% [PSD, FREQ] = pwelch(nsw,ns/100,[],ns,fs); +% end +% figure; +% MAX = max(10*log(PSD)); +% plot(FREQ/1e9, 10*log(PSD)-MAX); +% title('Real Input signal'); +% xlim([0,fs/1e9]); +% grid on; + +%% Digitizer Anti-aliasing Filter + +f = [0 0.1 0.9 1]; +m = [0 1 1 0]; +b = fir2(1000,f,m); +s_dg_real = conv(noise+sw1,b,'valid'); +s_dg_imag = conv(noise+sw2,b,'valid'); +s_dg_bb = 0*s_dg_real+1i*s_dg_imag; +ns_dg_bb = size(s_dg_bb,2); + +if quantization == 1 + s_dg_bb_fi = fi(s_dg_bb,1,Q1,0); + s_dg_bb = s_dg_bb_fi.data; +end + +win = hanning(ns_dg_bb); +if average == 0 + [PSD, FREQ] = periodogram(s_dg_bb,win,ns_dg_bb,fs); +else + [PSD, FREQ] = pwelch(s_dg_bb,ns_dg_bb/100,[],ns_dg_bb,fs); +end +figure; +MAX = max(10*log(PSD)); +plot(FREQ/1e9, 10*log(PSD)-MAX); +title('Dual complex input signal'); +xlim([0,fs/1e9]); +grid on; + + +%% Oversampled Polyphase Filter Bank + +% All frequency values are in GHz. +Fs = fs/1e9; % Sampling Frequency +Fpass = (1-(1-D/M))*Fs/M; % Passband Frequency +Fstop = Fs/M; % Stopband Frequency +Dpass = 1-10^(-Apass/20); % Passband Ripple +Dstop = 10^(-Astop/20); % Stopband Attenuation + +% Calculate the order from the parameters using FIRPMORD. +[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs), [1 0], [Dpass, Dstop]); +Ndec0 = N; +if (mod(N,M) ~= M-1) + N = N + M-1 - mod(N,M); +end + +% Calculate the coefficients using the FIRPM function. +Hdec0 = firpm(N, Fo, Ao, W, {dens}); + +% Calculate polyphase filter +Hdec0 = fliplr(Hdec0); +len = length(Hdec0); +nrows = len/M; +Hdec0_pol = zeros(M,nrows); +for m=1:M + for i=1:nrows + Hdec0_pol(m,i)=Hdec0(1,(i-1)*M+m); + end +end +if quantization == 1 + Hdec0_pol_fi = fi(Hdec0_pol,1,Q2); + Hdec0_pol = Hdec0_pol_fi.data; +end + +% Demux Input +ns_dg_rs1 = floor((ns_dg_bb-M)/D); +s_dg_rs1 = zeros(M,ns_dg_rs1); +for m=1:M + for i=1:ns_dg_rs1 + s_dg_rs1(m,i) = s_dg_bb(1,(i-1)*D+m); + end +end +s_dg_rs1 = flipud(s_dg_rs1); + +% Circular shifting +s_dg_rs2 = s_dg_rs1; +ns_dg_rs2 = ns_dg_rs1; +% for i = 1:ns_dg_rs2 +% s_dg_rs2(:,i) = flip((s_dg_bb((i-1)*D+1:(i-1)*D+M))'); +% end +for i=1:ns_dg_rs2 + for m=1:M + s_dg_rs2(m,i) = s_dg_rs1(1+mod( (m-1) + mod((i-1)*D,M) ,M),i); + end +end + +% Apply polyphase filter +ns_pol = ns_dg_rs2-(nrows-1); +s_pol = zeros(M,ns_pol); + +for m=1:M + s_pol(m,:) = conv(s_dg_rs2(m,:),Hdec0_pol(m,:),'valid'); +end + +s_pol(:,1:M) = 0*s_pol(:,1:M); +s_pol(10,1:10) = 1i; +s_pol_fi = fi(s_pol,1,19,10); +s_pol = s_pol_fi.data; + +% DFT +s_pol_dft = zeros(M,ns_pol); + +if M == 10 + s_pol_rearranged = [s_pol(1,:); s_pol(3,:); s_pol(5,:); s_pol(7,:); s_pol(9,:); s_pol(2,:); s_pol(4,:); s_pol(6,:); s_pol(8,:); s_pol(10,:)]; +elseif M == 20 + s_pol_rearranged = [s_pol(1,:); s_pol(5,:); s_pol(9,:); s_pol(13,:); s_pol(17,:); s_pol(3,:); s_pol(7,:); s_pol(11,:); s_pol(15,:); s_pol(19,:); s_pol(2,:); s_pol(6,:); s_pol(10,:); s_pol(14,:); s_pol(18,:); s_pol(4,:); s_pol(8,:); s_pol(12,:); s_pol(16,:); s_pol(20,:)]; +end + +%% +for i = 1:M/5 + s_pol_dft(1+5*(i-1):5*i,:) = winograd5(s_pol_rearranged(1+5*(i-1):5*i,:), 8); +end + +%F = fimath('RoundingMethod','Floor','ProductMode','KeepMSB', 'ProductFractionLength',6); +wn5 = fi(exp(-2*1i*pi*[0:4]/10), 1, 8, 6); +wn5 = wn5.data; +wn10 = fi(exp(-2*1i*pi*[0:9]/20), 1, 8, 6); +wn10 = wn10.data; +for i = 1:M/10 + s_pol_dft(1+10*(i-1):10*i, :) = radix2(s_pol_dft(1+10*(i-1):10*i, :), wn5); +end +if M == 20 + s_pol_dft = radix2(s_pol_dft, wn10); +end + +% for i=1:ns_pol +% s_pol_dft(:,i) = fft(s_pol(:,i)); +% end +%s_pol_dft(2:end, :) = flip(s_pol_dft(2:end, :)); +% for i=1:ns_pol +% for p=1:M +% for m=1:M +% s_pol_dft(p,i) = s_pol_dft(p,i) + s_pol(m,i)*exponential(mod((m-1)*(p-1), M)+1); +% end +% end +% end + +tb_input = s_pol_fi.data*2^s_pol_fi.FractionLength; +tb_input = [real(tb_input);imag(tb_input)]; +tb_input = reshape(tb_input, 1, size(tb_input,1)*size(tb_input,2)); +tb_output = fi(s_pol_dft,1,6,4); +tb_output = tb_output.data*2^(4); +tb_output = floor([real(tb_output);imag(tb_output)]); +tb_output = reshape(tb_output, 1, size(tb_output,1)*size(tb_output,2)); + + +%% Sub-band Selection + +sb_nbr = 9; +% +% if sb_nbr < M/2 +% s_pol_sel = s_pol_dft(sb_nbr+1,:)+conj(s_pol_dft(M-sb_nbr+1,:)); +% elseif sb_nbr == M/2 +% s_pol_sel = s_pol_dft(sb_nbr+1,:); +% if sb_nbr < M +% s_pol_sel = -1i*s_pol_dft(sb_nbr+1,:)+conj(-1i*s_pol_dft(M-sb_nbr+1,:)); +% elseif sb_nbr == M +% s_pol_sel = s_pol_dft(1,:); +% end + +s_pol_sel = s_pol_dft(sb_nbr,:); +% s_pol_sel = s_pol_dft(sb_nbr+1,:)+conj(s_pol_dft(M-sb_nbr+1,:)); +% s_pol_sel = -1i*s_pol_dft(sb_nbr+1,:)+conj(-1i*s_pol_dft(M-sb_nbr+1,:)); + +s_pol_sel=s_pol_sel.*exp(-1i*pi*[1:ns_pol])/2; + +win = hanning(ns_pol); +if average == 0 + [PSD, FREQ] = periodogram(s_pol_sel,win,ns_pol,(fs)/D); +else + [PSD, FREQ] = pwelch(s_pol_sel,floor(ns_pol/100),[],ns_pol,(fs)/D); +end +figure; +MAX = max(10*log(PSD)); +plot(FREQ/1e9, 10*log(PSD)-MAX); +title('Complex output signal'); +xlim([0,(fs)/D/1e9]); +grid on; + +%% Printf + +demux = M; + +file_folder = 'D:/Stage/ALMA_OPFB/simu/kx5_DFT - tb_6b_coeffs/tb_txts_files'; +write_file(tb_input, strcat(file_folder, '/input.txt'), 2*M, ' %4d'); +write_file(tb_input, strcat(file_folder, '/output.txt'), 2*M, ' %10d'); + +gen_Wn_coeffs_5ndft(M, 8, strcat(file_folder, '/coeffs.vhd')); \ No newline at end of file diff --git a/utils.vhd b/utils.vhd new file mode 100644 index 0000000..304a425 --- /dev/null +++ b/utils.vhd @@ -0,0 +1,33 @@ +-- *********************** Divers fonction utiles *************************** + + +LIBRARY ieee; +USE ieee.std_logic_1164.ALL; + + +PACKAGE utils IS + PROCEDURE horloge ( SIGNAL h: OUT std_logic; th, tb : time); + PROCEDURE horloge_retard ( SIGNAL h : OUT std_logic; periode : time ; + retard : time); +END utils; +--------------------------------------------------- +PACKAGE BODY utils IS + PROCEDURE horloge ( SIGNAL h : OUT std_logic; th, tb : time) IS + BEGIN + LOOP + h <= '0', '1' AFTER tb; + WAIT FOR tb + th ; + END LOOP; + END; + + PROCEDURE horloge_retard ( SIGNAL h : OUT std_logic; periode : time ; + retard : time) IS + BEGIN + h <= '0'; + WAIT FOR retard; + LOOP + h <= '1' , '0' AFTER periode/2 ; + WAIT FOR periode; + END LOOP; + END; +END utils; diff --git a/winograd5.m b/winograd5.m new file mode 100644 index 0000000..b473d57 --- /dev/null +++ b/winograd5.m @@ -0,0 +1,18 @@ +function output = winograd55(input, w) +in = [input(1,:); input(4,:); input(5,:); input(3,:); input(2,:)]; +s1 = [in(1,:); in(2,:)+in(4,:); in(3,:)+in(5,:); in(2,:)-in(4,:); in(5,:)-in(3,:)]; +s2 = [s1(1,:); s1(2,:)+s1(3,:); s1(3,:)-s1(2,:); s1(4,:); s1(5,:); s1(4,:)+s1(5,:)]; +mult = [1 (cos(2*pi/5)+cos(4*pi/5))/2-1 (cos(2*pi/5)-cos(4*pi/5))/2 sin(2*pi/5)-sin(4*pi/5) sin(2*pi/5)+sin(4*pi/5) sin(4*pi/5)]; +mult = fi(mult, 1, w, w-2); +mult = mult.data; +s4 = [s2(1,:)+s2(2,:); s2(2,:)*mult(2); s2(3,:)*mult(3); s2(4,:)*1i*mult(4); s2(5,:)*1i*mult(5); s2(6,:)*1i*mult(6)]; +s5 = [s4(1,:); s4(1,:)+s4(2,:); s4(3,:); s4(4,:); s4(5,:); s4(6,:)]; +s6 = [s5(1,:); s5(2,:)-s5(3,:); s5(2,:)+s5(3,:); s5(4,:)+s5(6,:); s5(6,:)-s5(5,:)]; +output = [s6(1,:); s6(3,:)+s6(5,:); s6(2,:)-s6(4,:); s6(2,:)+s6(4,:); s6(3,:)-s6(5,:)]; +end + +function output = radix2(input, w) + +s1 = [input(1) input(2)*w]; +output = [s1(1)+s1(2) s1(1)-s1(2)]; +end \ No newline at end of file diff --git a/winograd5.vhd b/winograd5.vhd new file mode 100644 index 0000000..c408f43 --- /dev/null +++ b/winograd5.vhd @@ -0,0 +1,309 @@ +LIBRARY ieee; +USE ieee.std_logic_1164.ALL; +USE ieee.std_logic_signed.ALL; +USE ieee.numeric_std.ALL; +USE work.FIVEn_DFT_PKG.ALL; + +ENTITY WINOGRAD5 IS + PORT( + i_clk : IN std_logic; + i_data_im : IN vect_input_winograd5_5ndft; + i_data_re : IN vect_input_winograd5_5ndft; + o_data_im : OUT vect_output_winograd5_5ndft; + o_data_re : OUT vect_output_winograd5_5ndft + ); +END WINOGRAD5; + +ARCHITECTURE Behavioral OF WINOGRAD5 IS + + SIGNAL mult_factors : vect_mult_factors_32b := ("10110000000000000000000000000000", "00100011110001101110111100110111", "00010111001111111101011000011110", "01100010011111000110001000101111", "00100101100111100100011000001001"); + -- multipliers multiplied by 2^30 + SIGNAL mult_factor_w_multipliers : vect_mult_factor_w_multipliers := (OTHERS => (OTHERS => '0')); + + --SIGNAL matrix_stages_signed_im : matrix_winograd5_generic_signed_stages := (OTHERS => (OTHERS => (OTHERS => '0'))); + --SIGNAL matrix_stages_signed_re : matrix_winograd5_generic_signed_stages := (OTHERS => (OTHERS => (OTHERS => '0'))); + SIGNAL matrix_stages_im : matrix_winograd5_generic_stages := (OTHERS => (OTHERS => (OTHERS => '0'))); --matrix(x)(y) = matrix(stage)(layer) form + SIGNAL matrix_stages_re : matrix_winograd5_generic_stages := (OTHERS => (OTHERS => (OTHERS => '0'))); -- matrix(x)(y) = matrix(stage)(layer) form + SIGNAL multiply_by_2_power_cst_w_precision : std_logic_vector(cst_w_precision_winograd5_coeffs_5ndft-3 DOWNTO 0) := (OTHERS => '0'); + --SIGNAL in1, in2 : smpl_out_winograd5_5ndft; + --SIGNAL isigned : smpl_out_winograd5_signed_5ndft; + + + + + + FUNCTION add_sub ( + w_smpl : IN natural; + sub : IN boolean; + in1, in2 : IN smpl_out_winograd5_5ndft) + RETURN smpl_out_winograd5_5ndft IS + VARIABLE smpl_stages_out : smpl_out_winograd5_5ndft := (OTHERS => '0'); + VARIABLE isigned : smpl_out_winograd5_signed_5ndft; + BEGIN + IF sub THEN + isigned(w_smpl DOWNTO 0) := signed(in1(w_smpl-1)&in1(w_smpl-1 DOWNTO 0))-signed(in2(w_smpl-1)&in2(w_smpl-1 DOWNTO 0)); + ELSE + isigned(w_smpl DOWNTO 0) := signed(in1(w_smpl-1)&in1(w_smpl-1 DOWNTO 0))+signed(in2(w_smpl-1)&in2(w_smpl-1 DOWNTO 0)); + END IF; + + smpl_stages_out(w_smpl DOWNTO 0) := std_logic_vector(unsigned(isigned(w_smpl DOWNTO 0))); + RETURN smpl_stages_out; + END FUNCTION; + + + + + + FUNCTION mult ( + w_smpl : IN natural; + cmplx : IN boolean; + w_coeff : IN natural; + input : IN smpl_out_winograd5_5ndft; + coeff : IN smpl_mult_factor_w_multipliers + ) + RETURN std_logic_vector IS + VARIABLE smpl_signed : smpl_out_winograd5_signed_5ndft := (OTHERS => '0'); + VARIABLE smpl_out : smpl_out_winograd5_5ndft; + BEGIN -- FUNCTION mult + IF(cmplx) THEN + smpl_signed(w_smpl+w_coeff-1 DOWNTO 0) := signed(input(w_smpl-1 DOWNTO 0)) * (-signed(coeff)); + ELSE + smpl_signed(w_smpl+w_coeff-1 DOWNTO 0) := signed(input(w_smpl-1 DOWNTO 0)) * signed(coeff); + END IF; + smpl_out := std_logic_vector(unsigned(smpl_signed)); + RETURN smpl_out; + END FUNCTION mult; + + + + + + FUNCTION smpl_copy ( + w_smpl : natural; + smpl_in : smpl_out_winograd5_5ndft) + RETURN std_logic_vector IS + VARIABLE smpl_out : smpl_out_winograd5_5ndft := (OTHERS => '0'); + BEGIN -- FUNCTION copy + smpl_out(w_smpl DOWNTO 0) := smpl_in(w_smpl-1)&smpl_in(w_smpl-1 DOWNTO 0); + RETURN smpl_out; --smpl_in(cst_winograd5_w_out_5ndft-1 DOWNTO w_smpl+1)&smpl_in(w_smpl-1)&smpl_in(w_smpl-1 DOWNTO 0);--smpl_out; + END FUNCTION smpl_copy; + + +BEGIN + + + fill_input_output_matrix_for : FOR i IN 0 TO 4 GENERATE + + matrix_stages_im(0)(i)(cst_w_in_5ndft-1 DOWNTO 0) <= i_data_im(i)(cst_w_in_5ndft-1 DOWNTO 0); + matrix_stages_re(0)(i)(cst_w_in_5ndft-1 DOWNTO 0) <= i_data_re(i)(cst_w_in_5ndft-1 DOWNTO 0); + o_data_im(i) <= matrix_stages_im(7)(i); + o_data_re(i) <= matrix_stages_re(7)(i); + + END GENERATE fill_input_output_matrix_for; + + + + -- purpose: Rounds the data in 32bits into cst_w_precision_winograd5_coeffs_5ndft bits (round for + -- MSBs). Should run and cut before simulation and bitstream + -- inputs : the coeffs to be cut mult_factors + -- outputs: the cut coeffs mult_factor_w_multipliers + mult_coeffs_cut : PROCESS(mult_factors) + BEGIN + FOR i IN 1 TO 5 LOOP + mult_factor_w_multipliers(i) <= mult_factors(i)(31 DOWNTO 32-cst_w_precision_winograd5_coeffs_5ndft); + IF(mult_factors(i)(31-cst_w_precision_winograd5_coeffs_5ndft) = '1') THEN + mult_factor_w_multipliers(i) <= std_logic_vector(unsigned(signed(mult_factors(i)(31 DOWNTO 32-cst_w_precision_winograd5_coeffs_5ndft)) +1)); + END IF; + END LOOP; -- i + END PROCESS mult_coeffs_cut; + + + + -- purpose: calculates each stage following the winograd5 schema + -- inputs: matrix_stages_im(0) + -- outputs: matrix_stages_im(7) + calculations_process : PROCESS(i_clk) + VARIABLE w_smpl : natural; + BEGIN + + IF(rising_edge(i_clk)) THEN + + -- stage 1 + -- w_smpl :=== cst_w_in_5ndft+1; + --data0 + matrix_stages_im(1)(0) <= smpl_copy(w_smpl => cst_w_in_5ndft, smpl_in => matrix_stages_im(0)(0)); + matrix_stages_re(1)(0) <= smpl_copy(w_smpl => cst_w_in_5ndft, smpl_in => matrix_stages_re(0)(0)); + + -- data1 + matrix_stages_im(1)(1) <= add_sub (w_smpl => cst_w_in_5ndft, sub => false, in1 => matrix_stages_im(0)(3), in2 => matrix_stages_im(0)(2)); + matrix_stages_re(1)(1) <= add_sub (w_smpl => cst_w_in_5ndft, sub => false, in1 => matrix_stages_re(0)(3), in2 => matrix_stages_re(0)(2)); + + --data2 + matrix_stages_im(1)(2) <= add_sub (w_smpl => cst_w_in_5ndft, sub => false, in1 => matrix_stages_im(0)(4), in2 => matrix_stages_im(0)(1)); + matrix_stages_re(1)(2) <= add_sub (w_smpl => cst_w_in_5ndft, sub => false, in1 => matrix_stages_re(0)(4), in2 => matrix_stages_re(0)(1)); + + --data3 + matrix_stages_im(1)(3) <= add_sub (w_smpl => cst_w_in_5ndft, sub => true, in1 => matrix_stages_im(0)(3), in2 => matrix_stages_im(0)(2)); + matrix_stages_re(1)(3) <= add_sub (w_smpl => cst_w_in_5ndft, sub => true, in1 => matrix_stages_re(0)(3), in2 => matrix_stages_re(0)(2)); + + --data4 + matrix_stages_im(1)(4) <= add_sub (w_smpl => cst_w_in_5ndft, sub => true, in1 => matrix_stages_im(0)(1), in2 => matrix_stages_im(0)(4)); + matrix_stages_re(1)(4) <= add_sub (w_smpl => cst_w_in_5ndft, sub => true, in1 => matrix_stages_re(0)(1), in2 => matrix_stages_re(0)(4)); + + + + + + -- stage 2 + w_smpl := cst_w_in_5ndft+1; + -- data0,3,4 + matrix_stages_im(2)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(1)(0)); + matrix_stages_re(2)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(1)(0)); + matrix_stages_im(2)(3) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(1)(3)); + matrix_stages_re(2)(3) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(1)(3)); + matrix_stages_im(2)(4) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(1)(4)); + matrix_stages_re(2)(4) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(1)(4)); + + --data1 + matrix_stages_im(2)(1) <= add_sub (w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(1)(1), in2 => matrix_stages_im(1)(2)); + matrix_stages_re(2)(1) <= add_sub (w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(1)(1), in2 => matrix_stages_re(1)(2)); + + --data2 + matrix_stages_re(2)(2) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_re(1)(2), in2 => matrix_stages_re(1)(1)); + matrix_stages_im(2)(2) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_im(1)(2), in2 => matrix_stages_im(1)(1)); + + --data5 + matrix_stages_re(2)(5) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(1)(3), in2 => matrix_stages_re(1)(4)); + matrix_stages_im(2)(5) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(1)(3), in2 => matrix_stages_im(1)(4)); + + + + + + -- stage 3 + w_smpl := cst_w_in_5ndft+2; + --data1,2,3,4,5 + matrix_stages_im(3)(1) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(2)(1)); + matrix_stages_re(3)(1) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(2)(1)); + matrix_stages_im(3)(2) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(2)(2)); + matrix_stages_re(3)(2) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(2)(2)); + matrix_stages_im(3)(3) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(2)(3)); + matrix_stages_re(3)(3) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(2)(3)); + matrix_stages_im(3)(4) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(2)(4)); + matrix_stages_re(3)(4) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(2)(4)); + matrix_stages_im(3)(5) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(2)(5)); + matrix_stages_re(3)(5) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(2)(5)); + + --data0 + matrix_stages_im(3)(0) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(2)(1), in2 => matrix_stages_im(2)(0)); + matrix_stages_re(3)(0) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(2)(1), in2 => matrix_stages_re(2)(0)); + + + + + + -- stage 4, multiply + w_smpl := cst_w_in_5ndft+3; + --data0, multiply by 1 = copy + matrix_stages_im(4)(0)(w_smpl+cst_w_precision_winograd5_coeffs_5ndft-1 DOWNTO 0) <= matrix_stages_im(3)(0)(w_smpl-1)&matrix_stages_im(3)(0)(w_smpl-1)&matrix_stages_im(3)(0)(w_smpl-1 DOWNTO 0)&multiply_by_2_power_cst_w_precision; + matrix_stages_re(4)(0)(w_smpl+cst_w_precision_winograd5_coeffs_5ndft-1 DOWNTO 0) <= matrix_stages_re(3)(0)(w_smpl-1)&matrix_stages_re(3)(0)(w_smpl-1)&matrix_stages_re(3)(0)(w_smpl-1 DOWNTO 0)&multiply_by_2_power_cst_w_precision; + + --data1 + matrix_stages_im(4)(1) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_im(3)(1), coeff => mult_factor_w_multipliers(1)); + matrix_stages_re(4)(1) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_re(3)(1), coeff => mult_factor_w_multipliers(1)); + + --data2 + matrix_stages_im(4)(2) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_im(3)(2), coeff => mult_factor_w_multipliers(2)); + matrix_stages_re(4)(2) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_re(3)(2), coeff => mult_factor_w_multipliers(2)); + + --data3 + matrix_stages_re(4)(3) <= mult (w_smpl => w_smpl, cmplx => true, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_im(3)(3), coeff => mult_factor_w_multipliers(3)); + matrix_stages_im(4)(3) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_re(3)(3), coeff => mult_factor_w_multipliers(3)); + + --data4 + matrix_stages_re(4)(4) <= mult (w_smpl => w_smpl, cmplx => true, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_im(3)(4), coeff => mult_factor_w_multipliers(4)); + matrix_stages_im(4)(4) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_re(3)(4), coeff => mult_factor_w_multipliers(4)); + + --data5 + matrix_stages_re(4)(5) <= mult (w_smpl => w_smpl, cmplx => true, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_im(3)(5), coeff => mult_factor_w_multipliers(5)); + matrix_stages_im(4)(5) <= mult (w_smpl => w_smpl, cmplx => false, w_coeff => cst_w_precision_winograd5_coeffs_5ndft, input => matrix_stages_re(3)(5), coeff => mult_factor_w_multipliers(5)); + + + + + + -- stage 5 + w_smpl := cst_w_in_5ndft+3+cst_w_precision_winograd5_coeffs_5ndft; + --data0, 2, 3, 4, 5 + matrix_stages_im(5)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(4)(0)); + matrix_stages_re(5)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(4)(0)); + matrix_stages_im(5)(2) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(4)(2)); + matrix_stages_re(5)(2) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(4)(2)); + matrix_stages_im(5)(3) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(4)(3)); + matrix_stages_re(5)(3) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(4)(3)); + matrix_stages_im(5)(4) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(4)(4)); + matrix_stages_re(5)(4) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(4)(4)); + matrix_stages_im(5)(5) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(4)(5)); + matrix_stages_re(5)(5) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(4)(5)); + + --data1 + matrix_stages_re(5)(1) <= add_sub(w_smpl => w_smpl, sub => false, IN1 => matrix_stages_re(4)(1), in2 => matrix_stages_re(4)(0)); + matrix_stages_im(5)(1) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(4)(1), in2 => matrix_stages_im(4)(0)); + + + + + + -- stage 6 + w_smpl := cst_w_in_5ndft+3+cst_w_precision_winograd5_coeffs_5ndft+1; + --data0 + matrix_stages_im(6)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(5)(0)); + matrix_stages_re(6)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(5)(0)); + + --data1 + matrix_stages_re(6)(1) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_re(5)(1), in2 => matrix_stages_re(5)(2)); + matrix_stages_im(6)(1) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_im(5)(1), in2 => matrix_stages_im(5)(2)); + + --data2 + matrix_stages_re(6)(2) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(5)(1), in2 => matrix_stages_re(5)(2)); + matrix_stages_im(6)(2) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(5)(1), in2 => matrix_stages_im(5)(2)); + + --data3 + matrix_stages_re(6)(3) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(5)(5), in2 => matrix_stages_re(5)(3)); + matrix_stages_im(6)(3) <= add_sub(w_smpl => w_smpl, sub => false, IN1 => matrix_stages_im(5)(5), in2 => matrix_stages_im(5)(3)); + + --data4 + matrix_stages_re(6)(4) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_re(5)(5), in2 => matrix_stages_re(5)(4)); + matrix_stages_im(6)(4) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_im(5)(5), in2 => matrix_stages_im(5)(4)); + + + + + + -- stage 7 + w_smpl := cst_w_in_5ndft+3+cst_w_precision_winograd5_coeffs_5ndft+2; + --data0 + matrix_stages_im(7)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_im(6)(0)); + matrix_stages_re(7)(0) <= smpl_copy(w_smpl => w_smpl, smpl_in => matrix_stages_re(6)(0)); + + --data1 + matrix_stages_re(7)(1) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(6)(2), in2 => matrix_stages_re(6)(4)); + matrix_stages_im(7)(1) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(6)(2), in2 => matrix_stages_im(6)(4)); + + --data2 + matrix_stages_re(7)(2) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_re(6)(1), in2 => matrix_stages_re(6)(3)); + matrix_stages_im(7)(2) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_im(6)(1), in2 => matrix_stages_im(6)(3)); + + --data3 + matrix_stages_re(7)(3) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_re(6)(1), in2 => matrix_stages_re(6)(3)); + matrix_stages_im(7)(3) <= add_sub(w_smpl => w_smpl, sub => false, in1 => matrix_stages_im(6)(1), in2 => matrix_stages_im(6)(3)); + + --data4 + matrix_stages_re(7)(4) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_re(6)(2), in2 => matrix_stages_re(6)(4)); + matrix_stages_im(7)(4) <= add_sub(w_smpl => w_smpl, sub => true, in1 => matrix_stages_im(6)(2), in2 => matrix_stages_im(6)(4)); + + END IF; + END PROCESS calculations_process; + + +END Behavioral; diff --git a/write_file.m b/write_file.m new file mode 100644 index 0000000..48b42c5 --- /dev/null +++ b/write_file.m @@ -0,0 +1,11 @@ +function write_file(input, file, nb_words_per_line, words_format) + +input_format = ''; +for i=1:nb_words_per_line + input_format = strcat(input_format,words_format); +end +input_format = strcat(input_format,'\n'); +fin = fopen(file,'w'); +fprintf(fin,input_format,input); +fclose(fin); +end \ No newline at end of file