Hi Karoline,
You need to ensure that nature of the signal and the properties of the “FFT” aligns with the compressed signals. The signals you provided is a sum of several cosine waves with different frequencies.
- If these frequencies do not align precisely with the “FFT” bins, the signal won't be sparse in the “FFT” domain. This misalignment causes the energy to spread across multiple “FFT” bins, reducing sparsity.
- For the “FFT” to work well, the frequencies should ideally match the discrete frequencies that the “FFT” can resolve given the signal length.
Compressed sensing relies on the assumption that the signal is sparse in some transform domain. If the signal is not sparse in the “FFT” domain, it is highly recommended to use transform method that better represents the signal's sparsity, such as the “DCT”. That is why it is easier to find the optimal value using the “DCT” rather than the “FFT”. It often leads to an infeasible state like infinity when using “FFT” for compressed sparse signals.
I have revised the code for finding optimal value in compressed signal using “FFT”. You need to ensure following points to avoid reaching the infeasible state:
- Use "SeDumi" solver as it optimized for sparse signal.
- Normalization: Ensure that the signal normalization step does not lead to division by zero or very small values.
- NaN and Inf Checks: The code checks for NaN or Inf values in the input data to prevent them from causing optimization failures.
Kindly, refer to the revised code:
t = linspace(0, 4000, n);
x = 0.5 * cos(2 * 0.008 * pi * t) + 0.5 * cos(2 * 0.016 * pi * t) + ...
0.5 * cos(2 * 0.064 * pi * t) + 0.5 * cos(2 * 0.256 * pi * t);
PSD = abs(real(xt)).^2 / ((n-1) * 1);
error('Normalization factor is zero, leading to division by zero.');
if any(isnan(Theta(:))) || any(isinf(Theta(:))) || any(isnan(y)) || any(isinf(y))
error('Inputs contain NaN or Inf values.');
norm(Theta * s - y') <= 0.01;
For more information on “FFT”, refer to the MATLAB documentation,