MATLAB Code % MATLAB script to compare different Spectral Estimation Methods using Built-in Functions % Sample signal: Sine wave with noise fs = 1000; % Sampling frequency (Hz) T = 1; % Signal duration (seconds) t = 0:1/fs:T-1/fs; % Time vector f_signal = 50; % Signal frequency (Hz) signal = sin(2*pi*f_signal*t) + 0.5*randn(size(t)); % Sine wave + noise % Method 1: Periodogram (Using built-in function) [pxx_periodogram, f_periodogram] = periodogram(signal, [], [], fs); % Method 2: Bartlett Method (Using built-in pwelch with default settings) [pxx_bartlett, f_bartlett] = pwelch(signal, [], [], [], fs); % Method 3: Welch Method (Using built-in pwelch with segment overlap) segmentLength = 256; % Length of each segment overlap = 128; % Overlap between segments [pxx_welch, f_welch] = pwelch(signal, segmentLength, overlap, [], fs); % Method 4: Blackman-Tukey Method (Using built-in cpsd function with autocorrelation) % Compute the Cross Power Spectral Density (CPSD) using autocorrelatio...