Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduction of Gibbs Phenomenon on FFT compression #124

Merged
merged 8 commits into from
Oct 5, 2024
Merged

Conversation

cjrolo
Copy link
Collaborator

@cjrolo cjrolo commented Oct 3, 2024

Current FFT implementation disregards the Gibbs phenomenon at the boundaries of the frame. This creates artifacts that need correction at those transitions.

This PR fixes the Gibbs phenomenon at the frame edge by expanding the frames during the FFT calculation (and inverse calculation) with either the first or last value of the frame.
This creates an attenuation effect without impacting the compression ratio. The tradeoff is more memory consumption (up to 5%) on the use of the FFT compressor.

This image illustrates a frame transition with the current code base and the one purposed by this fix.
image

@cjrolo cjrolo requested review from rukai and worryg0d October 3, 2024 15:50
@cjrolo
Copy link
Collaborator Author

cjrolo commented Oct 3, 2024

@rukai asking for your help on this review due to the way vectors/arrays are being padded, sliced and cloned.

Any suggestions to improve the performance of this code is welcome!

Thanks,

Carlos

Copy link
Contributor

@rukai rukai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heres a bunch of things you can do to reduce allocations.
That loop scares me though, I dont have the math skills to reduce it to an expression, but if its possible then that seems important.

/// Given a number N, checks what is the next number that is in the form of (2^N * 3^M)
pub fn next_size(mut n: usize) -> usize {
n += 1;
while !is_decomposable(n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this looping looks slow, are you sure there isnt a way to get the same result with an expression instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prime numbers are a pain! And I don't see how I can improve this. Let me see if I find a better solution.
This is only run once per frame on compression and decompression.
Given that we force frames into a subset of sizes (and power of 2^N) I don't expect this to loop for long. On larger numbers it might become problematic.
Alternative is providing a table of next number for the expected frame sizes and calculate for everything else? (We have some pre-defined frame sizes hardcoded anyway).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A table does sound like a good idea.
Could be left for follow up work.

brro-compressor/src/compressor/fft.rs Outdated Show resolved Hide resolved
brro-compressor/src/compressor/fft.rs Outdated Show resolved Hide resolved
brro-compressor/src/compressor/fft.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@worryg0d worryg0d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching issues at e2e. It's a bit embarrassing to see how I messed up here.

@cjrolo
Copy link
Collaborator Author

cjrolo commented Oct 4, 2024

Thanks for catching issues at e2e. It's a bit embarrassing to see how I messed up here.

Everyone makes mistakes, the tests did their job and that is why I caught them! :)

@cjrolo cjrolo merged commit c3e8c0a into main Oct 5, 2024
2 checks passed
@cjrolo cjrolo deleted the fft-artifact-control branch October 5, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants