How to remove the AWGN noise from data?
Show older comments
Let's say we have a vector data Uo=[20 30 40 50];
If we add AWGN noise to it, it becomes data U i.e.,
U=awgn(Uo,30);
Now we see that U and Uo are different. We want to get back our original data Uo. I tried as:
Uo=U-awgn(30);
But it gives error as:
Error using awgn (line 63)
Not enough input arguments.
What commands should I use to get back my vector Uo?
Answers (2)
Uo=[20 30 40 50]; % signal
U=awgn(Uo,30) % add noise to signal
% Uo=U-awgn(30);
% if you don't know the noise (which is U-Uo), you are not able to fully
% recover the signal.
% However, it is possible to "filter" out noise if signal and noise are
% different in certain characteristics.
% For your case, signal is a low-pass signal and lowpass filter can help to
% remove some noise.
Uo = [20:1:100]/30;
U = awgn(Uo, 10);
b = fir1(20, 0.02); % low pass filter
Ufiltered = filtfilt(b, 1, U);
t = 0:length(Uo)-1;
plot(t, Uo, 'r', t, U, 'b', t, Ufiltered, 'k')
legend("Signal", "Signal+noise", "Filtered")
2 Comments
Sadiq Akbar
on 30 Sep 2022
Chunru
on 30 Sep 2022
The plot is for u to see how good the filtered result as an approximation. You can always comment it out when you are satisfied the results.
For filter to work. You need sufficient data. If you have only 4 points, you may not be able to do much with the added noise.
Star Strider
on 30 Sep 2022
0 votes
I would simply use a moving average filter, for example movmean, or choose one of the options in smoothdata, to eliminate normally-distributed additive noise.
15 Comments
Chunru
on 30 Sep 2022
Perhaps that is a demonstration of the differences between data processing and signal processing :-)
Star Strider
on 30 Sep 2022
I’m just suggesting a more straightforward approach. I frequently use (and recommend) smoothdata — particularly the 'sgolay' option — to eliminate broadband noise.
Chunru
on 30 Sep 2022
I am a signal processing person and tend to think of filtering though I am also aware the smoothdata,movmean. Indeed, movmean is more STRAIGHTFORWARD approach (which is essentially a filter with uniform weight).
Star Strider
on 30 Sep 2022
I have a reasonable background in signal processing. I generally favour the sgolayfilt function for broadband noise problems, and wavelets are also appropriate.
Sadiq Akbar
on 30 Sep 2022
Star Strider
on 30 Sep 2022
See: How to implement a matched filter for one approach. (That example use the filter function, although filtfilt could likely provide a better result, so try both and see what works best for you.)
Sadiq Akbar
on 30 Sep 2022
Getting your original vector may not be possible. It may be necessary to accept the result being ‘close enough’.
% clear all
% clc
% A template is given
temp = [20 30 40 50]';
% Create a matched filter based on the template
b = flipud(temp(:));%My comment:Just reverse the vector temp up side down
% For testing the matched filter, create a random signal which
% contains a match for the template at some time index
x = [randn(200,1); temp(:); randn(300,1)];
n = 1:length(x);
% Process the signal with the matched filter
y = filter(b,1,x);
% Set a detection threshold (exmaple used is 90% of template)
thresh = 0.9
% Compute normalizing factor
u = temp.'*temp;
% Find matches
matches = n(y>thresh*u);
% Plot the results
plot(n,y,'b', n(matches), y(matches), 'ro')
grid
% Print the results to the console
display(matches);
Check = y(y>500)
Also, the filter may need to be ‘normalised’, for example:
y = filter(b,sum(b),x);
I will let you experiment further with this.
.
Sadiq Akbar
on 30 Sep 2022
My pleasure!
Yopu are filtering a signal padded on both ends by normally-distributed random numbers. It is unlikely that you will be able to recover your exact signal from it. (I changed the filter call to experiment with a normalised version. Change it back if you want to.)
% clear all
% clc
% A template is given
temp = [20 30 40 50]';
% Create a matched filter based on the template
b = flipud(temp(:));%My comment:Just reverse the vector temp up side down
% For testing the matched filter, create a random signal which
% contains a match for the template at some time index
x = [randn(200,1); temp(:); randn(300,1)];
n = 1:length(x);
% Process the signal with the matched filter
y = filter(b,sum(b),x); % Changed
% Set a detection threshold (exmaple used is 90% of template)
thresh = 0.9
% Compute normalizing factor
u = temp.'*temp;
% Find matches
matches = n(y>thresh*u);
% Plot the results
plot(n,y,'b', n(matches), y(matches), 'ro')
grid
% Print the results to the console
display(matches);
Check = y(y>mean(y(1:100))+10*std(y(1:100))) % Recover Peak Data
.
Sadiq Akbar
on 1 Oct 2022
Star Strider
on 1 Oct 2022
The code I quoted is not mine. I just referred you to it, so it is not obvious to me what choices the original author made, or why.
‘5-What does this command do? y = filter(b,sum(b),x);’
That normalises the filter, so that ideally it does not amplify the signal being filtered.
Sadiq Akbar
on 3 Oct 2022
Star Strider
on 3 Oct 2022
My pleasure!
It is likely not possible to completely recover a signal that has had Gaussian white noise added to it.
Experiment with the sgolayfilt function and wdenoise (wavelet denoising) function. Those are likely the best options.
Sadiq Akbar
on 4 Oct 2022
Categories
Find more on Smoothing and Denoising in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

