% Parameters
Fs = 1000;               % Sampling frequency in Hz (adjust as needed)
N = 1024;                % Number of DFT points (preferably a power of 2)
t = (0:N-1)/Fs;          % Time vector

% Example signal (you can replace this with your own)
x = cos(2*pi*150*t) + 0.5*cos(2*pi*300*t);  % A signal with components at 150 Hz and 300 Hz

% Compute DFT
X = fft(x, N);
magX = abs(X) / N;       % Normalize magnitude

% Frequency axis (in Hz)
f = Fs * (0:N/2)/N;      % Up to Nyquist frequency

% Plot
figure;
stem(f, magX(1:N/2+1), 'filled');
xlabel('Frequency (Hz)');
ylabel('|DFT[x[n]]|');
title('Magnitude Spectrum');
grid on;
