Amplitude increase after filter
Show older comments
Hello,
I am using a moving average to filter and find the envelope of a raw signal. I am curious as to why the amplitude of the filtered envelope is so much higher than the original signal. Does anyone have a way to filter noise out of a signal, while keeping the integrity of the signal as close as possible?
My steps below, along with a screenshot of the raw and filtered envelope.
Thanks for any help
WindowEnvelope = .75;
step1 = abs(signal)/2; % take the absolute value of the signal
step2 = hilbert(step1); % take the hilbert transform of the absolute value
step3 = sqrt(step2.*conj(step2)); % take the sqrt of the complex conjugate of the hilbert transform
step4 = filtfilt(ones(1,round(Fs*WindowEnvelope))/round(Fs*.1),1,step3); %filter the signal
subplot(2,1,1)
plot(t, signal)
subplot(2,1,2)
plot(t, step4)

Accepted Answer
More Answers (4)
Kcire L
on 11 Mar 2021
Kcire L
on 11 Mar 2021
0 votes
4 Comments
Star Strider
on 11 Mar 2021
It seems to be acting normally. It has 0 dB at 0 Hz, so it is passing everything correctly, since 0 dB means no attenuation. It appears to have a very narrow passband and very steep attenuation, so it acts like a lowpass filter with a narrow passband.
To see this in greater detail, after the freqz call, add:
set(subplot(2,1,1), 'XLim',[0 500]) % Optional
set(subplot(2,1,2), 'XLim',[0 500]) % Optional
Set the axis limits to provide the best view, since it may be necessary to narrow them further.
Kcire L
on 11 Mar 2021
Kcire L
on 11 Mar 2021
Star Strider
on 11 Mar 2021
As always, my pleasure!
I would use the Signal Analyzer App, or calculate the fft of the signal, in order to determine its spectral characteristics, then let that information guide the filter design. A lowpass filter with a 100 Hz cutoff may well do what you want it to do. It is likely better than the moving-average filter, and much more predictable.
Filter design and implementation is straightforward in MATLAB. I will help you with that if necessary.
Kcire L
on 11 Mar 2021
1 Comment
Star Strider
on 11 Mar 2021
As always, my pleasure!
Assuming your sampling frequency is 20000 Hz (from the freqz output earlier):
Fs = 2E4;
Fn = Fs/2;
cutoff = 100;
[n,Wn] = buttord(cutoff/Fn, 1.1*cutoff/Fn, 1, 50);
[z,p,k] = butter(n,Wn);
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos, 2^14, Fs)
set(subplot(2,1,1), 'XLim',[0 500]) % Optional
set(subplot(2,1,2), 'XLim',[0 500]) % Optional
That should do what you want. (I have no idea what Octave has available, so I can only hope this works in Octave.)
Also, MATLAB Online might be an option. I have not used it, since I always have my desktop or a laptop available.
Kcire L
on 11 Mar 2021
0 votes
1 Comment
Star Strider
on 11 Mar 2021
Yes!
raw_filtered = filtfilt(sos, g, raw);
.
Categories
Find more on Multirate Signal Processing 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!
