Using filter in Poisson solver

Hello! I am trying to implement a filter on poisson solver matrix for periodic grid. So, I have x and y grid where y is periodic, hence I can decouple in y using fft. Now, if I were to apply a filter around a particular mode, say k, I can run over the y loop and select only modes in vicinity of k. To do so, I wrote the function :

function build_fft_solver_filtered(p::Int, grid_x::Vector{Float64}, n_y::Int, m::Real, delta::Real; L::Float64=1.0)
    # x-direction: build non–uniform knot vector and matrices.
    local knots_x = construct_knots(grid_x, p)
    local n_x = length(knots_x) - p - 1
    local Mx = assemble_mass_matrix(p, knots_x)
    local Kx = assemble_stiffness_matrix(p, knots_x)
    # Apply Dirichlet BC on x (first and last DOF)
    for i in (1, n_x)
        @inbounds begin
            Mx[i, :] .= 0.0; Mx[:, i] .= 0.0; Mx[i, i] = 1.0
            Kx[i, :] .= 0.0; Kx[:, i] .= 0.0; Kx[i, i] = 1.0
        end
    end
    # y-direction: build periodic knot vector with period L.
    local knots_y = construct_periodic_knots(n_y, p, L)
    local My = assemble_mass_matrix_periodic(p, knots_y, n_y)
    local Ky = assemble_stiffness_matrix_periodic(p, knots_y, n_y)
    local lam_M_y = fft(My[:,1])
    local lam_K_y = fft(Ky[:,1])
    local factors = Vector{Union{LU{Float64, Matrix{Float64}}, Nothing}}(undef, n_y)
    local allowed = Vector{Bool}(undef, n_y)
    for k in 1:n_y
        local ω = freq(k, n_y, L)
        if abs(ω - m) <= delta
            allowed[k] = true
            local A_k = lam_M_y[k]*Kx + lam_K_y[k]*Mx
            A_k = real(A_k)
            factors[k] = lu(A_k)
        else
            allowed[k] = false
            factors[k] = nothing
        end
    end
    return FFTDecoupledSolverFiltered(p, grid_x, knots_x, n_x, n_y, knots_y, Mx, Kx, lam_M_y, lam_K_y, factors, allowed, L)
end

The above function computes the block of matrices to solve for the system of linear equations. The is based on typical Galerkin method.

Now, if I were to implement a filter for mode k based on the location of x grid value (say, k = c*x[i]), what would be the most efficient way? I need to precompute this matrix in order to use it a number of times on the same grid for the system. Also, is there a more efficient way to write the same thing keeping performance in mind?