I have measured a voltage, and I need to include the .txt file in my LTSpice simulation. Before doing that, I first want to filter the noise I ended up measuring (see figure below).
How can I do that using MATLAB?
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.Sign up to join this community
So what you are after is filtering. However, you are in a really good position as you have the complete set of data and do not need to perform "real time" filtering.
"real time" filtering using FIR and IIR are good but introduce errors as they are causal and these errors are typically gain and phase related.
With the complete dataset a range of "offline" post-processing methods are available to you which you would not be able to fully realise in real-time.
filtfilt. This type of filtering filters forward and reverse to mitigate the phase shift that filters typically introduce: https://www.mathworks.com/help/signal/ref/filtfilt.html
Savitzky-Golay Filters An advanced weighted least squares tracking filter which is extremely effective at extracting the underlying characteristics by providing lower significant on transient type effects. https://www.mathworks.com/help/signal/ref/sgolayfilt.html
Kalman filter an acausal type filter using "look ahead" to extract the true underlying trend https://www.mathworks.com/help/control/ug/kalman-filtering.html
perfect Sinc filter A sinc waveform which matches the length of the complete data is a true "brick wall" filter https://www.mathworks.com/matlabcentral/fileexchange/42956-sinc-filter
My personal favorite is the SavGol filter
t= linspace(0,1e-3,10000); y = zeros(10000,1); y(t> 100e-6 & t < 300e-6) = 10; y = y + rand(10000,1); Ysav = sgolayfilt(y, 5, 9); Y1stord = lowpass(y,1000,1/t(2)); figure; plot(t,y); hold; plot(t,Ysav); plot(t,Y1stord) legend('raw data','SavGol filter','1st order LPF');
Basically you want filtering but you do not need to restrict yourself to the classic LPF (FIR,IIRC, R-C type filtering) as you have the complete dataset and thus more opportunities available
These "small oscillations" that you
refer to as noise look suspiciously similar to quantization noise. If this is the case, consider a revision of your data acquisition setup. You may well be able to significantly reduce the amplitude of these "small oscillation" by simply increasing your ADC's resolution (like bit depth), signal amplifier gain or whatever serves to decrease the volt per level parameter. Even if the data acquisition setup is outside your control, knowing the origin of the unwanted distortions that measurement adds to your signal greatly helps in designing the noise suppression procedures like filtering or data fitting.