# Automate the length of samples in the envelope function to get the optimal peak envelope from various signals

1 view (last 30 days)

Show older comments

Shiva Vikram Bhagavatula
on 16 May 2023

Commented: Star Strider
on 22 May 2023

##### 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

##### 0 Comments

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!