How to remove noise of low frequency signals

26 views (last 30 days)
Hello,
I have to create a model of following signal in such a way a way that red signal will not fluctuate with the green signal and will always take mean of green signal. I have used moving average filter, but still there is some fluctuation, I cannot increase N of moving average filter, since it will make it less responsive. Could you suggest me such a way where I could make red signals more or less like straight tine. is there any filter or algorithm available for this.
Note - this signal manipulation should be done in realtime, model is created in Simulink

Accepted Answer

Star Strider
Star Strider on 5 Jun 2024
Calculate the fft of the green signal (if you do not already know its spectral qualities), then use it to define the cutoff frequency of a lowpass filter.
Example —
Fs = 1E+3;
L = 5;
t = linspace(0, Fs*L, Fs*L+1)/Fs;
s1 = sin(2*pi*t*2.5);
s2 = sin(2*pi*t*0.25);
green = s1+s2;
figure
plot(t, green, '-g')
set(gca, 'Color','k')
[p,f] = pspectrum(green, Fs);
figure
plot(f, p)
xlim([0 5])
xlabel('Frequency')
ylabel('Power')
xline(0.4, '--k', 'F_{co}')
red = lowpass(green, 0.4, Fs, 'ImpulseResponse','iir');
figure
plot(t, green, '-g')
hold on
plot(t, red, '-r')
hold off
set(gca, 'Color','k')
Make appropriate changes to work with your signal.
.
  2 Comments
Avdhut Machchhindra
Avdhut Machchhindra on 9 Jun 2024
Moved: Star Strider on 9 Jun 2024
Thank you so much for your answer. I would also like to measure the frequency of the signal I have posted earlier. So based on that I could build my logic. Fluctuations are at different values like 50, sometime 80,40, 30. Is there any block available in simulink for this, or MATLAB code.
Thank you in advance.
Avdhut
Star Strider
Star Strider on 9 Jun 2024
As always, my pleasure!
The best I can do in that respect is to add my one-sided Fourier transform funciton ‘FFT1’: that I wrote because I calculate Fourier transforms relatively frequently, and got tired of always typing essentially the same code to calculate them:
function [FTs1,Fv] = FFT1(s,t)
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
FTs1 = FTs(Iv,:);
end
Using it (inistead of pspectrum) with my previous code —
Fs = 1E+3;
L = 5;
t = linspace(0, Fs*L, Fs*L+1)/Fs;
s1 = sin(2*pi*t*2.5);
s2 = sin(2*pi*t*0.25);
green = s1+s2;
figure
plot(t, green, '-g')
set(gca, 'Color','k')
[FTs1,Fv] = FFT1(green,t);
[pks,frqs,wdths] = findpeaks(abs(FTs1)*2, Fv, 'MinPeakProminence',0.2, 'WidthReference','halfheight')
pks = 2x1
1.0738 0.9458
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
frqs = 1x2
0.2441 2.4414
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
wdths = 1x2
0.4393 0.4206
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Fco = 0.4;
figure
plot(Fv, abs(FTs1)*2)
xlim([0 5])
xlabel('Frequency')
ylabel('Power')
xline(0.4, '--k', "F_{co} = "+Fco)
fxl = xline(frqs, '--r', "Peak Frequency");
fxl(1).LabelVerticalAlignment = 'middle';
fxl(1).LabelHorizontalAlignment = 'center';
fxl(2).LabelVerticalAlignment = 'middle';
fxl(2).LabelHorizontalAlignment = 'center';
red = lowpass(green, Fco, Fs, 'ImpulseResponse','iir');
figure
plot(t, green, '-g')
hold on
plot(t, red, '-r')
hold off
set(gca, 'Color','k')
function [FTs1,Fv] = FFT1(s,t)
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
FTs1 = FTs(Iv,:);
end
The results of the findpeaks call will allow you to position the passbands and stopbands appropriately. The outputs are respectively the peaks, frequencies of the peaks, and full-width-half-maximum (FWHM) with respect to frequency of the peaks on the Fourier transform.
.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 9 Jun 2024
Edited: Image Analyst on 9 Jun 2024
One way is use envelope, envspectrum, or audioEnvelope.
Once you have the envelope, just subtract the lower curve of the envelope from your data.
In spectroscopy there are numerous methods to do "baseline correction". For example one basically uses the convex hull to find the lower envelop and then subtract that from the data, essentially pulling the valleys of your data down to the x axis.
Here is a comment block from one of my programs functions that does "Convex Polygonal Line baseline correction":
%=======================================================================================
%> @ingroup maths
%>@file
%>@brief Convex Polygonal Line baseline correction
%>
%> This was inspired on OPUS Rubberband baseline correction (RBBC) [1].
%>
%> Stretches a convex polygonal line whose vertices touch troughs of x
%> without crossing x (see below).
%>
%> This one is parameterless, whereas OPUS RBBC asks for a number of points.
%>
%> @image html rubberlike_explain.png
%>
%> <h3>References</h3>
%> [1] Bruker Optik GmbH, OPUS 5 Reference Manual. Ettlingen: Bruker, 2004.
%>
%> @sa demo_pre_bc_rubber.m
%
%> @param X [@ref no]x[@ref nf] matrix whose rows will be individually baseline-corrected
%>
%> @return @em [Y] or @em [Y, L] Where @em L are the baselines
By the way, these methods, like @Star Strider's are not real time. They depend on you having at least some time stretch of data to work with. I don't know whether it will work with a 1 second capture of a signal or a 10 second capture of a signal, but there will be a delay where you capture some amount of time, then filter it, then pass it on to whatever part of your process needs it next. The lag will be as much as the capture time plus the processing time.
There is no way you can do a perfectly real time adjustment of your signal of one data point at a time because you don't know the baseline for just one point. The best you could do is some sort of estimation of what the baseline for that point might be based on an analysis of data immediately prior to your new data point. So you'd always have a sliding "look back" period to estimate the amount of correction needed. If your data collection is slow enough then it could appear real time if you could process the old data fast enough to make an estimate on the new data.

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!