Implementing Hilbert Function to obtain envelope

5 views (last 30 days)
William Greenway on 3 Mar 2022
I'm trying to implement a Hilbert filter in order to get the envelope of a signal. I ideally want to use:
Hilbert = firpm(64 , [0.05 0.95] , [1 1] , 'Hilbert');
I have produced some test code which I have tested using a sinusoid, but find that the output has an amplitude lower than the peak of the signal. I have some code which produces the correct output (below):
z = sin((1:10000)./100);
Envelope = abs(hilbert(z));
figure;
plot(1:10000, z, 1:10000, Envelope);
and some code using the firpm() function which doesn't look as accurate:
z = sin((1:10000)./100);
% Design Hilbert Filter
HilbertOrder = 64;
Hilbert = firpm(HilbertOrder , [0.05 0.95] , [1 1] , 'Hilbert');
% Apply Hilbert Filter
Hilbert_out = filter(Hilbert,1,z);
% Calculate envelope including delay of 1/2 HilbertOrder
Envelope = sqrt((z(1:end-HilbertOrder/2)).^2 + (Hilbert_out((HilbertOrder/2+1):(end))).^2);
% Plot results
plot(1:10000, z, 1:length(Envelope), Envelope);
Why does the output of the second code not look as good as the first? Is anything wrong with the second code? What can I do to make the envelope a better approximation?

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by