Prev: Interaction of MEX and MATLAB or mexCallMATLAB and Co.
Next: the distance between two time series
From: Steve Amphlett on 27 Apr 2010 12:03 Greg Heath <heath(a)alumni.brown.edu> wrote in message <0bb0996b-f5fc-455e-8101-b4ff3c7651d1(a)j15g2000vbq.googlegroups.com>... > On Apr 27, 2:50 am, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- > Work.com> wrote: > > Greg Heath <he...(a)alumni.brown.edu> wrote in message <c17b6883-f695-4934-877c-838b7ff5f...(a)n5g2000yqh.googlegroups.com>... > > > On Apr 26, 11:05 am, Luis <luisthearc...(a)gmail.com> wrote: > > > > Hi. > > > > > > In the example on how to use fft, once they have the signal, they do this: > > > > > > NFFT = 2^nextpow2(L); % Next power of 2 from length of y > > > > Y = fft(y,NFFT)/L; > > > > > > Meaning that they get the next power of 2 from length of y (the signal), and then they calculate the NFFT-points fft, to then divide it by L (length of y). > > > > ¿Can you tell me why they do that? > > > > > > What I'm trying to do is capture a sound signal and then with the fft get the frequency of that signal. > > > > > > Thank you! > > > > > 1. You don't have to do either. > > > > > a. If L is huge and/or you have to process many cases, > > > you can reduce running time by a factor of log(NFFT)/L . > > > If this doesn't concern you, just use > > > > > Y = fft(y)/L. > > > > > b. The normalizing factor L will yield an amplitude of 1 > > > for exp(i*2*f0*t) at f = f0. > > > > > Hope this helps. > > > > > Greg > > > > ... except at DC and Nyquist, where you need 2/L > > No. > > >> Fs = 1, N = 6, dt = 1/Fs > t = dt*(0:N-1); > x = 1 + cos(2*pi*(Fs/2)*t); > X = fft(x)/N > > Fs = 1 > N = 6 > dt = 1 > > X = 1 0 0 1 0 0 > > Hope this helps. > > Greg Is this a recent change?
From: Greg Heath on 27 Apr 2010 20:40 On Apr 27, 12:03 pm, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- Work.com> wrote: > Greg Heath <he...(a)alumni.brown.edu> wrote in message <0bb0996b-f5fc-455e-8101-b4ff3c765...(a)j15g2000vbq.googlegroups.com>... > > On Apr 27, 2:50 am, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- > > Work.com> wrote: > > > Greg Heath <he...(a)alumni.brown.edu> wrote in message <c17b6883-f695-4934-877c-838b7ff5f...(a)n5g2000yqh.googlegroups.com>... ----SNIP > > > > Y = fft(y)/L. > > > > > b. The normalizing factor L will yield an amplitude of 1 > > > > for exp(i*2*f0*t) at f = f0. > > > > ... except at DC and Nyquist, where you need 2/L > > > No. > > > >> Fs = 1, N = 6, dt = 1/Fs > > t = dt*(0:N-1); > > x = 1 + cos(2*pi*(Fs/2)*t); > > X = fft(x)/N > > > Fs = 1 > > N = 6 > > dt = 1 > > > X = 1 0 0 1 0 0 > > > Is this a recent change? No. Too make things more clear: >> x1 = 1 + exp(i*2*pi*(Fs/2)*t'); x2 = 1 + exp(-i*2*pi*(Fs/2)*t'); x = [x1 x2] x0 = mean(x) X = fft(x)/N x = 2 2 0 +1.2246e-016i 0 -1.2246e-016i 2 -2.4493e-016i 2 +2.4493e-016i 0 +3.6739e-016i 0 -3.6739e-016i 2 -4.8986e-016i 2 +4.8986e-016i 0 +6.1232e-016i 0 -6.1232e-016i x0 = 1 +6.1232e-017i 1 -6.1232e-017i X = 1 +6.1232e-017i 1 -6.1232e-017i -3.5353e-017 +6.1232e-017i 3.5353e-017 -6.1232e-017i -1.0606e-016 +6.1232e-017i 1.0606e-016 -6.1232e-017i 1 -3.0616e-016i 1 +3.0616e-016i 1.0606e-016 +6.1232e-017i -1.0606e-016 -6.1232e-017i 3.5353e-017 +6.1232e-017i -3.5353e-017 -6.1232e-017i or, after thresholding x = 2 2 0 0 2 2 0 0 2 2 0 0 x0 = 1 1 X = 1 1 0 0 0 0 1 1 0 0 0 0 Hope this helps. Greg
From: Steve Amphlett on 28 Apr 2010 04:43 Greg Heath <heath(a)alumni.brown.edu> wrote in message <2f45f49b-2586-4d1b-badf-8b3687382c2c(a)y12g2000vbr.googlegroups.com>... > On Apr 27, 12:03 pm, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- > Work.com> wrote: > > Greg Heath <he...(a)alumni.brown.edu> wrote in message <0bb0996b-f5fc-455e-8101-b4ff3c765...(a)j15g2000vbq.googlegroups.com>... > > > On Apr 27, 2:50 am, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- > > > Work.com> wrote: > > > > Greg Heath <he...(a)alumni.brown.edu> wrote in message <c17b6883-f695-4934-877c-838b7ff5f...(a)n5g2000yqh.googlegroups.com>... > ----SNIP > > > > > > Y = fft(y)/L. > > > > > > > b. The normalizing factor L will yield an amplitude of 1 > > > > > for exp(i*2*f0*t) at f = f0. > > > > > > ... except at DC and Nyquist, where you need 2/L > > > > > No. > > > > > >> Fs = 1, N = 6, dt = 1/Fs > > > t = dt*(0:N-1); > > > x = 1 + cos(2*pi*(Fs/2)*t); > > > X = fft(x)/N > > > > > Fs = 1 > > > N = 6 > > > dt = 1 > > > > > X = 1 0 0 1 0 0 > > > > > > Is this a recent change? > > No. > > Too make things more clear: > > >> x1 = 1 + exp(i*2*pi*(Fs/2)*t'); > x2 = 1 + exp(-i*2*pi*(Fs/2)*t'); > x = [x1 x2] > x0 = mean(x) > X = fft(x)/N > > x = > 2 2 > 0 +1.2246e-016i 0 -1.2246e-016i > 2 -2.4493e-016i 2 +2.4493e-016i > 0 +3.6739e-016i 0 -3.6739e-016i > 2 -4.8986e-016i 2 +4.8986e-016i > 0 +6.1232e-016i 0 -6.1232e-016i > > x0 = 1 +6.1232e-017i 1 -6.1232e-017i > > X = > 1 +6.1232e-017i 1 -6.1232e-017i > -3.5353e-017 +6.1232e-017i 3.5353e-017 -6.1232e-017i > -1.0606e-016 +6.1232e-017i 1.0606e-016 -6.1232e-017i > 1 -3.0616e-016i 1 +3.0616e-016i > 1.0606e-016 +6.1232e-017i -1.0606e-016 -6.1232e-017i > 3.5353e-017 +6.1232e-017i -3.5353e-017 -6.1232e-017i > > or, after thresholding > > x = > 2 2 > 0 0 > 2 2 > 0 0 > 2 2 > 0 0 > > x0 = 1 1 > > X = > 1 1 > 0 0 > 0 0 > 1 1 > 0 0 > 0 0 > > Hope this helps. > > Greg My example is: >> t=(0:1023)/1024; >> x=1+cos(2*pi*t); >> fx=fft(x)/length(x); >> fx(1:2) ans = 1.0000 0.5000 - 0.0000i So the first and second bins require different scaling. They should both have the same amplitude. I thought it was because the cosine's amplitude is shared between the positive and negative parts of the spectrum (requiring 2/L scaling), whereas the DC's isn't.
From: Greg Heath on 28 Apr 2010 07:06 On Apr 28, 4:43 am, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- Work.com> wrote: > Greg Heath <he...(a)alumni.brown.edu> wrote in message <2f45f49b-2586-4d1b-badf-8b3687382...(a)y12g2000vbr.googlegroups.com>... > > On Apr 27, 12:03 pm, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- > > Work.com> wrote: > > > Greg Heath <he...(a)alumni.brown.edu> wrote in message <0bb0996b-f5fc-455e-8101-b4ff3c765...(a)j15g2000vbq.googlegroups.com>... > > > > On Apr 27, 2:50 am, "Steve Amphlett" <Firstname.Lastn...(a)Where-I- > > > > Work.com> wrote: > > > > > Greg Heath <he...(a)alumni.brown.edu> wrote in message <c17b6883-f695-4934-877c-838b7ff5f...(a)n5g2000yqh.googlegroups.com>... > > ----SNIP > > > > > > > Y = fft(y)/L. > > > > > > > b. The normalizing factor L will yield an amplitude of 1 > > > > > > for exp(i*2*f0*t) at f = f0. > > > > > > ... except at DC and Nyquist, where you need 2/L > > > > > No. > > > > > >> Fs = 1, N = 6, dt = 1/Fs > > > > t = dt*(0:N-1); > > > > x = 1 + cos(2*pi*(Fs/2)*t); > > > > X = fft(x)/N > > > > > Fs = 1 > > > > N = 6 > > > > dt = 1 > > > > > X = 1 0 0 1 0 0 > > > > Is this a recent change? > > > No. > > > Too make things more clear: > > > >> x1 = 1 + exp(i*2*pi*(Fs/2)*t'); > > x2 = 1 + exp(-i*2*pi*(Fs/2)*t'); > > x = [x1 x2] > > x0 = mean(x) > > X = fft(x)/N > > > x = > > 2 2 > > 0 +1.2246e-016i 0 -1.2246e-016i > > 2 -2.4493e-016i 2 +2.4493e-016i > > 0 +3.6739e-016i 0 -3.6739e-016i > > 2 -4.8986e-016i 2 +4.8986e-016i > > 0 +6.1232e-016i 0 -6.1232e-016i > > > x0 = 1 +6.1232e-017i 1 -6.1232e-017i > > > X = > > 1 +6.1232e-017i 1 -6.1232e-017i > > -3.5353e-017 +6.1232e-017i 3.5353e-017 -6.1232e-017i > > -1.0606e-016 +6.1232e-017i 1.0606e-016 -6.1232e-017i > > 1 -3.0616e-016i 1 +3.0616e-016i > > 1.0606e-016 +6.1232e-017i -1.0606e-016 -6.1232e-017i > > 3.5353e-017 +6.1232e-017i -3.5353e-017 -6.1232e-017i > > > or, after thresholding > > > x = > > 2 2 > > 0 0 > > 2 2 > > 0 0 > > 2 2 > > 0 0 > > > x0 = 1 1 > > > X = > > 1 1 > > 0 0 > > 0 0 > > 1 1 > > 0 0 > > 0 0 > > > Hope this helps. > > > Greg > > My example is: > > >> t=(0:1023)/1024; > >> x=1+cos(2*pi*t); > >> fx=fft(x)/length(x); > >> fx(1:2) > > ans = > > 1.0000 0.5000 - 0.0000i > > So the first and second bins require different scaling. They should both have the same amplitude. I thought it was because the cosine's amplitude is shared between the positive and negative parts of the spectrum (requiring 2/L scaling), whereas the DC's > isn't. Sorry, I don't get your point. (I hope you are agreeing with me). Staying with your example (f0 = df = 1): >> Fs = 1024; N = 1024; dt = 1/Fs; t = dt*(0:N-1)'; df = Fs/N; f0 = df; x = 1 + 0.5*exp(i*2*pi*f0*t)+ 0.5*exp(-i*2*pi*f0*t); f = (0:N-1)'; X = fft(x)/N; tab = [1 2 N/2-1 N/2 N/2+1 N-1 N]; [f(tab) X(tab)] ans = 0 1 1 0.5 -6.2224e-017i 510 -2.5434e-018 +9.1992e-019i 511 0 +6.3875e-018i 512 0 1022 1.4135e-017 -1.6012e-018i 1023 0.5 +6.2224e-017i % thresholding: ans = 0 1 1 0.5 510 0 511 0 512 0 1022 0 1023 0.5 Hope this helps. Greg
First
|
Prev
|
Pages: 1 2 Prev: Interaction of MEX and MATLAB or mexCallMATLAB and Co. Next: the distance between two time series |