Prev: Recent File List/MatLAB GUI
Next: Surf plot with NaN
From: Martijn Roelofsz on 13 Jul 2010 02:48 Greg, thanks for your reply. When I use your code I still get 4.6922 at 200Hz. I get read that number from the plot after zooming in on the 200Hz spike. It is just hard for me to understand that a 200Hz, 20mV top to top sine does not have a 10mv(or close to) outcome as fft.
From: Martijn Roelofsz on 13 Jul 2010 02:56 "Steve Amphlett" <Firstname.Lastname(a)Where-I-Work.com> wrote in message <i1h1tq$oid$1(a)fred.mathworks.com>... > "Martijn Roelofsz" <martijn.roelofsz(a)nlr.nl> wrote in message <i1f2ok$1cv$1(a)fred.mathworks.com>... > > I am trying to plot an fft of a known sinusoid signal. > > The input signal is a 20mVtt, 200Hz sinus. Duration is 0.2sec. 500kHz samplerate. > > When i calculate the fft I expect a spike at 200Hz with a magnitude of 10(in this case mV). > > > > y = fft(X); > > m = abs(y); > > plot(m); > > > > The fft shows a amplitude of 4.6922 at 200Hz. Why is it not 10(or very close to 10) and how can I scale it back to mV again? > > Putting leakage to one side, you are mainly not using the number of points to scale your transform. > > N=length(X); > m=abs(y)*2/N; > > (Note that the DC and Nyquist frequencies should only be scaled by 1/N, but that detail isn't hugely important here.) With this code: Fs = 5e5; tmax = 0.2; dt = 1/Fs; % 2e-6 % t = 0:dt:T-dt; % t = dt*(0:N-1); T = tmax+dt; % 0.200002 N = T/dt; % 100001 y = fft(X); %/N; % will give the correct spectrum scale m = abs(y); m=abs(y)*2/N; plot(m); The outcome is 9.3843, if i devide "fft(X)" with N (y = fft(X)/N;) i get the same but than times e-5. The outcome 9.3843 looks reasonable to me. Can the missing 0.68mV be the leakage?
From: Wayne King on 13 Jul 2010 02:59 "Martijn Roelofsz" <martijn.roelofsz(a)nlr.nl> wrote in message <i1h0tt$oal$1(a)fred.mathworks.com>... > Greg Heath <heath(a)alumni.brown.edu> wrote in message <0f2e8b34-9dc2-44b9-9e16-dcc474e036af(a)i1g2000vbk.googlegroups.com>... > > On Jul 12, 8:45 am, "Martijn Roelofsz" <martijn.roelo...(a)nlr.nl> > > wrote: > > > I am trying to plot an fft of a known sinusoid signal. > > > The input signal is a 20mVtt, > > > > What does "tt" mean? > > > > >200Hz sinus. Duration is 0.2sec. 500kHz samplerate. > > > > Fs = 5e5 > > tmax = 0.2 > > dt = 1/Fs % 2e-6 > > > > % t = 0:dt:T-dt; > > % t = dt*(0:N-1); > > > > T = tmax+dt % 0.200002 > > N = T/dt % 100001 > > > > > When i calculate the fft I expect a spike at 200Hz with a magnitude of 10(in this case mV). > > > > > > y = fft(X); > > > > y = fft(X)/N; % will give the correct spectrum scale > > > > > m = abs(y); > > > plot(m); > > > > > > The fft shows a amplitude of 4.6922 at 200Hz. Why is it not 10(or very close to 10) and how can I scale it back to mV again? > > > > > > It's not clear how you obtained that number. > > > > Hope this helps. > > > > Greg > > Greg > > tt is the top to top voltage. In this case 20mV. Hi Martijn, Assuming that your signal values are in mV and that your single real-valued sinusoid oscillates between -10 and 10 mV, you would expect two complex exponentials in the Fourier transform--each complex exponential will have amplitude 10/2=5. This can be shown as follows: Fs = 5e5 ; t = 0:(1/Fs):0.2-(1/Fs); x = 10*cos(2*pi*200*t); xDFT = fftshift(fft(x)); plot(abs(xDFT)/length(x)) freq = -Fs/2+(Fs/length(x)):Fs/length(x):Fs/2; plot(freq,abs(xDFT)/length(x)) axis([-250 250 0 5]) If you are only interested in representing the positive part of the spectrum: xDFT = fft(x); xDFT = xDFT(1:length(x)/2+1); xDFT(2:end)=2*xDFT(2:end); freq = 0:(Fs/length(x)):Fs/2; plot(freq,abs(xDFT)/length(x)); axis([0 250 0 10]); Hope that helps, Wayne
From: Greg Heath on 13 Jul 2010 09:09 On Jul 13, 2:48 am, "Martijn Roelofsz" <martijn.roelo...(a)nlr.nl> wrote: > Greg, thanks for your reply. When I use your code I still get 4.6922 at 200Hz. I get read that number from the plot after zooming in on the 200Hz spike. > > It is just hard for me to understand that a 200Hz, 20mV top to top sine does not have a 10mv(or close to) outcome as fft. 10*sin(z) = 5*exp(j*z)+5*exp(-j*z) If you had an integral number of periods you would get 5 instead of 4.6922. Lothar: This is the result of "leakage" The other 4.6922 is at frequency -200Hz+Fs. Hope that helps. Greg Greg
From: Wayne King on 13 Jul 2010 09:32
Greg Heath <heath(a)alumni.brown.edu> wrote in message <6db36221-b4c2-4eb8-966d-3935c3a3953f(a)g19g2000yqc.googlegroups.com>... > On Jul 13, 2:48 am, "Martijn Roelofsz" <martijn.roelo...(a)nlr.nl> > wrote: > > Greg, thanks for your reply. When I use your code I still get 4.6922 at 200Hz. I get read that number from the plot after zooming in on the 200Hz spike. > > > > It is just hard for me to understand that a 200Hz, 20mV top to top sine does not have a 10mv(or close to) outcome as fft. > > 10*sin(z) = 5*exp(j*z)+5*exp(-j*z) > > If you had an integral number of periods you > would get 5 instead of 4.6922. > > Lothar: This is the result of "leakage" > > The other 4.6922 is at frequency -200Hz+Fs. > > Hope that helps. > > Greg > > Greg Hi Greg, just a minor typo, I think you meant: 10*cos(z) = 5*exp(j*z)+5*exp(-j*z) Wayne |