You are on page 1of 5

DELHI TECHNOLOGICAL UNIVERSITY

(FORMERLY Delhi College Engineering)

MATLAB CODE
FOR

AUDIO SIGNAL PROCESSING

SUBMITTED BY: SUBMITTED TO:

SANTOSH _RAI_2K20_EC_191 Dr. SACHIN TARAN


SHIVAM_2K20_EC_199
PROGRAM FOR ADDING AND REMOVING NOISE TO A SIGNAL

% Program to implement a LPF(FIR) with cutoff 8kHz to denoise audio signal.


[fileName, pathName] = uigetfile('*.*', 'select the input audio');
[x, Fs] = audioread(num2str(fileName)); % x is the audio samples and Fs is the
sampling rate.

% filter implementation
Fsf = 44100; % Sampling Frequency
Fp = 8e3; % Passband Frequency in Hz
Fst = 8.4e3; % stopband Frequency in Hz
Ap = 1; % passband ribble in db
Ast = 95; % stopband attenuations in db

df = designfilt('lowpassfir', 'PassbandFrequency', Fp, 'StopbandFrequency',...


Fst, 'passbandRipple', Ap, 'stopbandAttenuation', Ast, 'sampleRate', Fsf);

fvtool(df); % visualize freq response of filter


xn = awgn(x,15,'measured'); % signal corrupted by white Gaussian noise

y = filter(df, xn);
%plotting signals

subplot(3,1,1)
plot(x)
title('Original signal')
subplot(3,1,2)
plot(xn)
title('Noisy signal')
subplot(3,1,3)
plot(y)
title('Filtered signal')
output: -

Fig: magnitude vs frequency graph


Fig: phase vs frequency graph

Fig: Combined graph of magnitude/phase vs frequency


Program for adding and removing echo for a audio file

[filename, pathname] = uigetfile('*.*', 'select your audio file');


[w, Fs] = audioread(num2str(filename));
n = length(w); % length of the music file
a = 0.8; % attenuation factor(gain)
d = 2000; % Delay input stream
y = zeros((n + d),1); % Initialize the output music signal
q= zeros((n + d),1);
xn = padarray(w, [d,0], 0, 'pre');

for i = (d+1): 1: n
y(i-d,1) = w(i) + a*xn(i-d);
end

for i = (d+1): 1: n
q(i-d,1) = w(i) - a*xn(i-d);
end

You might also like