Wednesday, August 12, 2015

Remove silent region in audio signal

[ip,fs]=audioread('so1.wav');
%plot(ip);
% step 1 - break the signal into frames of 0.1 seconds
fs = 11000; % sampling frequency
frame_duration = 0.04;
frame_len = frame_duration*fs;
N = length(ip);
num_frames= floor(N/frame_len);

new_sig = zeros(N,1);
count=0;
for k = 1 : num_frames
    % extracting a frame of speech
    frame = ip( (k-1)*frame_len + 1 : frame_len*k );
    % step 2 - identify non silence frames by finding frames with max amplitute more than
    % 0.03
   
    max_val = max(frame);
    if(max_val > 0.03)
        count=count+1;
        new_sig((count-1)*frame_len + 1 : frame_len*count) = frame;
    end
end

new_sig(frame_len*count:end)=[];
 plot(new_sig);

Filters

Low Pass filter

High Pass filter
Narrow Band Pass filter

Wide Band Pass filter
Notch filter

Band Reject filter
 

Friday, August 7, 2015

dir() function

dir(name) 

attribute_name= dir(name)

  • dir(name) lists files and folders that match the string name. When name is a folder, dir lists contents of the folder.
  • attribute_name= dir(name) returns attributes about name.

 

disp() function

disp(x)

disp(x) displays the contents of x without printing the variable name

input() function

result = input(prompt)

str = input(prompt, 's')


  • result = input(prompt) displays the prompt string on the screen, waits for input from the keyboard, evaluates any expression in the input, and returns the result.
  • str = input(prompt, 's') returned the entered text as Matlab string, without evaluating expression.

length() function

 num = length(array) 

 length(array) returns length along the largest dimension of the array or matrix.


% Example
A = [101, 20;
    10, 24;
    11, 7];

%Function
ANSWER = length(A);

%Display result 
disp('Result: ');
disp(ANSWER);

Result :

3

zeros() function

X = zeros(n)

X = zeros(m, n)

  • zeros(n) returns n by n matrix of zeros
  • zeros(m, n) returns a m by n matrix of zeros

ones() function



X = ones(n) 

X = ones(m, n)

·         ones(n) returns n by n matrix of ones

·         ones(m, n) returns a m by n matrix of ones


Recording sound from Microphone



MATLAB command "wavrecord" to read the audio signals from the microphone directly. The command format is

y = wavrecord(n, fs);



fs=16000; % Sampling rate

duration=2; % Recording duration

fprintf('Press any key to start  %g seconds of recording...', duration); pause

fprintf('Recording...');

y=wavrecord(duration*fs, fs);  % duration*fs is the total number of sample points

fprintf('Finished recording.\n');

 fprintf('Press any key to play the recording...'); pause;

fprintf('\n');

wavplay(y,fs);

Thursday, August 6, 2015

Band Pass Filter


There are applications where a particular band, or spread, or frequencies need to be filtered from a wider range of mixed signals. Filter circuits can be designed to accomplish this task by combining the properties of low-pass and high-pass into a single filter. The result is called a band-pass filter. Creating a bandpass filter from a low-pass and high-pass filter can be illustrated using block diagrams:
The main function of such a filter in a transmitter is to limit the bandwidth of the output signal to the minimum necessary to convey data at the desired speed and in the desired form. In a receiver, a band-pass filter allows signals within a selected range of frequencies to be heard or decoded, while preventing signals at unwanted frequencies from getting through.


There are basically two types of bandpass filters wide bandpass and narrow bandpass filters.

Wednesday, August 5, 2015

Digital Filtering in Matlab


Digital filtering is a widely used technique that is common in many fields of science and engineering.  Filters remove unwanted signals and noise from a desired signal.  There are many different kinds of filters, including low pass, high pass, band pass and band stop filters.  There is a large collection of filters that famous engineers and mathematicians have invented, including Hanning, Hamming, Blackman, Kaiser and Tukey windows.


y = filter(b,a,x) filters the input data, x, using a rational transfer function defined by the numerator and denominator coefficients b and a, respectively.
If a(1) is not equal to 1, then filter normalizes the filter coefficients by a(1). Therefore, a(1) must be nonzero.

y - Filtered data, returned as a vector, matrix, or multidimensional array of the same size as the input data, x.

  • If x is a vector, then filter returns the filtered data as a vector of the same size as x.
  • If x is a matrix, then filter acts along the first dimension and returns the filtered data for each column.
  • If x is a multidimensional array, then filter acts along the first array dimension whose size does not equal 1. 
* 'low' : Low-pass filters, which remove frequencies greater than some specified value.
* 'high' : High-pass filters, which remove frequencies lower than some specified value.
* 'stop' : Stop-band filters, which remove frequencies in a given range of values.