fft magnitude and phase (Octave)

n = 0:127;
x = sin(2 * pi * 0.05 * n); 

X = fft(x); 
mag = abs(X); 
phase = angle(X);

figure;
subplot(3, 1, 1);
plot(n, x, 'k', 'LineWidth', 1.5); 
title('Original Signal');
xlabel('Time Index (n)');
ylabel('Amplitude');
grid on;

subplot(3, 1, 2); 
plot(mag, 'r', 'LineWidth', 1.5); 
title('Magnitude Spectrum');
xlabel('Frequency (FFT Index)');
ylabel('|X(f)|');
grid on;

subplot(3, 1, 3);
plot(phase, 'b', 'LineWidth', 1.5);
title('Phase Spectrum');
xlabel('Frequency (FFT Index)');
ylabel('Phase (radians)');
grid on;

Read more here: Source link