Detect the boundary of signal
조회 수: 10 (최근 30일)
이전 댓글 표시
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')
댓글 수: 0
답변 (1개)
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
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 Exchange에서 AI for Signals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!