Plotting DFT, figure not corresponding
3 views (last 30 days)
Show older comments
I am plotting the real and imaginary parts of the base functions of DFT.
N = 40;
for k = (0:3)
x = exp(-j*2*pi*(k/N)*[0:N-1])
end
figure
plot (real(x), 'b')
xlabel('Sample number')
ylabel('Amplitude')
hold on;
plot (imag(x), 'r')
hold on;
legend('Real','Imaginary')
No issues there, but when it comes to the plot figure, I get:

At k = 0, shouldn't my cosine wave amplitudes be 1 and sine A at 0? Why the gap on the plot? I think the issue is that im multiplying by zero here: [0:N-1], but how do I go about fixing it in a most convinient way?
Edit: Got fixed, proper way is to define the x axis, like: plot ((0:N-1),real(x), 'b')
0 Comments
Answers (1)
KALYAN ACHARJYA
on 19 Feb 2021
Edited: KALYAN ACHARJYA
on 19 Feb 2021
"Ak k = 0, shouldnt my cosine wave amplitudes be 1 and sine A - 0? "
The shown graph for k=3 only
Because you are not storing x values for all iterations. So this results from the last k value which is 3. Use figure and plots functions within the loop to see three results windows for k=1 to 3.
0 Comments
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!