Automate the length of samples in the envelope function to get the optimal peak envelope from various signals
2 views (last 30 days)
Show older comments
Shiva Vikram Bhagavatula
on 16 May 2023
Commented: Star Strider
on 22 May 2023
The optimal extraction of peak envelope with the 'envelope' function (https://nl.mathworks.com/help/signal/ref/envelope.html) necessitates the optimal selection of the sample length ("The envelopes are determined using spline interpolation over local maxima separated by at least np samples."). While manual optimization of the length is the most common route, it does not allow a rapid and accurate envelope extraction from different types of signals (with different time - frequency relationships). Is there a way to automate the selection of sample length for obtaining the optimal envelope? How to describe the optimal peak envelope (one definition would be touching all the peaks with minimal difference)?
5 Comments
Star Strider
on 22 May 2023
This is the sort of approach I had in mind when I wrote my Answer —
clear all
close all
t=0:1e-9:1e-6;% time
fc=1e6; % carrier
del_f=300e3; % frequency deviation
mod_f=100e3; % modulating frequency
std_dev=10; %introduce randomness in amplitude of carrier and frequency deviation
amp=(std_dev*randn(length(t),1))';
mod_signal=1e-2*amp.*(del_f*cos(2*pi*mod_f*t)); % modulating signal with randomized frequency deviation
fmcw_mod=5*amp.*cos(2*pi*fc*t+mod_signal); % fmcw modulated signal
figure
plot(t,fmcw_mod);
factor=2^9
% env_len=round(length(fmcw_mod)/factor);%length over which the function executes
[pks,locs] = findpeaks(fmcw_mod, 'MinPeakProminence',10) % Use 'MinPeakProminence' To Select The Peaks To Detect
env_len = floor(median(diff(locs))) % Create An Appropriate Metric From The Returned Peak Indices
[up,lo]=envelope(fmcw_mod,env_len,'peak');
hold all
plot(t,up);% upper envelope
plot(t,lo);% lower envelope
figure
plot(t,fmcw_mod);
hold on
plot(t,up);% upper envelope
plot(t,lo);% lower envelope
hold off
xlim([0.4 0.6]*1E-6)
title('Detail')
.
Accepted Answer
Star Strider
on 17 May 2023
Consider first using either findpeaks or islocalmax with find, and then calculate the appropriate distances (using min, max, mean, median or some other metric on the differences of the peak locations) to get the appropriate parameter for the second envelope argument. This is likely easiest, although another option would be to calculate the one-sided fft, find the peaks of the absolute values, and then calculate the inverse of the frequency at that peak location.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!