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 8414183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:05:58+00:00 2026-06-10T01:05:58+00:00

The Octave radix-4 FFT code below works fine if I set power of 4

  • 0

The Octave radix-4 FFT code below works fine if I set power of 4 (xp) values case-by-case.

$ octave fft4.m

ans = 1.4198e-015

However, if I uncomment the loop code I get the following error

$ octave fft4.m

error: `stage' undefined near line 48 column 68
error: evaluating argument list element number 1
error: evaluating argument list element number 2
error: called from:
error:   r4fftN at line 48, column 22
error:   c:\Users\david\Documents\Visual Studio 2010\Projects\mv_fft\fft4.m at line 80, column 7

the "error" refers to a line the in fft function code which otherwise works correctly when xp is not set by a loop ... very strange.


    function Z = radix4bfly(x,segment,stageFlag,W)
      % For the last stage of a radix-4 FFT all the ABCD multiplers are 1.
      % Use the stageFlag variable to indicate the last stage
      % stageFlag = 0 indicates last FFT stage, set to 1 otherwise

      % Initialize variables and scale to 1/4
      a=x(1)*.25;
      b=x(2)*.25;
      c=x(3)*.25;
      d=x(4)*.25;

      % Radix-4 Algorithm
      A=a+b+c+d;
      B=(a-b+c-d)*W(2*segment*stageFlag + 1);
      C=(a-b*j-c+d*j)*W(segment*stageFlag + 1);
      D=(a+b*j-c-d*j)*W(3*segment*stageFlag + 1);

      % assemble output
      Z = [A B C D];
    end % radix4bfly()


    % radix-4 DIF FFT, input signal must be floating point, real or complex
    %
    function S = r4fftN(s)

      % Initialize variables and signals: length of input signal is a power of 4
      N = length(s);
      M = log2(N)/2;

      % Initialize variables for floating point sim
      W=exp(-j*2*pi*(0:N-1)/N);
      S = complex(zeros(1,N));
      sTemp = complex(zeros(1,N));

      % FFT algorithm
      % Calculate butterflies for first M-1 stages
      sTemp = s;
      for stage = 0:M-2
        for n=1:N/4
          S((1:4)+(n-1)*4) = radix4bfly(sTemp(n:N/4:end), floor((n-1)/(4^stage)) *(4^stage), 1, W);
        end
        sTemp = S;
      end

      % Calculate butterflies for last stage
      for n=1:N/4
        S((1:4)+(n-1)*4) = radix4bfly(sTemp(n:N/4:end), floor((n-1)/(4^stage)) * (4^
    stage), 0, W);
      end
      sTemp = S;

      % Rescale the final output
      S = S*N;
    end % r4fftN(s)


    % test FFT code
    %
    xp = 2;

    % ERROR if I uncomment loop!

    %for xp=1:8
      N = 4^xp; % must be power of: 4 16 64 256 1024 4086 ....
      x = 2*pi/N * (0:N-1);
      x = cos(x);
      Y_ref = fft(x);
      Y = r4fftN(x);
      Y = digitrevorder(Y,4);
      %Y = bitrevorder(Y,4);
      abs(sum(Y_ref-Y)) % compare fft4 to built-in fft
    %end
  • 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-06-10T01:06:00+00:00Added an answer on June 10, 2026 at 1:06 am

    The problem was the loop-bound for the exponent xp should start from 2 as the fft4 code assumes at least 2 stages of radix-4 butterflies

    Sorry folks 🙁

    -David

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ubuntu 12.04 and Octave: $ octave octave:1> _ I set my
I would like to save and load a set of images in Octave /
Maybe I'm spoiled by Python, but does Octave allows one to assign the values
I'm playing with octave's fft functions, and I can't really figure out how to
I am porting code created in octave into pylab. One of the ported equations
I set an alias in my .bash_profile for Octave alias octave=open /Applications/Octave.app It opens
I'm trying to port some Octave code to Java. I'm trying out atan2 so
What's wrong with my code? octave:26> plot([1;2;3;4],[1;8;27;64], 'marker', 'o', 'linestyle', 'none', 'marker', 'o', 'markeredgecolor',
I used to use matrix in octave to store data from data set, in
In GNU Octave, I'm getting an error with this code. A = cell(10,1); A{5,1}

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.