diff --git a/applications/lofar2/model/pfs_coeff_final.m b/applications/lofar2/model/pfs_coeff_final.m index 3c3bb8947306f96fc3b736bdbed837ae719ad32c..b8bb2d3f196d52abebd5285886a20594b8cd5309 100644 --- a/applications/lofar2/model/pfs_coeff_final.m +++ b/applications/lofar2/model/pfs_coeff_final.m @@ -21,7 +21,10 @@ % Authors : % Created by FilterTaskForce team 2004 for LOFAR1 [1, 2] % Updated in 2022 for LOFAR20 by E. Kooistra -% Purpose: +% Purpose: Generate and analyse subband FIR filter coefficients and compare +% with LOFAR1 coefficients [4, 5] +% +% MATLAB: Tested with MATLAB R2018a + Signal Processing Toolbox % % References: % [1] hdl/applications/lofar1/FilterTaskForce/readme_FilterTaskForce.txt @@ -93,6 +96,7 @@ % g) Determine half power bandwidth of the pass band % h) Support loading and analysing LOFAR1 coefficients for comparison % i) Support changing the half power subband band width via relative_bw = 1 +% j) Save plots in plots/ close all; clear all; @@ -101,6 +105,7 @@ fig = 0; reproduce_ftf = true; %reproduce_ftf = false; + %% User settings if not(reproduce_ftf) % passband ripple (in dB); @@ -152,13 +157,14 @@ M2 = N*L; % fine frequency resolution P = 10; M3 = M2 * P; -% frequency scale +% frequency scales, normalized to f_sub = 1 fs1 = N/Q; fs2 = N; f1_axis = [-M1/2:M1/2-1]/M1 * fs1; % for compute filter f2_axis = [-M2/2:M2/2-1]/M2 * fs2; % for interpolated filter f3_axis = [-M3/2:M3/2-1]/M3 * fs2; % for fine resolution spectrum + %% Plot possible window functions fig=fig+1; figure('position', [300+fig*20 200-fig*20 1000 800]); @@ -169,6 +175,8 @@ title('Window functions'); xlabel('Sample') ylabel('Gain') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') %% Compute filter @@ -180,6 +188,7 @@ spectrum_comp = abs(fftshift_comp) / max(abs(fftshift_comp)); spectrum_comp_dB = 20*log10(spectrum_comp); phase_comp = unwrap(angle(fftshift_comp)); + %% Compute windowed filter if strcmp(use_window, 'blackman') disp(sprintf('NOTE: use blackman window')); @@ -196,6 +205,7 @@ else % default 'none' end h_wcomp = h_window' .* h_comp; + %% Plot frequency response of compute filter fft_wcomp = fft(h_wcomp); fftshift_wcomp = fftshift(fft_wcomp); @@ -209,9 +219,11 @@ figure(fig); plot(f1_axis, spectrum_comp_dB, 'r', f1_axis, spectrum_wcomp_dB, 'g') legend('computed','windowed') title('Power spectrum of computed and windowed filter'); -xlabel('f [Hz]') +xlabel('f [Hz] (normalized)') ylabel('Gain [dB]') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') fig=fig+1; figure('position', [300+fig*20 200-fig*20 1000 800]); @@ -219,12 +231,15 @@ figure(fig); plot(f1_axis, phase_comp, 'r', f1_axis, phase_wcomp, 'g') legend('computed','windowed') title('Phase spectrum of computed and windowed filter'); % no difference -xlabel('f [Hz]') +xlabel('f [Hz] (normalized)') ylabel('Phase [rad]') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') %% Use fourier interpolation to create final filter +% . interpolation is used because fircls1 algorithm cannot handle >> 1000 taps f2 = zeros(1, M2); % copy the lower frequency half of the computed filter into f2. n = 0:M1/2; @@ -253,6 +268,7 @@ else h_quant = round(h_fourier); end + %% Load LOFAR1 coefficients if use_lofar1 h_quant = load('data/Coeffs16384Kaiser-quant.dat'); @@ -270,11 +286,13 @@ else disp(sprintf('WARNING: quantized FIR coefficients are NOT symmetrical.')); end -% save the coefficients + +%% Save the coefficients fid = fopen('data/Coefficient_16KKaiser.dat','w'); fprintf(fid,'%i\n', h_quant); fclose(fid); + %% Compare with reference FTF coefficients h_ftf = load('data/Coefficient_16KKaiser.gold'); d = h_ftf' == h_quant; @@ -288,6 +306,7 @@ else end end + %% Compare with LOFAR1 coefficients h_lofar1 = load('data/Coeffs16384Kaiser-quant.dat'); d = h_lofar1' - h_quant; @@ -297,8 +316,10 @@ figure(fig); plot(d) title('Difference between recreated coefficients and LOFAR1 coefficients'); xlabel('Sample') -ylabel('Coefficient') +ylabel('Coefficient difference') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') d = h_lofar1' == h_quant; if sum(d) == length(d) @@ -318,6 +339,9 @@ title('Impulse response'); xlabel('Sample') ylabel('Coefficient') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') + %% Plot quantization error histogram to see effect of use_uencode fig=fig+1; @@ -328,6 +352,8 @@ title('Quantization error histogram'); xlabel('Quantization error'); ylabel('Relative probability'); grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') %% Plot DC response per polyphase @@ -344,6 +370,8 @@ title('DC response per polyphase'); xlabel('Polyphase index') ylabel('DC response') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') %% Plot frequency response of original and quantized filter @@ -369,9 +397,11 @@ figure(fig); plot(f3_axis, spectrum_org_dB, 'r', f3_axis, spectrum_quant_dB, 'g') legend('original','quantized') title('Power spectrum of original and quantized filter'); -xlabel('f [Hz]') +xlabel('f [Hz] (normalized)') ylabel('Gain [dB]') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') fig=fig+1; figure('position', [300+fig*20 200-fig*20 1000 800]); @@ -387,9 +417,11 @@ phase_quant = phase_quant + phase_offset; plot(f3_axis, phase_org, 'r', f3_axis, phase_quant, 'g') legend('original','quantized') title('Phase spectrum of original and quantized filter'); -xlabel('f [Hz]') +xlabel('f [Hz] (normalized)') ylabel('Phase [rad]') grid on; +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') %% Determine half power bandwidth of the subband @@ -408,3 +440,5 @@ pass_bw = (pass_index_hi - pass_index_lo + 1) / M3 * fs2; %disp(sprintf('%f', pass_index_lo)); %disp(sprintf('%f', pass_index_hi)); disp(sprintf('NOTE: quantized FIR filter normalized subband bandwidth is %6.4f * f_sub', pass_bw)); +file_name = sprintf('plots/pfs_coeff_final_%d.jpg', fig); +print(file_name, '-djpeg') diff --git a/applications/lofar2/model/plots/pfs_coeff_final_1.jpg b/applications/lofar2/model/plots/pfs_coeff_final_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6012d00eca7b3d9d2baa2c89b65dcce08c5f4d31 Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_1.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_2.jpg b/applications/lofar2/model/plots/pfs_coeff_final_2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2c03a5ddd4c4c38f4c155defcc20ca681277e5ab Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_2.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_3.jpg b/applications/lofar2/model/plots/pfs_coeff_final_3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a3e7ecdbad6a2db82bcc1d7e6ba2610392482477 Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_3.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_4.jpg b/applications/lofar2/model/plots/pfs_coeff_final_4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d43c8398df5ff96722defbea1fe4b71bcabda074 Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_4.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_5.jpg b/applications/lofar2/model/plots/pfs_coeff_final_5.jpg new file mode 100644 index 0000000000000000000000000000000000000000..727c4a8355bef46b16a18d45584a36eaceaefaca Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_5.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_6.jpg b/applications/lofar2/model/plots/pfs_coeff_final_6.jpg new file mode 100644 index 0000000000000000000000000000000000000000..55423e4317fe6d38095c42315c18c665d377a6b8 Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_6.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_7.jpg b/applications/lofar2/model/plots/pfs_coeff_final_7.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a99efbdef10494365634d07bd6d33ae171810a81 Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_7.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_8.jpg b/applications/lofar2/model/plots/pfs_coeff_final_8.jpg new file mode 100644 index 0000000000000000000000000000000000000000..26f83b602445402d57781f3fd5ac47102ea9472e Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_8.jpg differ diff --git a/applications/lofar2/model/plots/pfs_coeff_final_9.jpg b/applications/lofar2/model/plots/pfs_coeff_final_9.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e313855a7547a5c11dd74b2942461985782cf34a Binary files /dev/null and b/applications/lofar2/model/plots/pfs_coeff_final_9.jpg differ