Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3361124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:06:53+00:00 2026-05-18T03:06:53+00:00

I am trying to write a simple DCT algorithm in java. I want my

  • 0

I am trying to write a simple DCT algorithm in java. I want my findDCT method to have as a parameter an integer array like this:

public class DCT {
    private Random generator = new Random();
    private static final int N = 8;
    private int[][] f = new int[N][N];
    private double[] c = new double[N];

    public DCT() {
        this.initializeCoefficients();
    }

    private void initializeCoefficients() {
        int value;

        // temporary - generation of random numbers between 0 and 255 
        for (int x=0;x<8;x++) {
            for (int y=0;y<8;y++) {
              value = generator.nextInt(255);
              f[x][y] = value;
              System.out.println("Storing: "+value+" in: f["+x+"]["+y+"]");
            }
        }

        for (int i=1;i<N;i++) {
            c[i]=1/Math.sqrt(2.0);
            System.out.println("Storing: "+c[i]+" in: c["+i+"]");
        }
        c[0]=1;
    }

    public double[][] applyDCT() {
        double[][] F = new double[N][N];
        for (int u=0;u<N;u++) {
              for (int v=0;v<N;v++) {
                double somme = 0.0;
                for (int i=0;i<N;i++) {
                  for (int j=0;j<N;j++) {
                    somme+=Math.cos(((2*i+1)/(2.0*N))*u*Math.PI)*Math.cos(((2*j+1)/(2.0*N))*v*Math.PI)*f[i][j];
                  }
                }
                somme*=(c[u]*c[v])/4;
                F[u][v]=somme;
              }
            }
        return F;
    }
}

Now, how would I declare this method and to be able to pass ‘int[][] f’ as a parameter instead of using f[][] declared as a private variable and initialized in the constructor of the current class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:06:54+00:00Added an answer on May 18, 2026 at 3:06 am

    How about extracting the initializeCoefficients and changing the constructor from

    public DCT() {
        this.initializeCoefficients();
    }
    

    to

    public DCT(int[][] f) {
        this.f = f;
    }
    

    You could then use the class like

    double[][] dctApplied = new DCT(yourTwoDimF).applyDCT();
    

    Also, I wouldn’t use N the way you do. I would look at the dimensions of f itself when applying the DCT.

    That is, I would change

        double[][] F = new double[N][N];
        for (int u=0;u<N;u++) {
              for (int v=0;v<N;v++) {
                  // ...
    

    to something like

        double[][] F = new double[f.length][];
        for (int u = 0; u < f.length; u++) {
              F[u] = new double[f[u].length];
              for (int v=0;v<N;v++) {
                  // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write simple Visual Studio Add-In for code generation. In my
I'm trying to write a simple game/utility to calculate poker odds. I know there's
I'm trying to write a simple program in VC++ which will just initialize the
I'm trying to write a simple WPF app that has two ellipses, joined by
I'm trying to write a simple raytracer as a hobby project and it's all
I'm just starting out writing trying to write a simple program in C and
I'm trying to write a super-simple podcast-to-device downloading service to use for running. I
I am trying to write a really simple Outlook VSTO add in that checks
I'm trying to think of clever, clear, and simple ways to write code that
I am trying to write a console app that simply lists the number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.