# Frequency Estimation by Subspace Methods

This example shows how to resolve closely spaced sine waves using subspace methods. Subspace methods assume a harmonic model consisting of a sum of sine waves, possibly complex, in additive noise. In a complex-valued harmonic model, the noise is also complex-valued.

Create a complex-valued signal 24 samples in length. The signal consists of two complex exponentials (sine waves) with frequencies of 0.50 Hz and 0.52 Hz and additive complex white Gaussian noise. The noise has zero mean and variance $0.{2}^{2}$. In a complex white noise, both the real and imaginary parts have variance equal to 1/2 the overall variance.

```n = 0:23; rng default x = exp(1j*2*pi*0.5*n)+exp(1j*2*pi*0.52*n)+ ... 0.2/sqrt(2)*(randn(size(n))+1j*randn(size(n)));```

Using `periodogram`, attempt to resolve the two sine waves.

`periodogram(x,rectwin(length(x)),128,1)`

The periodogram shows a broad peak near 1/2 Hz. You cannot resolve the two separate sine waves because the frequency resolution of the periodogram is 1/_N_, where N is the length of the signal. In this case, 1/_N_ is greater than the separation of the two sine waves. Zero padding does not help to resolve two separate peaks.

Use a subspace method to resolve the two closely spaced peaks. In this example, use the root-MUSIC method. Estimate the autocorrelation matrix and input the autocorrelation matrix into `pmusic`. Specify a model with two sinusoidal components. Plot the result.

```[X,R] = corrmtx(x,14,'mod'); [S,F] = pmusic(R,2,[],1,'corr'); plot(F,S,'linewidth',2) xlim([0.46 0.60]) xlabel('Hz') ylabel('Pseudospectrum')```

The root-MUSIC method is able to separate the two peaks at 0.5 and 0.52 Hz. However, subspace methods do not produce power estimates like power spectral density estimates. Subspace methods are most useful for frequency identification and can be sensitive to model-order misspecification.