Faster DP_fiber with GPU processing... Run test\gpu_cpu_comparison.m to see difference on your setup
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
classdef Optical_Multiplex < handle
|
||||
% Takes a cell array of signals
|
||||
% returns a total field signal
|
||||
% WDM spacing is given in wavelength plan OR via delta_F
|
||||
|
||||
% returns a total field signal
|
||||
% WDM spacing is given in wavelength plan OR via delta_F
|
||||
|
||||
% The grid is stored in the output signal -> the demux will ideally
|
||||
% look this up and use this as the demux frequencies...
|
||||
% look this up and use this as the demux frequencies...
|
||||
|
||||
% signal_cell = {Opt_sig_1, Opt_sig_2};
|
||||
% Opt_sig_wdm = Optical_Multiplex("fs_in",Opt_sig.fs,"fs_out",4*Opt_sig.fs,...
|
||||
@@ -117,7 +117,7 @@ classdef Optical_Multiplex < handle
|
||||
% adapt frequency shifts to match the FFT grid! Find nearest grid point
|
||||
[glitch(o),pos] = min(abs( freqaxis-obj.df_T(o) ));
|
||||
obj.df_T(o) = freqaxis(pos);
|
||||
|
||||
|
||||
polrots = [polrots, data_in{o}.polrot];
|
||||
end
|
||||
|
||||
@@ -139,25 +139,36 @@ classdef Optical_Multiplex < handle
|
||||
|
||||
x_envelopes = NaN([blocklen_out N]);
|
||||
y_envelopes = x_envelopes;
|
||||
|
||||
|
||||
% ---- OPTIMIZED: Pre-compute all LO phases as [blocklen_out × N] matrix ----
|
||||
time_idx = (0:blocklen_out-1).'; % [blocklen_out × 1]
|
||||
lo_phases = mod(2*pi * time_idx * obj.df_T / obj.fs_out, 2*pi); % [blocklen_out × N]
|
||||
lo_all = cos(lo_phases) + 1i*sin(lo_phases); % [blocklen_out × N]
|
||||
|
||||
% Collect all resampled signals first (still requires loop due to cell array)
|
||||
x_signals = zeros(blocklen_out, N);
|
||||
y_signals = zeros(blocklen_out, N);
|
||||
|
||||
for o = 1:N
|
||||
|
||||
pha = mod(2*pi*(0:blocklen_out-1)*obj.df_T(o)/obj.fs_out,2*pi).';
|
||||
lo = cos(pha)+1i*sin(pha);
|
||||
data_in_resampled = data_in{o}.resample("fs_out",obj.fs_out);
|
||||
|
||||
res_env = ifft(fft(data_in_resampled.signal(:,1)).*H);
|
||||
x_envelopes(:,o) = att.*res_env.*lo;
|
||||
|
||||
res_env = ifft(fft(data_in_resampled.signal(:,2)).*H);
|
||||
y_envelopes(:,o) = att.*res_env.*lo;
|
||||
|
||||
data_in_resampled = data_in{o}.resample("fs_out", obj.fs_out);
|
||||
x_signals(:, o) = data_in_resampled.signal(:, 1);
|
||||
y_signals(:, o) = data_in_resampled.signal(:, 2);
|
||||
end
|
||||
|
||||
% ---- VECTORIZED: Batched FFT/IFFT for all channels ----
|
||||
% Apply filter to all channels at once
|
||||
x_filtered = ifft(fft(x_signals) .* H); % [blocklen_out × N]
|
||||
y_filtered = ifft(fft(y_signals) .* H); % [blocklen_out × N]
|
||||
|
||||
% Apply attenuation and LO shift to all channels
|
||||
x_envelopes = att .* x_filtered .* lo_all; % [blocklen_out × N]
|
||||
y_envelopes = att .* y_filtered .* lo_all; % [blocklen_out × N]
|
||||
|
||||
data_out = data_in_resampled;
|
||||
data_out.signal = [sum(x_envelopes,2), sum(y_envelopes,2)];
|
||||
data_out.lambda = obj.lambda_T;
|
||||
data_out.polrot = polrots;
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user