フィルターのクリア

Detect the boundary of signal

6 ビュー (過去 30 日間)
Sabella Huang
Sabella Huang 2023 年 6 月 25 日
コメント済み: Star Strider 2023 年 6 月 25 日
Hi Guys,
I have one example of sound signal. In this case, I want to automatically detect the boundary of sound signal. I tried to use Hilbert envelope, but I stuck to determine the boundary of the signal. Please help me to revise my code as below
readExcel = xlsread('Test.xlsx');
data = readExcel(:,1);
time = linspace(1,max(length(data)),length(data))';
idx = data>=0 ;
y = hilbert(data(idx));
env = abs(y);
plot_param = {'Color', [0.6 0.1 0.2],'Linewidth',2};
data_neg = -1*data;
idx_neg = data>=0;
y_d = hilbert(data_neg(idx_neg));
env_down = -1*abs(y_d);
plot(time, data)
hold on
plot(time(idx),env,plot_param{:})
plot(time(idx),env_down,plot_param{:})
hold off
title('Hilbert Envelope')

回答 (1 件)

Star Strider
Star Strider 2023 年 6 月 25 日
This is easier if you have the envelope function (introduced in R2015b) since it has options that hilbert does not —
readExcel = readmatrix('Test.xlsx');
data = readExcel(:,1);
time = linspace(1,max(length(data)),length(data))';
% idx = data>=0 ;
% y = hilbert(data(idx));
% env = abs(y);
window_length = 3; % ADDED
[env,env_down] = envelope(data, window_length, 'peak'); % CHANGED
plot_param = {'Color', [0.6 0.1 0.2],'Linewidth',2};
data_neg = -1*data;
idx_neg = data>=0;
% y_d = hilbert(data_neg(idx_neg));
% env_down = -1*abs(y_d);
figure
plot(time, data)
hold on
plot(time,env,plot_param{:})
plot(time,env_down,plot_param{:})
hold off
title('Hilbert Envelope')
figure
plot(time, data)
hold on
plot(time,env,plot_param{:})
plot(time,env_down,plot_param{:})
hold off
title('Hilbert Envelope (Detail)')
xlim([3.9 4.1]*1E+4)
The ‘boundary’ with respect to the peaks is the envelope output in that region. Adjust the ‘window_length’ parameter to get the result you want.
Another option to get the approximate signal boundaries is to use a lowpass filter. Experiment with the cutoff frequency to get the result you want. (For best results, use the 'ImpulseResponse','iir' name-value pair.)
See the envelope function documentation for details.
.
  2 件のコメント
Sabella Huang
Sabella Huang 2023 年 6 月 25 日
Hi sir,
Thank you for reply.
Is it possible if I used this method to get a boundary of signal like this figure? For example, defining the boundary of the signal from the cross line of envelope in positive and negative value
Star Strider
Star Strider 2023 年 6 月 25 日
My pleasure!
My code (using envelope) creates the upper and lower envelopes individually (one of the benefits of using the envelope function).
I am not certain what you want, from your description. The two envelope outputs should not cross each other, although I suppose that is possible if ‘window_length’ is such (likely too high) that there are transients and the transients overlap.
I am repeating the earlier code and adding plots of the upper and lower envelopes individually to see if that might help define what you want to do.
readExcel = readmatrix('Test.xlsx');
data = readExcel(:,1);
time = linspace(1,max(length(data)),length(data))';
% idx = data>=0 ;
% y = hilbert(data(idx));
% env = abs(y);
window_length = 3; % ADDED
[env,env_down] = envelope(data, window_length, 'peak'); % CHANGED
plot_param = {'Color', [0.6 0.1 0.2],'Linewidth',2};
data_neg = -1*data;
idx_neg = data>=0;
% y_d = hilbert(data_neg(idx_neg));
% env_down = -1*abs(y_d);
figure
plot(time, data)
hold on
plot(time,env,plot_param{:})
plot(time,env_down,plot_param{:})
hold off
title('Hilbert Envelope')
figure
plot(time, data)
hold on
plot(time,env,plot_param{:})
plot(time,env_down,plot_param{:})
hold off
title('Hilbert Envelope (Detail)')
xlim([3.9 4.1]*1E+4)
figure
tiledlayout(2,1)
nexttile
plot(time,env,plot_param{:})
title('Upper Envelope (Detail)')
xlim([3.9 4.1]*1E+4)
ylim([-200 800])
nexttile
plot(time,env_down,plot_param{:})
title('Lower Envelope (Detail)')
xlim([3.9 4.1]*1E+4)
ylim([-800 200])
I have no t yet experimented with lowpass filtering, however I willl do that if you want to see if that would help get the result you want. In that respect, it would help significantly to know what the sampling frequency of the signal is, since that has not yet been provided.
.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by