From: kk KKsingh on



So I followed the same steps what i am doing wrong below according to you !


N=200; % Number sample points
M=(N-1)/2; %Number of frequency points
m=-M:M
fo = 4; %frequency of the sine wave
Fs = 50; %sampling rate
Ts = 1/Fs; %sampling time interval
t = 0:Ts:Ts*(N-1); %sampling period
y = 2*sin(2*pi*fo*t);
deltaf=2*pi/(N*Ts);%Defining the grid size of Fourier domain
for k=1:length(m)
freq = (-j*2*pi*(k-1))/(N*Ts);
Wnk = exp(freq.*(0:length(t)-1));
X(k)=Ts*sum(y.*Wnk);
end


if mod(N,2)==0
k=-N/2:N/2-1; % N even
else
k=-(N-1)/2:(N-1)/2; % N odd
end

f=1/Ts/N*k;


Y = fft(y);
subplot(211);
stem(f,fftshift(abs(X))); title('DFT');
subplot(212);
stem(f,fftshift(abs(Y))); title('MATLAB FFT');


















Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <00cea41d-4df4-4913-b747-7ee1df663171(a)c16g2000yqd.googlegroups.com>...
> On 20 Feb, 08:57, "kk KKsingh" <akikumar1...(a)gmail.com> wrote:
> > I want to write my own code for DFT for regular sampling signall
> ...
> > I am doing some thing terribly wrong here ! I am confuse ...kindly help in writing code for DFT ...Assuming X as time and K as frequency in above expression......
>
> The error you make is that you think that a particular application
> of the DFT requires a totally new implementation. It doesn't.
>
> Use the standard (2D) DFT routines. Just add the book-keeping of the
> frequency and wavenumber domains, which happen to be a couple of
> vectors that have nothing to do with what goes on nside the (2D) DFT.
>
> Rune
From: Rune Allnor on
On 20 Feb, 23:23, "kk KKsingh" <akikumar1...(a)gmail.com> wrote:
> So I followed the same steps what i am doing wrong below according to you !

Everything. You haven't understood the basics of the maths
involved, nor the essentials of the DFT. These things are
trivial; it's just a matter of book-keeping.

Start out with a simple example in 1D, and extrapolate
from there.

Rune
From: kk KKsingh on






Well i know how to write DFT code!

N=200; % Number sample points
M=(N-1)/2; %Number of frequency points
m=-M:M
fo = 4; %frequency of the sine wave
Fs = 50; %sampling rate
Ts = 1/Fs; %sampling time interval
t = 0:Ts:Ts*(N-1); %sampling period
y = 2*sin(2*pi*fo*t);
deltaf=2*pi/(N*Ts);%Defining the grid size of Fourier domain
for k=1:length(m)
freq = (-j*(2*pi/(N))*(k-1));
Wnk = exp(freq.*(0:length(t)-1));
X(k)=Ts*sum(y.*Wnk);
end


if mod(N,2)==0
k=-N/2:N/2-1; % N even
else
k=-(N-1)/2:(N-1)/2; % N odd
end

f=1/Ts/N*k;


Y = fft(y);
subplot(211);
stem(f,fftshift(abs(X))); title('DFT');
subplot(212);
stem(f,fftshift(abs(Y))); title('MATLAB FFT');




But thing is I wrote a same thing frm another book i which they define the size of grid in Fourier domain



deltaf=2*pi/(N*Ts);%Defining the grid size of Fourier domain

I am simple asking why i am getting wrong result when i use deltaf in this

for k=1:length(m)
freq = (-j*(deltaf)*(k-1));
Wnk = exp(freq.*(0:length(t)-1));
X(k)=Ts*sum(y.*Wnk);
end

I am confused by a expression guy used in his paper...in which he use deltaf as above








Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <c0e98861-ddd6-407b-bed6-4ae0a964fa97(a)g28g2000yqh.googlegroups.com>...
> On 20 Feb, 23:23, "kk KKsingh" <akikumar1...(a)gmail.com> wrote:
> > So I followed the same steps what i am doing wrong below according to you !
>
> Everything. You haven't understood the basics of the maths
> involved, nor the essentials of the DFT. These things are
> trivial; it's just a matter of book-keeping.
>
> Start out with a simple example in 1D, and extrapolate
> from there.
>
> Rune
From: kk KKsingh on
Thanks i got my mistake ! I was not cancelling some variables from numerater and denominater

Apprciate your patience in explaining me this

kk



Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <c0e98861-ddd6-407b-bed6-4ae0a964fa97(a)g28g2000yqh.googlegroups.com>...
> On 20 Feb, 23:23, "kk KKsingh" <akikumar1...(a)gmail.com> wrote:
> > So I followed the same steps what i am doing wrong below according to you !
>
> Everything. You haven't understood the basics of the maths
> involved, nor the essentials of the DFT. These things are
> trivial; it's just a matter of book-keeping.
>
> Start out with a simple example in 1D, and extrapolate
> from there.
>
> Rune