0
votes

Currently in a digital signal processing class, but need help reproducing the results of this code without using symbolic math in Matlab but rather using nested for loops to generate the values of X as a function of omega.

Symbolic Solution

This is what I have so far, using various matlab ideas for DTFT:

N=8;
figure
upper = pi;
lower = -pi;
bw = 1000;

omega = linspace(-pi,pi,1000);

for k=0:bw
    for n=0:N-1
         Y = X(k+1) + x(n+1)*exp(-j*2*pi*n*k/N) ;
    end
end
1
Please describe the problem you need help with. What result do you see, what is the result you would expect? Any idea why these two sets of results might differ? - Mouse On Mars

1 Answers

0
votes

The key is to focus on this part of the symbolic expression

%X is the sum of all 8 functions 0 to 7
X = f2(1) + f2(2) + f2(3) + f2(4) + f2(5) + f2(6) + f2(7) + f2(8)

And try to write your own code from that.


clear; clc;
figure

upper = pi
lower = -pi
bw = 1000

%w is in 1x1000
w =linspace(lower, upper, bw)

N=8

X=zeros(1, 1000)

for k=0:N

    f2=exp(-j*w*k);

    X = X + f2;

end

f4=X

subplot(2,1,1)

plot(linspace(lower, upper, bw), abs(f4), 'b');

Since I know that the we're looking for the sum of all 8 functions for n=1:8, I can achieve that in one line of code, as here

X = X + f2;

where here, the functions are contained in the vector f2,

f2=exp(-j*w*k);

This gets you the same result as the subplot for the reference code.