From: kk KKsingh on 6 Jul 2010 17:48 When it comes to Fourier transform ! I always compare my codes with other and try to learn from them ; Here is some thing which i didnt get it function X = dtft1(x, omega, n_shift) %function X = dtft1(x, omega, n_shift) % Compute DTFT of 1D signal x at frequency locations wx % In % x [N,ncol] signal values % omega [M,1] frequency locations % n_shift [1,1] use [0:(N-1)]-n_shift indices % Out % X [M,ncol] DTFT values % % This needs enough memory to store M * N size matrices % Copyright 2000-1-9 Jeff Fessler The University of Michigan % % if no arguments, then run a simple test % if nargin < 2 N = 4; x = [[1:N]', [1 1 2 2]']; % two test signal omega = 2*pi*[0:(N-1)]'/N; % test with uniform frequency locations Xd = dtft1(x, omega); Xf = fft(x); % disp([Xd Xf]) help(mfilename) disp(sprintf('max %% difference = %g', max_percent_diff(Xf,Xd))) return end N = size(x,1); if ~isvar('n_shift') | isempty(n_shift), n_shift = 0; end nn = [0:(N-1)] - n_shift; X = exp(-i*omega*nn) * x; % compute 1D DTFT Question Arises : 1. This code works well both for the regular samples and irregular samples 2. what n_shit is doing here is it really needed! when i should use it 3. If i want to test it with non uniform time location isnt nn=(actual sample positons) and omega=2*pi*[(0*(N-1))}*deltak where deltak=1/max(x)-min(x)
From: Greg Heath on 6 Jul 2010 22:26 On Jul 6, 5:48 pm, "kk KKsingh" <akikumar1...(a)gmail.com> wrote: > When it comes to Fourier transform ! I always compare my codes > with other and try to learn from them ; Here is some thing which > i didnt get it > > function X = dtft1(x, omega, n_shift) > %function X = dtft1(x, omega, n_shift) > % Compute DTFT of 1D signal x at frequency locations wx > % In > % x [N,ncol] signal values > % omega [M,1] frequency locations > % n_shift [1,1] use [0:(N-1)]-n_shift indices > % Out > % X [M,ncol] DTFT values > % > % This needs enough memory to store M * N size matrices > % Copyright 2000-1-9 Jeff Fessler The University of Michigan > > % > % if no arguments, then run a simple test > % > if nargin < 2 > N = 4; > x = [[1:N]', [1 1 2 2]']; % two test signal > omega = 2*pi*[0:(N-1)]'/N; % test with uniform frequency locations > Xd = dtft1(x, omega); > Xf = fft(x); > % disp([Xd Xf]) > help(mfilename) > disp(sprintf('max %% difference = %g', max_percent_diff(Xf,Xd))) > return > end The above code is garbage. There are more mistakes than there are lines of code. > N = size(x,1); Doesn't allow row vectors. > if ~isvar('n_shift') | isempty(n_shift), n_shift = 0; end > nn = [0:(N-1)] - n_shift; > > X = exp(-i*omega*nn) * x; % compute 1D DTFT Assumes x is uniformly spaced with Fs = 1 No assurance that the Nyquist criterion is satisfied. > Question Arises : > 1. This code works well both for the regular samples and irregular samples No. See above. > 2. what n_shit is doing here is it really needed! when i should use it If the time reference is -nshift/Fs instead of 0. > 3. If i want to test it with non uniform time location isnt nn=(actual sample positons) and omega=2*pi*[(0*(N-1))}*deltak > where deltak=1/max(x)-min(x) Not applicable to nonuniform time locations Need somethinf like (x.*dts) or (xs.*dt). Hope this helps. Greg
From: kk KKsingh on 6 Jul 2010 23:53 Greg Heath <heath(a)alumni.brown.edu> wrote in message <26b11113-b6d8-4c88-b079-69d889b0c4b9(a)z8g2000yqz.googlegroups.com>... > On Jul 6, 5:48 pm, "kk KKsingh" <akikumar1...(a)gmail.com> wrote: > > When it comes to Fourier transform ! I always compare my codes > > with other and try to learn from them ; Here is some thing which > > i didnt get it > > > > function X = dtft1(x, omega, n_shift) > > %function X = dtft1(x, omega, n_shift) > > % Compute DTFT of 1D signal x at frequency locations wx > > % In > > % x [N,ncol] signal values > > % omega [M,1] frequency locations > > % n_shift [1,1] use [0:(N-1)]-n_shift indices > > % Out > > % X [M,ncol] DTFT values > > % > > % This needs enough memory to store M * N size matrices > > % Copyright 2000-1-9 Jeff Fessler The University of Michigan > > > > % > > % if no arguments, then run a simple test > > % > > if nargin < 2 > > N = 4; > > x = [[1:N]', [1 1 2 2]']; % two test signal > > omega = 2*pi*[0:(N-1)]'/N; % test with uniform frequency locations > > Xd = dtft1(x, omega); > > Xf = fft(x); > > % disp([Xd Xf]) > > help(mfilename) > > disp(sprintf('max %% difference = %g', max_percent_diff(Xf,Xd))) > > return > > end > > The above code is garbage. There are more mistakes > than there are lines of code. > > > N = size(x,1); > > Doesn't allow row vectors. > > > if ~isvar('n_shift') | isempty(n_shift), n_shift = 0; end > > nn = [0:(N-1)] - n_shift; > > > > X = exp(-i*omega*nn) * x; % compute 1D DTFT > > Assumes x is uniformly spaced with Fs = 1 > No assurance that the Nyquist criterion is satisfied. > > > Question Arises : > > 1. This code works well both for the regular samples and irregular samples > > No. > See above. > > > 2. what n_shit is doing here is it really needed! when i should use it > > If the time reference is -nshift/Fs instead of 0. > > > 3. If i want to test it with non uniform time location isnt nn=(actual sample positons) and omega=2*pi*[(0*(N-1))}*deltak > > where deltak=1/max(x)-min(x) > > Not applicable to nonuniform time locations > Need somethinf like (x.*dts) or (xs.*dt). > > Hope this helps. > > Greg Thanks for the reply Greg ! About dts, in some papers when author say about non uniform sampling, every one has different way of handling it like in your codes you used diff(t)..some people use different weighting scheme over there to compensate the effect of irregular sampling. Also people even dont use dts at some places , when data is highly irregular they just use the sampling positions dont use dts...like people in the link below http://www-user.tu-chemnitz.de/~potts/nfft/guide/html/node4.html Though i have checked using dts gives better results Thanks Kumar
|
Pages: 1 Prev: Multiplying very large very sparse square symmetric matrix with column Next: Reassign values |