To separate noise from harmonics in a signal using FFT in MATLAB, you can use a technique called spectral subtraction.
Here is an example script that demonstrates how to do that:
main.m594 chars24 lines
In this script, we first load the input signal (assuming that it is in WAV format), and define the frequency range of the harmonics that we want to keep (in this case, we keep the harmonics between 1800 and 2000 Hz).
Next, we compute the FFT of the signal and its power spectrum. We also compute the noise spectrum by averaging the power spectrum outside the harmonics range.
Then, we compute the spectral subtraction function by subtracting the noise spectrum from the power spectrum and taking the maximum between the result and zero (to eliminate negative values).
Finally, we compute the enhanced signal by multiplying the input signal's FFT by the square root of the spectral subtraction function divided by the power spectrum, and take the inverse FFT to get the time-domain signal. The enhanced signal is saved in a WAV file.
Note that this is just an example, and you may need to adjust the parameters and apply additional techniques based on your specific requirements and characteristics of the signal.
gistlibby LogSnag