title: How to control the length and sampling time of the output of ifft in MATLAB?
body: <p>I have data in frequency domain that looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Wm5zr.gif" alt="enter image description here"></p>
  
  <p>This means I have a vector Y that contains the amplitude for the frequency points in the vector x. For example</p>
  
  <pre><code>f = [0 1 2 3 4 5 6 7 8 9 10]
  Y = [0 0 0 0 0 1 0 0 0 0  0]
  </code></pre>
  
  <p>Performing an inverse fourier transform should give a sine wave with the frequency 5Hz.</p>
  
  <p>The MATLAB function ifft can transform Y and f to time domain. Lets call the vectors in time domain y and t. I'm looking for a way how to get time domain data with a specified samplig frequency and a specified signal length. For example, I want time domain data with a signal length of 1 second and a sampling frequency of 1000Hz.</p>
  
  <p>The output of MATLABs ifft function has always the same length as the input, so I'm not sure what to give as input to get the required sampling frequency and signal length.</p>
  
  <p>To sum it up, I'm trying to write a MATLAB function</p>
  
  <pre><code>[t,y] = custom_ifft(f,Y,sampling_frequency,signal_length)
  </code></pre>
  
  <p>that converts the frequency domain data (f,Y) to time domain data (t,y), where the length of the time vector t can be specified in signal length (for example 1 second) and the sampling frequency ( length(y)/signal_length ) can be specified with sampling_frequency</p>
  
  <p>EDIT:
  Please include in your answer the MATLAB code how to implement your idea. I already have the concept of how to do it, but I can't get the actual implementation to work.
  I'm specifically asking what to give as input argument to the ifft function:</p>
  
  <pre><code>y = ifft(input_arg);
  </code></pre>
  
  <p>I'm looking for MATLAB code how to create input_arg when (f,Y,sampling_frequency,signal_length) are known.</p>
  
  <p>Here is my implementation that does not work as expected:</p>
  
  <pre><code>Y = [0 zeros(1,100) 1 0 0 zeros(1,500) 0 0 1 zeros(1,100)];
  Y_interp = interp1(Y,linspace(1,length(Y),2*length(Y)));
  y = ifft(Y) ;
  y_interp = ifft(Y_interp);
  figure;
  plot(y);
  figure;
  plot(real(y_interp));
  figure;
  plot(abs(y_interp));
  </code></pre>