%
%  enforced_motion_modal_transient_engine_fea_plate.m  ver 1.2  by Tom Irvine
%

function[aa,dd]=enforced_motion_modal_transient_engine_fea_plate(FP,a1,a2,df1,df2,df3,...
                                    ~,~,~,af1,af2,af3,nt,num_modes,Q,retdof)
%

% Coeffs per mode (rows)
bD = [df1(:) df2(:) df3(:)];                 % displacement numerators
bA = [af1(:) af2(:) af3(:)];                 % acceleration numerators
aC = [ones(num_modes,1) -a1(:) -a2(:)];      % common denominators

nx = zeros(nt,num_modes,'like',FP);
na = zeros(nt,num_modes,'like',FP);

for j = 1:num_modes
    am = FP(j,:);                 % 1×nt
    den = aC(j,:);
    nx(:,j) = filter(bD(j,:), den, am).';   % nt×1
    na(:,j) = filter(bA(j,:), den, am).';   % nt×1
end

%
disp(' Calculate d');

% Q: p×m, nx: nt×m, retdof ∈ [1..p]
dd = nx * Q(retdof,:).';        % nt×1

clear nx;

%%%%

disp(' Calculate a');

% retdof is a single index, na is nt×m, Q is sz(1)×m
aa = na * Q(retdof, :).';   % nt×1