Prev: ??? Unexpected or internal error encountered in "slOneSimStep". Please report this to The MathWorks if you can cause it to recur.
Next: ODE and external function as input
From: Matt J on 18 Mar 2010 10:29 "Saurabh " <saurabhs(a)student.ethz.ch> wrote in message <hnt7c9$1od$1(a)fred.mathworks.com>... > > 1. you suggested to replace N which was length of signal by Fs but i found in the code above no difference. > Hence i think normalizing by length of signal makes more meaning ============= No, that's only because in this particular example, you had Fs=N. But that only occurs when your sampling period is 1. If instead, you had Fs=100; Ts=1/Fs; t = 0:Ts:2; %sampling period then you would not have obtained the desired scaling with fft(y)/length(t) > 2. Now i can reterive back the signal well It would be instructive if you can point me the difference between DTFT and DFT with some simple example which is implemented in matlab to apreciate the difference ============= As Wayne said, the DTFT is a continuous function of frequency. The DFT is a discrete sampling of the DTFT at frequency intervals 1/N/Ts=Fs/N.
From: Greg Heath on 18 Mar 2010 19:09 On Mar 18, 7:37 am, "Matt J " <mattjacREM...(a)THISieee.spam> wrote: > A few comments about things that could be contributing to the problem: > > > %takes the fft of the signal, and adjusts the amplitude accordingly > > X=fft(x)/N; % normalize the data > > =============== > > This doesn't seem like an appropriate normalization. Its very understandable: It gives the amplitude of 1 at frequency f0 when x = exp(i*2*pi*f0*t) >If you'e trying to approximate the continuous Fourier transform, the > appropriate normalization would be > > X=fft(x)*Fs; %Equation 1 > > Also, if you invert Equation 1, you get > > x=ifft(X)/Fs; %Equation 2 Incorrect. dt = 1/Fs N = length(x) T = N*dt t = dt*(0:N-1); % t = 0:dt:T-dt; and df = Fs/N % Fs = 1/T f = df*(0:N-1); % f =0:df:Fs-df; Then X = dt*fft(x); % Approximate CTFT and x = N*(df*ifft(X)); > > which shows that later, when you take the ifft, you have to undo the > normalization you did in Equation 1 to get the original signal back again. > > > X=fftshift(X); %shifts the fft data so that it is centered > > > Now I want to take IFFT of the function but i do not get back the same > input signal > > > orignal_signal = ifft(YfreqDomain); > > time = ifft(frequencyRange); > > ================= > > I'm baffled as to why you think you can or need to use the IFFT to generate the time axis. You already created a time axis, t, early in the code. Yes, the time and frequency axes are relatively independent of ifft and fft. If you choose ANY sequence y with length N, then Y = fft(y); which can correspond to ANY positive dt OR any positive df provided df*dt = 1/N. Hope this helps. Greg
From: Greg Heath on 18 Mar 2010 20:04
On Mar 18, 7:38 am, "Saurabh " <saura...(a)student.ethz.ch> wrote: > Hi Rune > > Thanks for your reply. > > But i wonder if i take a some function lets say sine just for case to make myself convinced .. > fo = 4; %frequency of the sine wave > Fs = 100; %sampling rate > Ts = 1/Fs; %sampling time interval > t = 0:Ts:1-Ts; %sampling period > n = length(t); %number of samples Be more careful. That approach has gotten people into trouble: In general, there is no guarantee that (1-Ts)/Ts is an integer. I prefer using the notation dt = 1/Fs T = N*dt df = 1/T %( or Fs/N) Then t = dt*(0:N-1); t = 0:dt:T-dt; and f = df*(0:N-1); f= 0:df:Fs-df; > y = 2*sin(2*pi*fo*t); %the sine curve > > and if you do its Fourier transform using fft > > YfreqDomain = fft(y); %take the fft of our sin wave, y(t) > > stem(abs(YfreqDomain)); > > This doesn’t quite look like what we predicted above. That is because you are looking at 0 <= f <= Fs -df. To yield a centered point of view with an understandable scaling, X = fft(x)/N; Xc = fftshift(X); absXc = abs(Xc); fc = f - df*floor(N/2); figure, hold on plot(fc,absXc) plot(fc,absXc,'o') > If you notice, there are a couple of things that are missing. > The x-axis gives us no information on the frequency. You have to provide that with stem(fc,absXc) >How can we tell that the peaks are in the right place? In simple cases loke this one, just read it off the plot. In general, N is large and there can be many peaks with different levels. The function MAX will only find the first of the peaks that have the largest value. To find all isolated peaks you can use find(absXc(i) > max(absXc(i-1),absXc(i+1))) > The amplitude is all the way up to 100 Because you didn't normalize with N > The spectrum is not centered around zero Because you didn't use Xc and fc > All above goes courtesy to a blog by blinkdagger > > Next time search within the newsgroup > > I am stuck in making some sort of same routine for ifft so > that now when I do ifft i could reterive back the starting function ? Since X and Xc are complex but x is real, x = N*real(ifft(X)); or x = N*real(ifft( ifftshift(Xc) )); Hope this helps. Greg |