Plot signal of DFT without using FFT function
조회 수: 8 (최근 30일)
이전 댓글 표시
I looked at so many blogs until I came here and still can't figure it out.
I have a signal given as:
The DFT of that signal is:
The analytical solution for fk is:

Where fk = 100 when k = 67 and 0 otherwise.
Here's what I have:
clc;clear;
N = 715;
k = 0:N-1;
n = k;
fj_func = @(N,n) (100*exp(2i.*pi.*67/N.*k)).*(n>=0 & n<=N-1);
fj = fj_func(N,n);
fk_func = @(N,k) (1/N).*fj.*(exp(-2i.*pi.*k.*n./N)).*(k>=0 & k<=N-1);
fk = fk_func(N,k);
stem(k,abs(fk)/N)
When I use the analytical solution above, I get:
clc;clear;
N = 715;
k = 0:N-1;
n = k;
fk_func = @(k) (100/N).*((1-exp(2i.*pi.*n.*(67-k)))./(1-exp(2i.*pi.*n.*(67-k)./N)));
fk = fk_func(k);
stem(k,abs(fk)/N)
I used the fft function for fj, and it works. My value is at
clc;clear;
N = 715;
k = 0:N-1;
n = k;
fj_func = @(N,k) (100*exp(2i.*pi.*67/N.*k)).*(k>=0 & k<=N-1);
fj = fj_func(N,k);
ft = fft(fj);
stem(k,abs(ft)/N)
I'm not sure what I'm doing wrong. Any ideas would be greatly appreciated. Thanks
댓글 수: 0
채택된 답변
Paul
2021년 11월 4일
편집: Paul
2021년 11월 4일
The first approach to compute DFT directly using the definition can't be correct because there is no summation over n. Try it this way. First off there really isn't a need to define a function to compute fn.
N = 715;
n = 0:(N-1);
fn = 100*exp(2i*pi*67*n/N);
Now define a function to compute the DFT for a given value of k
dftfn = @(k,fn,n,N) (sum(fn .* exp(-1i*2*pi*k*n/N))/N);
Now test for a couple of values of k
dftfn(5,fn,n,N)
dftfn(67,fn,n,N)
The next step would be to write a loop to evaluate dftfn at the values of k of interest.
Note: there are other alternatives, but I think this is the clearest.
For the second approach, I don't think the closed form expression is correct. There shoudn't be an n in any term.
fk_func = @(k,N) (100/N).*((1-exp(2i.*pi.*(67-k)))./(1-exp(2i.*pi.*(67-k)./N)));
k = 0:(N-1);
fk = fk_func(k,N);
stem(k,abs(fk)) % no need to divide by N, that's already in fk_func
As expected all the reults are tiny, but what happened at k = 67?
stem(k,abs(fk));
xlim([60 70])
We see that there is a gap, because the formula at k = 67 yields NaN because it evaluates to 0/0.
fk_func(67,N)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




