# Phase Issue in IFFT Hi all, I've been trying to zero centre a waveform prior to IFFT. my recent attempts are based on the following code which is producing the waveform below. I don't understand why this isn't working or why there are notches in the sawtooth wave. Is my math incorrect?

The following code snippet is used to center it.

zeroStartRadianValue = 2*PI*f0/fs*NFFT*0.50*-1.0;

• You will need to give more information: What is the above plot of? How was it generated? There appear to be two graphs there? What are they?
– Peter K.
Sep 11 '15 at 2:02
• The Plot is the left and right channel of the synthesized signal. The signal is a sawtooth waveform. The spectrum was generating by analysing a near perfect (mathematical) sawtooth audio clip, analysing it to extract out the harmonic mags and phases and then resynthesizing it via an IFFT using the extracted spectrum centering the start phase using the above line of code. The artifacts in the waveform are the 'teeth' in the descending slope. I'm wondering if these teeth are caused by an incorrect calculation in the above code. Sep 11 '15 at 2:27
• The code you posted does nothing but compute a value. If you have some artifact creeping in then in is certainly in the code in which you are doing something with the value. Without sharing more about that process nobody is going to be able to help you. Sep 11 '15 at 6:22
• For me it looks perfectly ok. That's what sawtooth wave without aliasing looks like.
– jojek
Sep 11 '15 at 8:35

As @jojek says, this looks precisely correct. It's like Gibbs phenomenon, but for a sawtooth.

The wikipedia page for the sawtooth has this way to write a sawtooth:

$$x(t) = \frac{A}{2} - \frac{A}{\pi} \sum_{k=1}^{\infty} \frac{\sin(2\pi k f t)}{k}$$

which yields the image below, showing gradual convergence over summing the first 10 terms. If I just use 64 terms, then this is what I get: Scilab code is below.

// 25750
// https://en.wikipedia.org/wiki/Sawtooth_wave
clf
f = 0.01;
N = 200;
t = [0:N-1];
A = 1;
graphs = ["","r","g","k",":","r:","g:","k:",".","r.","g.","k.",]
idx = 1;
for h=1:10,
x = A/2*ones(1,N);
for k=1:h,
x = x - A/%pi * sin(2*%pi*k*f*t)/k;
end
plot(t,x,graphs(idx))
idx = idx + 1;
end

• Thanks for the responses. I was expecting something smoother in my waveform as I'm using 64 terms. Sep 11 '15 at 19:47
• @cixelsyd : Same problem: you need MANY more than 64 to accurately represent any waveform with discontinuities in it.
– Peter K.
Sep 11 '15 at 20:13
• Thanks Peter. and thanks for the scilab plots and code. I've been struggling with Octave and scilab looks like it could be a good alternative. Again thanks for the code and the plot. Sep 11 '15 at 22:33