Plotting DFT, figure not corresponding

3 views (last 30 days)
Artur Kastro
Artur Kastro on 19 Feb 2021
Edited: Artur Kastro on 19 Feb 2021
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')

Answers (1)

KALYAN ACHARJYA
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.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!