Plotting DFT, figure not corresponding

4 visualizzazioni (ultimi 30 giorni)
Artur Kastro
Artur Kastro il 19 Feb 2021
Modificato: Artur Kastro il 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')

Risposte (1)

KALYAN ACHARJYA
KALYAN ACHARJYA il 19 Feb 2021
Modificato: KALYAN ACHARJYA il 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.

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by