2
\$\begingroup\$

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).

enter image description here

How can I do that using MATLAB?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ what do you mean by "delete the noise" ? If you mean "filtering" using a low pass filter then the noise will only be attenuated, not completely deleted. Search for FIR filtering with MATLAB on google or Stackoverflow. If you really expect to have an ultra clean pulse with no noise at all, then it may be much easier to just redraw the curve "by hand" given its simplicity. \$\endgroup\$
    – Blup1980
    Dec 2 '21 at 9:41
  • \$\begingroup\$ @Blup1980 as you can see in the figure, I have small oscillations that I refer to ass noise. I will check the FIR filtering, thank you :). This figure is simple, indeed. However, I have other voltage measurements that oscillate way more and in which you can see the spurious oscillations (which I call noise). \$\endgroup\$
    – Wallflower
    Dec 2 '21 at 9:55
5
\$\begingroup\$

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.

  1. 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

  2. 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

  3. 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

  4. 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

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Very good. As an EE I obviously immediately jump to a causal system that is LTI, forgetting the advantages of having access to the "future" samples and the use of a non causal approach that is much more suited here. bad habits.... \$\endgroup\$
    – Blup1980
    Dec 2 '21 at 13:49
  • \$\begingroup\$ Thank you for your response, it helped a lot. I have one other question though, I tried to automatically (using MATLAB) compute the rise and fall times of the following signal. However, whenever I use the predefined MATLAB functions I get a values of 19 and 23, respectively. Knowing that, my time scale is in milliseconds... \$\endgroup\$
    – Wallflower
    Dec 7 '21 at 10:35
3
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.