# How to filter data to remove noise in MATLAB?

I have 2 arrays of 800000 input and output data samples. The system is a kind of oven that works from 0 to 10 volts. The sample time is 0.001s.

I have to identify the model of this system, but first of all, given that the data are clearly dirty, I would like to filter the noise.

• How can I do it with the System Identification Toolbox of MATLAB?

• Moreover, how can I estimate the cutoff frequency to remove the noise?

EDIT:

As suggested, here below are the sampled data plot. As you can see the voltage inputs looks good, but the temperature outputs are affect of noise. I would like to remove it, in order have the output more "smooth". • did you even bother googling it ? have a look at one Matlab System Identification Example ccrma.stanford.edu/~jos/fp/… – Sufiyan Ghori Mar 22 '13 at 10:47
• Yes I did. I've seen the filter option under preprocess menu but, as I stated, I don't know which value to put as cutoff frequency. Even because, I cannot use the Nyquist theorem, given that I have too many samples and obviously the sampling time should be lower than 0.001 seconds for such system. – Daniele Vitali Mar 22 '13 at 10:57
• It would probably help if you posted a plot of your data and describe what you expect to see in the data. – Jim Clay Mar 22 '13 at 13:01
• @JimClay here they are :) – Daniele Vitali Mar 22 '13 at 14:08
• you should start playing with 1-D wavelet toolbox i guess. – Sufiyan Ghori Mar 22 '13 at 15:03

There are two sources of errors that cause the temperature reading to look different than the voltage reading: sensor error and temperature error. You want to get rid of the sensor error and keep the temperature error. I would surmise that the high-frequency spikes are sensor error, and everything else is temperature error.

I would do it like this- plot the power of the voltage input in the frequency domain (e.g. plot(20*log10(abs(fft(voltInput)))) in MATLAB). It will have power across the entire frequency spectrum, but should be concentrated primarily in the lower frequencies. Figure out a cutoff point that will preserve most of your "signal" (voltage input) but should also get rid of most of your noise. I'm guessing that the oven acts like a low-pass filter (takes time for it to change temperature), so this shouldn't affect the true temperature reading much. You could verify this by doing a similar plot of the temperature reading. I bet the high-frequency signal content is quite attenuated. Setting your cutoff point to somewhere in that attenuated region would be a good choice.

You can also adjust your cutoff frequency and empirically see how that affects the results.

• Thank you for your replay. I have plotted the input as you suggested. The input spectrum has dominant values in low and high frequencies, and the output as well (with some differences in the middle). However cutting at 0.5Hz the output is improved but not the input (there are elongations on the initial and filan step). I don't understand why filter also the input. The voltage inputs looks clear without noise, aren't they? And do you think that I should downsample the data before start the identification process given that 800000 samples with 0.001 sample time are too many? Thank you :) – Daniele Vitali Mar 22 '13 at 16:45
• You don't need to filter the input. The point of looking at the input was just to figure out what a good cutoff frequency would be. Yes, downsampling wouldn't be a bad idea. In fact, if you downsample to a reasonable sample rate using Matlab's "decimate" command, that would probably take care of the noise problem for you. – Jim Clay Mar 22 '13 at 17:23
• I think that the "high values" that you are talking about are the low negative frequencies, not the high frequencies. The "middle values" would then be the high frequencies. Do "plot(20*log10(fftshift(abs(fft(voltInput)))))" to have the low frequencies in the middle, and the high frequencies on the far right and far left. – Jim Clay Mar 22 '13 at 19:52
• Ok the new plot shows as you said now. I was wondering does periodogram function plot the same graph as yours? And one more question.. Is there a way to set the downsampling factor for the decimate function that avoid aliasing effect on the data? Thank you for your time :) – Daniele Vitali Mar 23 '13 at 10:30
• I've never used the periodogram function, but according to its description it sounds like it is the same thing. The decimate function automatically applies an anti-aliasing filter so you shouldn't need to worry about that. If you are going to downsample by a large factor (e.g. 500) it's usually a good idea to break it up into multiple smaller decimates (e.g. 10, 10, 5) whose product is the downsample factor you want. – Jim Clay Mar 23 '13 at 15:25

You can try to remove noise (especially occasional spikes) by non-linear filter. I suggest to use median filter (http://en.wikipedia.org/wiki/Median_filter), as your spikes has length only few points (as I see). There is matlab function - medfilt1. It is probably that such filtration will be enough.