DSPRelated.com
Forums

Please verify my "solution" to FFT scale factors

Started by Unknown February 23, 2015
Dear DSP masters!!

I'm using the FFTW C library to evaluate some signal processing ideas. As I have Richard Lyons Understanding ... book I first tried his DFT example of paragraph 3.1.1 in order to check if the FFT results are matching. They did.

But I would like to use the FFT to get a correct frequency domain representation, so the outputs must be properly scaled.

Note: I'm using the FFTW library with a complex input and a complex output.

After the forward FFT operation I divide each individual real and imaginary part by N / 2. And after the inverse FFT operation I divide each individual real and imaginary part by 2.

This way the magnitudes in the frequency domain are correct and the inverse yields the original time domain input signal.

Alright? Am I good to go further? Or could there be complications doing it this way? It is a bit strange to me that I can't find a resource to back this up. My solution seems pretty logical, why does it look like nobody else is using this approach?

Best regards,
Zeyneb
On 2/23/15 11:45 AM, m_r_verhage@hotmail.com wrote:
> Dear DSP masters!! > > I'm using the FFTW C library to evaluate some signal processing ideas. As I have Richard Lyons Understanding ... book I first tried his DFT example of paragraph 3.1.1 in order to check if the FFT results are matching. They did. > > But I would like to use the FFT to get a correct frequency domain representation, so the outputs must be properly scaled. > > Note: I'm using the FFTW library with a complex input and a complex output. > > After the forward FFT operation I divide each individual real and imaginary part by N/2. And after the inverse FFT operation I divide each individual real and imaginary part by 2. > > This way the magnitudes in the frequency domain are correct and the inverse yields the original time domain input signal. > > Alright? Am I good to go further? Or could there be complications doing it this way? It is a bit strange to me that I can't find a resource to back this up. My solution seems pretty logical, why does it look like nobody else is using this approach?
not sure you need those two factors of 2. it should be N and 1. anyway, the most common *convention* of the DFT is without the 1/N in front of the summation, which requires the iDFT to have a 1/N in front of it. i would do it the other way around and assume that x[n] is the sum of some basis set e^(j 2 pi nk/N) (without the 1/N) and that would require the forward DFT to have 1/N. that's the simplest pedagogical convention from my POV. so i think the output of the DFT is N times too big using the common convention. some folks split the difference and put 1/sqrt(N) in front of the summation in *both* DFT and iDFT. that's the "unitary" DFT, the forward and inverse DFT look qualitatively identical. and it preserves total energy in the transformation. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Hi Robert,

Thanks for your message. 

I am going to explain to you why I would like to include the two factors of 2.

In the original time domain I've created this signal:

sin( (2.0 * M_PI * 1000 * i) / Fs )

It is a 1 kHz signal with a magnitude of 1.

Now I simply want my frequency domain output bin have that same magnitude of 1. Assuming N = 8, without scaling X(1) is 4 (as by Lyons example), dividing by N / 2 = 4 yields an final result of 1. So that's the frequency spectrum I would like to see. And in order to get the same original time domain signal back, I have to divide the inverse FFT outputs by 2.

Best regards,
Zeyneb


On 2/23/2015 2:00 PM, m_r_verhage@hotmail.com wrote:
> Hi Robert, > > Thanks for your message. > > I am going to explain to you why I would like to include the two factors of 2. > > In the original time domain I've created this signal: > > sin( (2.0 * M_PI * 1000 * i) / Fs ) > > It is a 1 kHz signal with a magnitude of 1. > > Now I simply want my frequency domain output bin have that same magnitude of 1. Assuming N = 8, without scaling X(1) is 4 (as by Lyons example), dividing by N / 2 = 4 yields an final result of 1. So that's the frequency spectrum I would like to see. And in order to get the same original time domain signal back, I have to divide the inverse FFT outputs by 2.
Perhaps I don't follow how you measure amplitude. It would appear you are using the peak value, not the peak to peak value? In other words you want the multiplier that would be applied to the sin function as your magnitude, yes? I guess that is a math way of measuring the amplitude while I tend to think more of the EE way of looking at it, either p-p or RMS. -- Rick
On 2/23/15 2:55 PM, rickman wrote:
> On 2/23/2015 2:00 PM, m_r_verhage@hotmail.com wrote: >> Hi Robert, >> >> Thanks for your message. >> >> I am going to explain to you why I would like to include the two >> factors of 2. >> >> In the original time domain I've created this signal: >> >> sin( (2.0 * M_PI * 1000 * n) / Fs ) >> >> It is a 1 kHz signal with a magnitude of 1.
(i changed "i" to "n".)
>> >> Now I simply want my frequency domain output bin have that same >> magnitude of 1. Assuming N = 8, without scaling X(1) is 4 (as by Lyons >> example), dividing by N / 2 = 4 yields an final result of 1. So that's >> the frequency spectrum I would like to see. And in order to get the >> same original time domain signal back, I have to divide the inverse >> FFT outputs by 2. > > Perhaps I don't follow how you measure amplitude.
see below...
> It would appear you > are using the peak value, not the peak to peak value? In other words you > want the multiplier that would be applied to the sin function as your > magnitude, yes? > > I guess that is a math way of measuring the amplitude while I tend to > think more of the EE way of looking at it, either p-p or RMS.
well, the DFT way of looking at it is with the amplitude of e^(j*2*pi*f0/Fs*n) rather than the amplitude of (e^(j*2*pi*f0/Fs*n) + e^(-j*2*pi*f0/Fs*n))/(2) or (e^(j*2*pi*f0/Fs*n) - e^(-j*2*pi*f0/Fs*n))/(2j) me thinks Zeyneb is considering only positive frequencies. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
> > Hi Robert, > > > > Thanks for your message. > > > > I am going to explain to you why I would like to include the two factors of 2. > > > > In the original time domain I've created this signal: > > > > sin( (2.0 * M_PI * 1000 * i) / Fs ) > > > > It is a 1 kHz signal with a magnitude of 1. > > > > Now I simply want my frequency domain output bin have that same magnitude of 1. Assuming N = 8, without scaling X(1) is 4 (as by Lyons example), dividing by N / 2 = 4 yields an final result of 1. So that's the frequency spectrum I would like to see. And in order to get the same original time domain signal back, I have to divide the inverse FFT outputs by 2. > > Perhaps I don't follow how you measure amplitude. It would appear you > are using the peak value, not the peak to peak value? In other words > you want the multiplier that would be applied to the sin function as > your magnitude, yes? > > I guess that is a math way of measuring the amplitude while I tend to > think more of the EE way of looking at it, either p-p or RMS. > > -- > > Rick
Hi Rickman, Nice you're responding. I know you for your awesome synchronization circuit for crossing clock domains in FPGAs. I heavily made use of this circuit at a former job. Primarily after writing a FIFO and signaling the other side to start reading it. You know this one: "sync circuit to generate a single pulse in the target clock domain regardless of the relative speed of the clocks." Ok, now about the scale factors. Yes I now do realize the different ways the amplitude can be specified. I took a look on how spectrum analyzers would deal with that for a conventional suggestion and it would display it as the RMS, like you said. So to get those results: After the forward FFT operation I divide each individual real and imaginary part by N / sqrt(2). And after the inverse FFT operation I divide each individual real and imaginary part by sqrt(2). Alright? Still it is very strange to me that I cannot find a resource that support my approach while it seems so very common. Why? Could you explain please? Best regards, Zeyneb
On 2/24/15 7:30 AM, m_r_verhage@hotmail.com wrote:
> > Still it is very strange to me that I cannot find a resource that support my approach while it seems so very common. Why? Could you explain please? >
Z, i'm not Rickman but i think i already had explained it. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On 2/24/2015 7:30 AM, m_r_verhage@hotmail.com wrote:
> >>> Hi Robert, >>> >>> Thanks for your message. >>> >>> I am going to explain to you why I would like to include the two factors of 2. >>> >>> In the original time domain I've created this signal: >>> >>> sin( (2.0 * M_PI * 1000 * i) / Fs ) >>> >>> It is a 1 kHz signal with a magnitude of 1. >>> >>> Now I simply want my frequency domain output bin have that same magnitude of 1. Assuming N = 8, without scaling X(1) is 4 (as by Lyons example), dividing by N / 2 = 4 yields an final result of 1. So that's the frequency spectrum I would like to see. And in order to get the same original time domain signal back, I have to divide the inverse FFT outputs by 2. >> >> Perhaps I don't follow how you measure amplitude. It would appear you >> are using the peak value, not the peak to peak value? In other words >> you want the multiplier that would be applied to the sin function as >> your magnitude, yes? >> >> I guess that is a math way of measuring the amplitude while I tend to >> think more of the EE way of looking at it, either p-p or RMS. >> >> -- >> >> Rick > > Hi Rickman, > > Nice you're responding. I know you for your awesome synchronization circuit for crossing clock domains in FPGAs. I heavily made use of this circuit at a former job. Primarily after writing a FIFO and signaling the other side to start reading it. > > You know this one: > > "sync circuit to generate a single pulse in the target clock domain regardless of the relative speed of the clocks."
I can't take credit for that circuit as I didn't invent it. Someone showed it to me once and I found it had tremendous potential for application when crossing clock boundaries. It also can be modified for a wide variety of circumstances. The main thing is to understand how it works, what its benefits are and what are its limitations. Like most things, no?
> Ok, now about the scale factors. Yes I now do realize the different ways the amplitude can be specified. I took a look on how spectrum analyzers would deal with that for a conventional suggestion and it would display it as the RMS, like you said. > > So to get those results: > > After the forward FFT operation I divide each individual real and imaginary part by N / sqrt(2). And after the inverse FFT operation I divide each individual real and imaginary part by sqrt(2). > > Alright? Still it is very strange to me that I cannot find a resource that support my approach while it seems so very common. Why? Could you explain please?
I remember this being mentioned by a professor in school. He said there was this factor of gain when doing the FFT and inverse FFT. Rather than get back what you started with, it is multiplied by this factor. So to correct for that you must divide by this factor. Where you do the division is arbitrary and varies according to the preference of the user or application. I won't argue that one way is better than another. If that works for you, then by all means use it. My previous comment was more about what is considered to be the amplitude of sin(x). A mathematician would say it is 1. I think a EE would want to call it either 1/sqrt(2) or 2 when in a circuit since those values correspond to the RMS value or the peak to peak value respectively. But I think that is not relevant to the question you are asking. -- Rick