Organized codegen for fracFdpw. Tested with random input in matlab script. OK
This commit is contained in:
@@ -1,20 +1,56 @@
|
||||
function [Achirp,AchirpOut,H,scale] = fracF_init(a)
|
||||
function [Achirp,H,Cchirp,Aa] = fracF_init(a)
|
||||
%#codegen
|
||||
%% fracF_init Precompute FrFT coefficients
|
||||
%
|
||||
% fracF_init
|
||||
% [Achirp,H,Cchirp,Aa] = fracF_init(a)
|
||||
%
|
||||
% Precompute FrFT coefficients for DPW processing.
|
||||
% Generates the constant coefficients required by the code-generation
|
||||
% implementation of the Fractional Fourier Transform (FrFT).
|
||||
%
|
||||
% INPUT:
|
||||
% a - FrFT order (single)
|
||||
% The implementation follows the chirp-convolution-chirp formulation:
|
||||
%
|
||||
% OUTPUTS:
|
||||
% Achirp [1024 x 1]
|
||||
% AchirpOut [512 x 1]
|
||||
% H [2048 x 1]
|
||||
% scale scalar
|
||||
% f(n)
|
||||
% ↓
|
||||
% Achirp
|
||||
% ↓
|
||||
% FFT
|
||||
% ↓
|
||||
% H = FFT(Bchirp)
|
||||
% ↓
|
||||
% IFFT
|
||||
% ↓
|
||||
% Cchirp
|
||||
% ↓
|
||||
% Aa
|
||||
% ↓
|
||||
% F_a(n)
|
||||
%
|
||||
% These coefficients depend only on the transform order 'a' and can
|
||||
% therefore be computed once and reused for all frames within a DPW.
|
||||
%
|
||||
% INPUT
|
||||
% a FrFT order (single)
|
||||
%
|
||||
% OUTPUTS
|
||||
% Achirp [1024 x 1] pre-multiplication chirp (A chirp)
|
||||
% H [2048 x 1] FFT of the convolution chirp (B chirp)
|
||||
% Cchirp [512 x 1] post-multiplication chirp (C chirp)
|
||||
% Aa scalar FrFT amplitude factor (A_alpha)
|
||||
%
|
||||
% Notes
|
||||
% - Input length is assumed to be N = 1024 samples.
|
||||
% - Output length is N/2 = 512 samples.
|
||||
% - All outputs are returned as complex(single).
|
||||
% - Intended for use with fracF_dpw().
|
||||
%
|
||||
% See also:
|
||||
% fracF_dpw
|
||||
|
||||
N = 1024;
|
||||
%% Fixed transform dimensions
|
||||
|
||||
N = 1024;
|
||||
|
||||
%% Transform parameters
|
||||
|
||||
pi_s = single(pi);
|
||||
|
||||
@@ -27,44 +63,53 @@ cos_phi = cos(phi);
|
||||
csc_phi = 1/sin_phi;
|
||||
cot_phi = cos_phi/sin_phi;
|
||||
|
||||
twoDelta = 2*sqrt(single(N)/2);
|
||||
two_delta = 2*sqrt(single(N)/2);
|
||||
|
||||
%% Chirp A
|
||||
%% Pre-multiplication chirp (A chirp)
|
||||
|
||||
n = single((-N/2:N/2-1).') / twoDelta;
|
||||
n = single((-N/2:N/2-1).') / two_delta;
|
||||
|
||||
Achirp = exp(-1j*pi_s*(n.^2)*tan_half_phi);
|
||||
|
||||
%% Chirp B
|
||||
%% Convolution chirp (B chirp)
|
||||
|
||||
m = single((-N:N-1).') / twoDelta;
|
||||
m = single((-N:N-1).') / two_delta;
|
||||
|
||||
Bchirp = exp(1j*pi_s*csc_phi*(m.^2));
|
||||
|
||||
%% FFT of Chirp B
|
||||
%% Frequency-domain convolution kernel
|
||||
%
|
||||
% H corresponds to FFT(Bchirp) and is used in the frequency-domain
|
||||
% implementation of the chirp convolution.
|
||||
|
||||
H = fft(Bchirp);
|
||||
|
||||
%% Output chirp
|
||||
%% Post-multiplication chirp (C chirp)
|
||||
%
|
||||
% Since the implementation extracts every other sample from the valid
|
||||
% convolution region, only the corresponding chirp samples are required.
|
||||
|
||||
AchirpOut = Achirp(1:2:end);
|
||||
Cchirp = Achirp(1:2:end);
|
||||
|
||||
%% Scale factor
|
||||
%% FrFT amplitude factor (A_alpha)
|
||||
|
||||
scale = sqrt(1 - 1j*cot_phi) / twoDelta;
|
||||
Aa = sqrt(1 - 1j*cot_phi) / two_delta;
|
||||
|
||||
%% Force single precision complex
|
||||
%% Force complex(single) outputs
|
||||
%
|
||||
% Explicit casting avoids unintended promotion to double precision and
|
||||
% ensures deterministic code generation.
|
||||
|
||||
Achirp = complex(single(real(Achirp)), ...
|
||||
single(imag(Achirp)));
|
||||
Achirp = complex(single(real(Achirp)), ...
|
||||
single(imag(Achirp)));
|
||||
|
||||
AchirpOut = complex(single(real(AchirpOut)), ...
|
||||
single(imag(AchirpOut)));
|
||||
H = complex(single(real(H)), ...
|
||||
single(imag(H)));
|
||||
|
||||
H = complex(single(real(H)), ...
|
||||
single(imag(H)));
|
||||
Cchirp = complex(single(real(Cchirp)), ...
|
||||
single(imag(Cchirp)));
|
||||
|
||||
scale = complex(single(real(scale)), ...
|
||||
single(imag(scale)));
|
||||
Aa = complex(single(real(Aa)), ...
|
||||
single(imag(Aa)));
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user