MATLAB Answers

Need help getting my delta functions to work

3 views (last 30 days)
Brianna Miranda
Brianna Miranda on 15 Oct 2021
Commented: Brianna Miranda on 15 Oct 2021
I'm trying to take the Fourier transform of two delta function but I'm having a problem with writing the code for my delta functions. The two functions are x = [1,0,0,0,....,0,0,0]; n=0...nfft-1 and y = x = [0,0,0,1,....,0,0,0]; n=0...nfft-1. The length of my fft (nfft) is 150. So far what I have is
nfft = 150;
x = [1,0,0,0:0:nfft-1];
y = [0,0,0,1,0:0:nfft-1];
but my vectors are x = [1,0,0] and y = [0,0,0,1]. They should be x = [1,0,0,.....0,0,0] and y = [0,0,0,1,0,0.....,0,0,0] from n=0 to nfft-1.

Answers (1)

Paul
Paul on 15 Oct 2021
The problem is that
nfft = 150;
0:0:nfft-1
ans = 1×0 empty double row vector
is empty. What that line is bascially asking for is a vector of number from 0 to 149 in increments of 0, which doesn't make sense, hench the empty result. If I understand the question correclty, you really want this
x = zeros(1,nfft);
x(1) = 1;
y = zeros(1,nfft);
y(4) = 1;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!