I am implementing a simple program to generate tone in MATLAB using FFT/iFFT by zeroing all frequency bins except for the one frequency that I'd like to generate a tone in.

Sampling frequency is 16000 Hz. I am using a 32 point FFT which gives me 16 frequency bins.

FFT data * Equalizer -> iFFT

If I want to generate a frequency of 1000 Hz, After FFT, using the Equalizer, I'd Zero all frequency bins except for frequency bin 2. This will generate a 1 kHz signal.

If I want to generate a frequency of 4000 Hz, After FFT, using the Equalizer, I'd Zero all frequency bins except for frequency bin 8. This will generate a 4 kHz signal.

I implemented this program. Here are the results

For 1 kHz,

enter image description here

For 2500 Hz,

enter image description here

For 5500 Hz,

enter image description here

As you can see from the figure above, the 1 kHz is a clean signal. But as I try to generate higher frequencies, the signals are less smoother. The spectral figure shows that the correct frequency is generated, but i'm wondering if the irregularity is due to Harmonics or an other phenomena?

So how can I generate a more clean signal in the higher frequencies ? And if possible also the reasoning behind these 'irregularities'?


1 Answer 1


The closer a synthesized frequency gets to half the sample rate, the better the reconstruction filter ones needs to reproduce a pure waveform. It looks like your plotting application has a poor reconstruction (upsampling to plot points) filter, causing the resulting plot to look irregular when the signal frequency gets much above about 1/8th the sample rate. A graph using polynomial, spline, or Sinc interpolation for the plot points would likely look much cleaner.

  • $\begingroup$ Just to clarify, the problem lies within the plotting application rather than the output itself. So is there no need to further 'filter/modify' the iFFT output? YOu did mention 'the better reconstruction filter one needs to produce a pure waveform'. So what kind of filter would i need to use ? What is reason behind the irregularity as you get closer to half the sampling rate ? $\endgroup$ Commented Dec 18, 2018 at 9:04
  • $\begingroup$ Yes, the "irregularities" that you observe are solely related to the fact that for higher frequencies less sampling points are used per cycle of your sine wave. I assume that the signal sounds just fine when you listen to it. What hotpaw2 means, as I get it, is that one additional operation happens between MATLAB, where you look at the time-domain signal, and the sound card that converts the samples into an analog signal: Interpolation. Hence, what you see is not what you hear. $\endgroup$
    – applesoup
    Commented Jan 17, 2019 at 10:10
  • $\begingroup$ Yes. When you “play” such sampled waveforms, the players DAC anti-alias filter, the weight (impedance) of the speakers, and maybe the cochlea in your ear, all act to filter (similar to interpolate) the sound waveform. $\endgroup$
    – hotpaw2
    Commented Jan 17, 2019 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.