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!




