Zero Crossing Rate plotting
7 次查看(过去 30 天)
显示 更早的评论
I am writing a code to detect voiced vs un-voiced segment in a signal. I believe I have the correct approach and code. However, I am having difficulty trying to overlay the original signal and the zero crossing rate in the same plot. I need this to test, how effective the zero crossing rate is.
Additionally, is there any normalization that I may be missing ?
% Algorithm to identify presence of voice activity using zero crossing rate and energy
% of speech signal
clear all; clc; close all;
%% Read the input signal
[y, fs] = audioread('ISTS-16s-44100.wav');
N = length(y);
t = (0:N-1)/fs;
framelen = 128;
numframes = floor(N/framelen);
overlap = 0;
zcr = [];
for k = 1:numframes
arry = [];
zcr_frame = [];
frame = y((k-1)*framelen+1 : framelen*k) ;
for i = 2:length(frame)
arry(i) = sgn(frame(i)) - sgn(frame(i-1));
end
zcr_frame = sum(abs(arry));
zcr = [zcr zcr_frame] ;
end
figure (1); clf; hold on;
grid on;
plot(t,y);
xlabel('time(secs)'); ylabel('linear output')
t_zcr = (0:framelen:N-framelen)/fs ;
plot(t_zcr,zcr);
0 个评论
采纳的回答
Mathieu NOE
2021-2-5
hello again
this is an improved code - no inner for loop needed
clear all; clc; close all;
%% Read the input signal
[y, fs] = audioread('test_voice.wav');
N = length(y);
t = (0:N-1)/fs;
framelen = 128;
numframes = floor(N/framelen);
overlap = 0;
zcr = [];
for k = 1:numframes
frame = y((k-1)*framelen+1 : framelen*k) ;
arry = sign(frame(2:framelen)) - sign(frame(1:framelen-1));
zcr_frame = sum(abs(arry));
zcr = [zcr; zcr_frame] ;
end
% normalisation
zcr = zcr./max(zcr);
y = y./max(abs(y));
figure (1);
% t_zcr = (0:framelen:N-framelen)/fs ; % time stamp positionned at beginning of frame
t_zcr = (framelen/2:framelen:N-framelen/2)/fs ; % time stamp positionned at center of frame
plot(t,y,'b',t_zcr,zcr -1.5,'r');grid on;
xlabel('time(secs)'); ylabel('linear output')
2 个评论
Mathieu NOE
2021-2-9
hello
3. as the ZCR info is computed on a frame , for me it was more evident that the time index associated with it should be at the center of the frame rather that one or the other end. But this is just a belief. It's like when you plot a spectrogram, for me the spectral info which is an average of what the signal says in one buffer should be associated with time at the center of the buffer, not the begining
更多回答(1 个)
Mathieu NOE
2021-2-5
hello
I am not aware of a function sgn in matlab , I believe this must be sign ?
so this is modified and somehow I introduced normalisation for both signal and zcr values. The time vector associated with zcr I put the time values at the center of the frame (my 2 cents)
i plotted the two on the same plot simply shifting zcr below the audio wave so easier to see.
I assume that zcr output must be low when speech is present (which seems to be the case on my test signal)
clear all; clc; close all;
%% Read the input signal
[y, fs] = audioread('test_voice.wav');
N = length(y);
t = (0:N-1)/fs;
framelen = 128;
numframes = floor(N/framelen);
overlap = 0;
zcr = [];
for k = 1:numframes
arry = [];
zcr_frame = [];
frame = y((k-1)*framelen+1 : framelen*k) ;
for i = 2:length(frame)
arry(i) = sign(frame(i)) - sign(frame(i-1));
end
zcr_frame = sum(abs(arry));
zcr = [zcr zcr_frame] ;
end
% normalisation
zcr = zcr./max(zcr);
y = y./max(abs(y));
figure (1);
% t_zcr = (0:framelen:N-framelen)/fs ; % time stamp positionned at beginning of frame
t_zcr = (framelen/2:framelen:N-framelen/2)/fs ; % time stamp positionned at center of frame
plot(t,y,'b',t_zcr,zcr -1.5,'r');grid on;
legend('audio signal','zrc output');
xlabel('time(secs)'); ylabel('linear output')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Expression Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!