Question

Using the MATLAB M-file dft, compute the 32-point DFT of rn cos(₩), 0 〈 n < 10, x[n] 0 for all other n. COS

M-file

dft.m

function Xk = dft(x)
[N,M] = size(x);
if M ~=1, % makes sure that x is a column vector
x = x';
N = M;
end
Xk=zeros(N,1);
n = 0:N-1;
for k=0:N-1
Xk(k+1) = exp(-j*2*pi*k*n/N)*x;
end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function Xk = dft(x,N)
M=length(x);
if M>N
disp('N must be >=M')
end
xnew=[x (zeros(1,N-M))]
for k=0:1:N-1  
for n=0:1:N-1
xk(k+1,n+1)=exp(-j*2*pi*k*n/N);
end
end
Xk=xk*xnew'

Program:


N=32
n=0:1:10
xn=cos(10*n*pi/11)
Xk=dft(xn,N)
%__________________________________
%plots
k=0:1:N-1;
subplot(311)
stem(n,xn,'k')
title('Sequence in time domain x(n)')
xlabel('n')
ylabel('x(n)')
subplot(312)
stem(k,abs(Xk),'r')
title('DFT of x(n)-Magnitude response')
xlabel('k')
ylabel('|X(k)|')
subplot(313)
stem(k,angle(Xk),'m')
title('DFT of x(n)-Phase response')
xlabel('k')
ylabel('<X(k)')

Sequence in time domain x(n) 0.5 2 4 DFT of x(n)-Magnitude response 2 0 1 0 20 25 30 35 DFT of x(n)-Phase response -3 10 20 25 30 35

Add a comment
Know the answer?
Add Answer to:
M-file dft.m function Xk = dft(x) [N,M] = size(x); if M ~=1, % makes sure that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT