Files of a 5*2^n VHDL entity using Winograd5 and radix2 implementations
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

239 lignes
6.5KB

  1. clear all;
  2. clear;
  3. close all;
  4. rng(1); % random seed
  5. global ns average quantization Q1 Q2 Q3 fs M D sb_nbr Apass Astop dens
  6. %% Parameter
  7. ns = 2e6; % Number of Sample
  8. fs = 40e9; % Sampling Frequency
  9. M = 20; % Polyphase factor
  10. D = 8; % Decimator
  11. sb_nbr = 3; % Sub-band Number in OPFB : 1 -> M
  12. average = 0; % PSD smoothing : 0 = OFF ; 1 = ON
  13. quantization = 1; % 0 = OFF ; 1 = ON
  14. Q1 = 6; % DG Quantization
  15. Q2 = 8; % TAP Quantizantion
  16. Q3 = 6; % PFB Quantization
  17. Apass = 0.25; % Passband Ripple (dB)
  18. Astop = 50; % Stopband Attenuation (dB)
  19. dens = 50; % Density Factor
  20. %% Input Signal
  21. bw = fs/M; % OPFB Output Bandwidth
  22. f1 = bw*(sb_nbr);
  23. f2 = bw*(sb_nbr-0.625+0.25*mod(sb_nbr,M/gcd(M,D)));
  24. t = 0:1/fs:(ns-1)/fs;
  25. sw1 = 1*sin(2*pi*f1*t);
  26. sw2 = 1*sin(2*pi*f1*t);
  27. noise = randn([1 ns]);
  28. nsw = noise+sw1+sw2;
  29. % win = hanning(ns);
  30. % if average == 0
  31. % [PSD, FREQ] = periodogram(nsw,win,ns,fs);
  32. % else
  33. % [PSD, FREQ] = pwelch(nsw,ns/100,[],ns,fs);
  34. % end
  35. % figure;
  36. % MAX = max(10*log(PSD));
  37. % plot(FREQ/1e9, 10*log(PSD)-MAX);
  38. % title('Real Input signal');
  39. % xlim([0,fs/1e9]);
  40. % grid on;
  41. %% Digitizer Anti-aliasing Filter
  42. f = [0 0.1 0.9 1];
  43. m = [0 1 1 0];
  44. b = fir2(1000,f,m);
  45. s_dg_real = conv(noise+sw1,b,'valid');
  46. s_dg_imag = conv(noise+sw2,b,'valid');
  47. s_dg_bb = 0*s_dg_real+1i*s_dg_imag;
  48. ns_dg_bb = size(s_dg_bb,2);
  49. if quantization == 1
  50. s_dg_bb_fi = fi(s_dg_bb,1,Q1,0);
  51. s_dg_bb = s_dg_bb_fi.data;
  52. end
  53. win = hanning(ns_dg_bb);
  54. if average == 0
  55. [PSD, FREQ] = periodogram(s_dg_bb,win,ns_dg_bb,fs);
  56. else
  57. [PSD, FREQ] = pwelch(s_dg_bb,ns_dg_bb/100,[],ns_dg_bb,fs);
  58. end
  59. figure;
  60. MAX = max(10*log(PSD));
  61. plot(FREQ/1e9, 10*log(PSD)-MAX);
  62. title('Dual complex input signal');
  63. xlim([0,fs/1e9]);
  64. grid on;
  65. %% Oversampled Polyphase Filter Bank
  66. % All frequency values are in GHz.
  67. Fs = fs/1e9; % Sampling Frequency
  68. Fpass = (1-(1-D/M))*Fs/M; % Passband Frequency
  69. Fstop = Fs/M; % Stopband Frequency
  70. Dpass = 1-10^(-Apass/20); % Passband Ripple
  71. Dstop = 10^(-Astop/20); % Stopband Attenuation
  72. % Calculate the order from the parameters using FIRPMORD.
  73. [N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs), [1 0], [Dpass, Dstop]);
  74. Ndec0 = N;
  75. if (mod(N,M) ~= M-1)
  76. N = N + M-1 - mod(N,M);
  77. end
  78. % Calculate the coefficients using the FIRPM function.
  79. Hdec0 = firpm(N, Fo, Ao, W, {dens});
  80. % Calculate polyphase filter
  81. Hdec0 = fliplr(Hdec0);
  82. len = length(Hdec0);
  83. nrows = len/M;
  84. Hdec0_pol = zeros(M,nrows);
  85. for m=1:M
  86. for i=1:nrows
  87. Hdec0_pol(m,i)=Hdec0(1,(i-1)*M+m);
  88. end
  89. end
  90. if quantization == 1
  91. Hdec0_pol_fi = fi(Hdec0_pol,1,Q2);
  92. Hdec0_pol = Hdec0_pol_fi.data;
  93. end
  94. % Demux Input
  95. ns_dg_rs1 = floor((ns_dg_bb-M)/D);
  96. s_dg_rs1 = zeros(M,ns_dg_rs1);
  97. for m=1:M
  98. for i=1:ns_dg_rs1
  99. s_dg_rs1(m,i) = s_dg_bb(1,(i-1)*D+m);
  100. end
  101. end
  102. s_dg_rs1 = flipud(s_dg_rs1);
  103. % Circular shifting
  104. s_dg_rs2 = s_dg_rs1;
  105. ns_dg_rs2 = ns_dg_rs1;
  106. % for i = 1:ns_dg_rs2
  107. % s_dg_rs2(:,i) = flip((s_dg_bb((i-1)*D+1:(i-1)*D+M))');
  108. % end
  109. for i=1:ns_dg_rs2
  110. for m=1:M
  111. s_dg_rs2(m,i) = s_dg_rs1(1+mod( (m-1) + mod((i-1)*D,M) ,M),i);
  112. end
  113. end
  114. % Apply polyphase filter
  115. ns_pol = ns_dg_rs2-(nrows-1);
  116. s_pol = zeros(M,ns_pol);
  117. for m=1:M
  118. s_pol(m,:) = conv(s_dg_rs2(m,:),Hdec0_pol(m,:),'valid');
  119. end
  120. s_pol(:,1:M) = 0*s_pol(:,1:M);
  121. s_pol(10,1:10) = 1i;
  122. s_pol_fi = fi(s_pol,1,19,10);
  123. s_pol = s_pol_fi.data;
  124. % DFT
  125. s_pol_dft = zeros(M,ns_pol);
  126. if M == 10
  127. 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,:)];
  128. elseif M == 20
  129. 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,:)];
  130. end
  131. %%
  132. for i = 1:M/5
  133. s_pol_dft(1+5*(i-1):5*i,:) = winograd5(s_pol_rearranged(1+5*(i-1):5*i,:), 8);
  134. end
  135. %F = fimath('RoundingMethod','Floor','ProductMode','KeepMSB', 'ProductFractionLength',6);
  136. wn5 = fi(exp(-2*1i*pi*[0:4]/10), 1, 8, 6);
  137. wn5 = wn5.data;
  138. wn10 = fi(exp(-2*1i*pi*[0:9]/20), 1, 8, 6);
  139. wn10 = wn10.data;
  140. for i = 1:M/10
  141. s_pol_dft(1+10*(i-1):10*i, :) = radix2(s_pol_dft(1+10*(i-1):10*i, :), wn5);
  142. end
  143. if M == 20
  144. s_pol_dft = radix2(s_pol_dft, wn10);
  145. end
  146. % for i=1:ns_pol
  147. % s_pol_dft(:,i) = fft(s_pol(:,i));
  148. % end
  149. %s_pol_dft(2:end, :) = flip(s_pol_dft(2:end, :));
  150. % for i=1:ns_pol
  151. % for p=1:M
  152. % for m=1:M
  153. % s_pol_dft(p,i) = s_pol_dft(p,i) + s_pol(m,i)*exponential(mod((m-1)*(p-1), M)+1);
  154. % end
  155. % end
  156. % end
  157. tb_input = s_pol_fi.data*2^s_pol_fi.FractionLength;
  158. tb_input = [real(tb_input);imag(tb_input)];
  159. tb_input = reshape(tb_input, 1, size(tb_input,1)*size(tb_input,2));
  160. tb_output = fi(s_pol_dft,1,6,4);
  161. tb_output = tb_output.data*2^(4);
  162. tb_output = floor([real(tb_output);imag(tb_output)]);
  163. tb_output = reshape(tb_output, 1, size(tb_output,1)*size(tb_output,2));
  164. %% Sub-band Selection
  165. sb_nbr = 9;
  166. %
  167. % if sb_nbr < M/2
  168. % s_pol_sel = s_pol_dft(sb_nbr+1,:)+conj(s_pol_dft(M-sb_nbr+1,:));
  169. % elseif sb_nbr == M/2
  170. % s_pol_sel = s_pol_dft(sb_nbr+1,:);
  171. % if sb_nbr < M
  172. % s_pol_sel = -1i*s_pol_dft(sb_nbr+1,:)+conj(-1i*s_pol_dft(M-sb_nbr+1,:));
  173. % elseif sb_nbr == M
  174. % s_pol_sel = s_pol_dft(1,:);
  175. % end
  176. s_pol_sel = s_pol_dft(sb_nbr,:);
  177. % s_pol_sel = s_pol_dft(sb_nbr+1,:)+conj(s_pol_dft(M-sb_nbr+1,:));
  178. % s_pol_sel = -1i*s_pol_dft(sb_nbr+1,:)+conj(-1i*s_pol_dft(M-sb_nbr+1,:));
  179. s_pol_sel=s_pol_sel.*exp(-1i*pi*[1:ns_pol])/2;
  180. win = hanning(ns_pol);
  181. if average == 0
  182. [PSD, FREQ] = periodogram(s_pol_sel,win,ns_pol,(fs)/D);
  183. else
  184. [PSD, FREQ] = pwelch(s_pol_sel,floor(ns_pol/100),[],ns_pol,(fs)/D);
  185. end
  186. figure;
  187. MAX = max(10*log(PSD));
  188. plot(FREQ/1e9, 10*log(PSD)-MAX);
  189. title('Complex output signal');
  190. xlim([0,(fs)/D/1e9]);
  191. grid on;
  192. %% Printf
  193. demux = M;
  194. file_folder = 'D:/Stage/ALMA_OPFB/simu/kx5_DFT - tb_6b_coeffs/tb_txts_files';
  195. write_file(tb_input, strcat(file_folder, '/input.txt'), 2*M, ' %4d');
  196. write_file(tb_input, strcat(file_folder, '/output.txt'), 2*M, ' %10d');
  197. gen_Wn_coeffs_5ndft(M, 8, strcat(file_folder, '/coeffs.vhd'));