title: Shifting the FFT of a signal in Matlab
body: <p>I'm trying to implement a spectral correlation function to plot with the surf function. 
  I think I understand the idea of the SCF as described in a paper I read, but I'm having trouble implementing my function in Matlab. I've been following these instructions:</p>
  
  <p><img src="https://i.stack.imgur.com/hjqa9.png" alt="Pseudo-code"></p>
  
  <p>I'm mostly having trouble shifting my pieces of the data properly. Is there an easy way to achieve step 3? </p>
  
  <p>Here's what I tried in my code: </p>
  
  <pre><code>function [output] = spectral(x, N)
      % This function does cyclostationary spectral analysis 
      % on a data set and returns some features
  
      t = length(x); 
      samplesPerFrame = floor(t / N); 
  
      count = 1; 
  
      for alpha = -1:0.01:1
  
  
  
          % Split up the samples into frames
          % Have to leave some samples out if unevenly split
          for i = 1:N+1
              frange = ((i - 1) * samplesPerFrame + 1):(i * samplesPerFrame);
              if i == N+1
                  break;
              end
              xFrame(i, :) = x(frange);
              ts = [1:length(xFrame(i,:))]; 
              shiftLeft = fft(xFrame(i, :) .* exp(-1 * 2 * pi * 1i * (alpha / 2) .* ts));
              shiftRight = fft(xFrame(i, :).* exp(2 * pi * 1i * (alpha / 2) .* ts)); 
  
              S(i,:) = (1 / samplesPerFrame) .* shiftLeft .* conj(shiftRight);
  
          end
  
          Savg(count, :) = mean(S, 1);
          Ssmooth(count, :) = smooth(Savg(count,:), 'moving'); 
          count = count + 1; 
      end
      output = Ssmooth; 
  end
  </code></pre>