Pages

Thursday, September 24, 2015

Matlab: Removing silence part in signal processing

I am just try and error in this matlab thing about a month ago tried to figure out a way to remove silence in signal. And at last i have found this solution on youtube.

[x,Fs] = audioread('Matlab\data\wav\example.wav'); no_silence_sig = silence_removal(Fs,x);


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
function no_silence_sig = silence_removal(fs,get_audio)
    
    frame_len = 0.01*fs; % 0.01 per frame
    N = length(get_audio);
    num_frames = floor(N/frame_len);
    new_sig = zeros(N,1);
    count = 0;
    
    for k=1:num_frames
       frame = get_audio((k-1)*frame_len+1 : frame_len*k);
       max_val = max(frame);
        %only append signal at amplitude >0.02
       if(max_val > 0.02)
            count = count+1;
            new_sig((count-1)*frame_len+1 : frame_len*count) = frame;
       end
    end
    
    % remove trailing zero in signal
    no_silence_sig=new_sig(1:find(new_sig, 1, 'last'));
end


No comments:

Post a Comment