In: Electrical Engineering
Design a matlab code that:
1-play sound
2- add noise to the sound
3- filter the noised signal using fir or iir filter
Note: FIR: Finite impulse response filter
IIR: Infinite impulse response filter
functionvarargout = Voice(varargin)
% VOICE MATLAB code for Voice.fig
% VOICE, by itself, creates a new VOICE or raises the
existing
% singleton*.
%
% H = VOICE returns the handle to a new VOICE or the handle
to
% the existing singleton*.
%
% VOICE('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in VOICE.M with the given input
arguments.
%
% VOICE('Property','Value',...) creates a new VOICE or raises
the
% existing singleton*. Starting from the left, property value
pairs
are
% applied to the GUI before Voice_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to Voice_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows
only
one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Voice
% Last Modified by GUIDE v2.5 26-May-2014 13:51:10
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Voice_OpeningFcn, ...
'gui_OutputFcn', @Voice_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin&&ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
ifnargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Voice is made visible.
functionVoice_OpeningFcn(hObject, eventdata, handles,
varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Voice (see VARARGIN)
% Choose default command line output for Voice
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Voice wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
functionvarargout = Voice_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see
VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
F1=7000;
F2=800;
F3=1000;
a=2*F2/F1;
b=2*F3/F1
r1=2;
r2=60;
p1=1-10.^(-r1/20);
s1=10.^(-r2/20);
FF=[a b];
ma=[1 0];
v=[p1 s1];
[A21,wA21,bt,Yp]=kaiserord(FF,ma,v);
B21=fir1(A21,wA21,kaiser(A21+1,bt));
[h,w]=freqz(B21,1);
figure;
plot(w*7000*0.5/pi,abs(h));
title('FIR low pass filter','fontweight','bold');
grid;
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
F1=4000;
F2=3500;
F3=3000;
a=2*F2/F1;
b=2*F3/F1
r1=2;
r2=60;
p=1-10.^(-r1/20);
s=10.^(-r2/20);
FF=[b a];
ma=[0 1];
v=[p s];
[A23,wA23,bt,Yp]=kaiserord(FF,ma,v);
B23=fir1(A23,wA23,'high',kaiser(A23+1,bt));
[h,w]=freqz(B23,1);
figure;
plot(w*10000*0.5/pi,abs(h));
title('FIR high pass filter', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
F21=1000;
F22=2500;
F31=3200;
F32=3000;
F1=7000;
a1=tan(pi*F21/F1);
a2=tan(pi*F22/F1)
b1=tan(pi*F31/F1);
b2=tan(pi*F32/F1);
w=a1*a2/b2;
bw=a2-a1;
a=2;
b=(a*a2-w.^2)/(bw*w);
[A02,wA02]=buttord(a,b,2,60, 's');
[B02,A02]=butter(A02,wA02, 's');
[n2,d2]=lp2bp(B02,A02,sqrt(a1*a2),bw);
[n22,deA02]=bilinear(n2,d2,0.5);
[h,w]=freqz(n22,deA02);
figure;
plot(w*6000*0.5/pi,abs(h));
title('FIR band pass filter', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
F1=7500;
F2=900;
F3=1100;
a=2*pi*F2/F1;
b=2*pi*F3/F1;
F2=2*F1*tan(a/2);
F3=2*F3*tan(a/2);
[C11,wC11]=buttord(a,b,2.60,'s');
[D11,C11]=butter(C11,wC11, 's');
[m11,deC11]=bilinear(D11,C11,0.5);
[h,w]=freqz(m11,deC11);
figure;
plot(w*7000*0.5/pi,abs(h));
title('IIR low pass filter', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
F1=8000;
F2=4000;
F3=3600;
a1=tan(pi*F2/F1);
b1=tan(pi*F3/F1);
a=2;
b=a1*a/b1;
[D13,wD13]=cheb1ord(a,b,2,60, 's');
[C13,D13]=cheby1(D13,1,wD13, 's');
[SHL,den]=lp2hp(C13,D13,wD13);
[n13,deD13]=bilinear(SHL,den,0.5);
[h,w]=freqz(n13,deD13);
figure;
plot(w*18000*0.5/pi,abs(h));
title(' IIR high pass filter', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
F21=1100;
F22=3000;
F31=900;
F32=3100;
F1=7800;
a1=tan(pi*F21/F1);
a2=tan(pi*F22/F1)
b1=tan(pi*F31/F1);
b2=tan(pi*F32/F1);
w=a1*a2/b2;
ww=a2-a1;
a=1;
b=(a1*a2-w.^2)/(ww*w);
[D12,wD12]=buttord(a,b,1,50, 's');
[C12,D12]=butter(D12,wD12, 's');
[n2,d2]=lp2bp(C12,D12,sqrt(a1*a2),ww);
[SHL12,deD12]=bilinear(n2,d2,0.5);
[h,w]=freqz(SHL12,deD12);
figure;
plot(w*7000*0.5/pi,abs(h));
title(' IIR band pass filter', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
n=10;
fs=16000;
channel=1;
y=audiorecorder(n*fs,fs,channel,'unit8');
pause
audioplayer(y,fs);
figure;
plot(y);
audiowrite(y,fs,'OriSound.wav');
pause
[y,fs,bits]=('OriSound.wav');
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
[y1,fs,bits]=wavread('D:\Orivoice.wav');
nor1=y1/max(y1);
sound(nor1,fs,bits);
data=round(32767*nor1);
t1=fopen('data.dat','w');
fprintf(t1,'1651 1 0 0 0\n');
fprintf(t1,'%d\n',data);
fclose(t1);
n=length(y1);
Noise=0.1*randn(size(y1));
s=y1+Noise;
S=fft(s,n);
normal=s/max(s);
cha=round(32767*normal);
pause(4);
sound(normal,fs,bits);
ch=fopen('cha.dat','w');
fprintf(ch,'1651 1 0 0 0\n');
fprintf(ch,'%d\n',cha);
fclose(ch);
F1=7000;
F2=1000;
F3=1100;
w1=2*pi*F2/F1;
w2=2*pi*F3/F1;
r1=1;
r2=50;
p=1-10.^(-r1/20);
q=10.^(-r2/20);
fp=[w1 w2];
mg=[1 0];
de=[p q];
[A21,wA21,beta,ftype]=kaiserord(fp,mg,de);
C21=fir1(A21,wA21,kaiser(A21+1,beta));
D21=fftfilt(C21,s);
sound(D21,fs,bits);
%sound(D21);
E21=fft(D21);
figure;
subplot(3,3,1);
plot(abs(S), 'g');
title('signal spectrum before filtering', 'fontweight',
'bold');
grid;
subplot(3,3,2);
plot(abs(E21), 'r');
title('signal spectrum after filtering', 'fontweight',
'bold');
grid;
subplot(3,3,3);
plot(s);
title('waveform before filtering', 'fontweight', 'bold');
grid;
subplot(3,3,4);
plot(D21);
title('waveform after filtering', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
[y,fs,bits]=wavread('D:\Orivoice.wav');
m=max(y);
normal1=y/max(y);
sound(normal1,fs,bits);
indata=round(32767*normal1);
tem1=fopen('indata.dat','w');
fprintf(tem1,'1651 1 0 0 0\n');
fprintf(tem1,'%d\n',indata);
fclose(tem1);
%sound(y,fs,nbits);
n=length(y);
Noise=0.1*randn(size(y));
s=y+Noise;
S=fft(s,n);
normal=s/max(s);
chang=round(32767*normal);
pause(4);
sound(normal,fs,bits);
ch=fopen('chang.dat','w');
fprintf(ch,'1651 1 0 0 0\n');
fprintf(ch,'%d\n',chang);
fclose(ch);
F1=8001;
F2=4000;
F3=3200;
w1=2*F2/F1;
w2=2*F3/F1;
r1=1;
r2=100;
p=1-10.^(-r1/20);
q=10.^(-r2/20);
fp=[w2 w1];
mg=[0 1];
de=[p q];
[A23,wA23,BT,ftype]=kaiserord(fp,mg,de);
C23=fir1(A23,wA23,'high',kaiser(A23+1,BT));
D23=fftfilt(C23,s);
sound(D23,fs,bits);
E23=fft(D23);
figure;
subplot(3,3,1);
plot(abs(S), 'g');
title('signal spectrum before filtering', 'fontweight',
'bold');
grid;
subplot(3,3,2);
plot(abs(E23), 'r');
title('signal spectrum after filtering', 'fontweight',
'bold');
grid;
subplot(3,3,3);
plot(s);
title('waveform before filtering', 'fontweight', 'bold');
grid;
subplot(3,3,4);
plot(D23);
title('waveform after filtering', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
[y,fs,bits]=wavread('D:\Orivoice.wav');
m=max(y);
normal1=y/max(y);
sound(normal1,fs,bits);
indata=round(32767*normal1);
tem1=fopen('indata.dat','w');
fprintf(tem1,'1651 1 0 0 0\n');
fprintf(tem1,'%d\n',indata);
fclose(tem1);
n=length(y);
Noise=0.1*randn(size(y));
s=y+Noise;
S=fft(s,n);
normal=s/max(s);
chang=round(32767*normal);
pause(4);
sound(normal,fs,bits);
ch=fopen('chang.dat','w');
fprintf(ch,'1651 1 0 0 0\n');
fprintf(ch,'%d\n',chang);
fclose(ch);
F11=1200;
F12=3000;
Fc1=1000;
Fc2=3200;
Fa=2200;
w11=tan(pi*F11/Fa);
w12=tan(pi*F12/Fa);
w21=tan(pi*Fc1/Fa);
w22=tan(pi*Fc2/Fa);
w=w11*w12/w22;
bw=w12-w11;
w1=1;
w2=(w1*w12-w.^2)/(bw*w);
[A22,wA22]=buttord(w1,w2,1,50, 's');
[C22,a22]=butter(A22,wA22, 's');
D22=fftfilt(C22,s);
sound(D22,fs,bits);
E22=fft(D22);
figure;
subplot(3,3,1);
plot(abs(S), 'g');
title('signal spectrum before filtering', 'fontweight',
'bold');
grid;
subplot(3,3,2);
plot(abs(E22), 'r');
title('signal spectrum after filtering', 'fontweight',
'bold');
grid;
subplot(3,3,3);
plot(s);
title('waveform before filtering', 'fontweight', 'bold');
grid;
subplot(3,3,4);
plot(D22);
title('waveform after filtering', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
[y,fs,bits]=wavread('D:\Orivoice.wav');
m=max(y);
normal1=y/max(y);
sound(normal1,fs,bits);
indata=round(32767*normal1);
tem1=fopen('indata.dat','w');
fprintf(tem1,'1651 1 0 0 0\n');
fprintf(tem1,'%d\n',indata);
fclose(tem1);
n=length(y);
Noise=0.1*randn(size(y));
s=y+Noise;
S=fft(s,n);
normal=s/max(s);
chang=round(32767*normal);
pause(4);
sound(normal,fs,bits);
ch=fopen('chang.dat','w');
fprintf(ch,'1651 1 0 0 0\n');
fprintf(ch,'%d\n',chang);
fclose(ch);
F1=8000;
F2=1000;
F3=1200;
w1=2*pi*F2/F1;
w2=2*pi*F3/F1;
fp=2*F1*tan(w1/2);
fs=2*F3*tan(w2/2);
[A11,wA11]=buttord(w1,w2,1,50,'s');
[C11,B11]=butter(A11,wA11,'s');
[N11,deA11]=bilinear(C11,B11,0.5);
[h,w]=freqz(N11,deA11);
D11=filter(N11,deA11,s);
pause(4);
normal2=D11/max(D11);
sound(normal2,fs,bits);
chang1=round(32767*normal2);
ch1=fopen('chang1.dat','w');
fprintf(ch1,'1651 1 0 0 0\n');
fprintf(ch1,'%d\n',chang1);
fclose(ch1);
F11=fft(D11);
figure;
subplot(3,3,1);
plot(abs(S), 'g');
title('signal spectrum before filtering', 'fontweight',
'bold');
grid;
subplot(3,3,2);
plot(abs(F11), 'r');
title('signal spectrum after filtering', 'fontweight',
'bold');
grid;
subplot(3,3,3);
plot(s);
title('waveform before filtering', 'fontweight', 'bold');
grid;
subplot(3,3,4);
plot(D11);
title('waveform after filtering', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton16 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
[y,fs,bits]=wavread('D:\Orivoice.wav');
m=max(y);
normal1=y/max(y);
sound(normal1,fs,bits);
indata=round(32767*normal1);
tem1=fopen('indata.dat','w');
fprintf(tem1,'1651 1 0 0 0\n');
fprintf(tem1,'%d\n',indata);
fclose(tem1);
n=length(y);
Noise=0.1*randn(size(y));
s=y+Noise;
S=fft(s,n);
normal=s/max(s);
chang=round(32767*normal);
pause(4);
sound(normal,fs,bits);
ch=fopen('chang.dat','w');
fprintf(ch,'1651 1 0 0 0\n');
fprintf(ch,'%d\n',chang);
fclose(ch);
F1=8000;
F2=1200;
F3=1000;
w11=tan(pi*F2/F1);
w21=tan(pi*F3/F1);
w1=1; w2=w11*w1/w21;
[A12,wA12]=cheb1ord(w1,w2,1,50,'s');
[B12,C12]=cheby1(A12,1,wA12,'s');
[NM,DE]=lp2hp(B12,C12,wA12);
[NG12,deA12]=bilinear(NM,DE,0.5);
[h,w]=freqz(NG12,deA12);
F12=filter(NG12,deA12,s);
sound(F12,fs,bits);
G12=fft(F12);
figure;
subplot(3,3,1);
plot(abs(S), 'g');
title('signal spectrum before filtering', 'fontweight',
'bold');
grid;
subplot(3,3,2);
plot(abs(G12), 'r');
title('signal spectrum after filtering', 'fontweight',
'bold');
grid;
subplot(3,3,3);
plot(s);
title('waveform before filtering', 'fontweight', 'bold');
grid;
subplot(3,3,4);
plot(F12);
title('waveform after filtering', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton17 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
[y,fs,bits]=wavread('D:\Orivoice.wav');
m=max(y);
normal1=y/max(y);
sound(normal1,fs,bits);
indata=round(32767*normal1);
tem1=fopen('indata.dat','w');
fprintf(tem1,'1651 1 0 0 0\n');
fprintf(tem1,'%d\n',indata);
fclose(tem1);
n=length(y);
Noise=0.1*randn(size(y));
s=y+Noise;
S=fft(s,n);
normal=s/max(s);
chang=round(32767*normal);
pause(4);
sound(normal,fs,bits);
ch=fopen('chang.dat','w');
fprintf(ch,'1651 1 0 0 0\n');
fprintf(ch,'%d\n',chang);
fclose(ch);
F11=1200;
F12=3000;
F01=1000;
F02=3200;
F1=8000;
w11=tan(pi*F11/F1);
w12=tan(pi*F12/F1);
w21=tan(pi*F01/F1);
w22=tan(pi*F02/F1);
w=w11*w12/w22;
bw=w12-w11;
w1=1;
w2=(w1*w12-w.^2)/(bw*w);
[A12,wA12]=buttord(w1,w2,1,50, 's');
[B12,a12]=butter(A12,wA12, 's');
[NM2,DE2]=lp2bp(B12,a12,sqrt(w11*w12),bw);
[NG12,deA12]=bilinear(NM2,DE2,0.5);
C21=filter(NG12,deA12,s);
sound(C21,fs,bits);
E21=fft(C21);
figure;
subplot(3,3,1);
plot(abs(S), 'g');
title('signal spectrum before filtering', 'fontweight',
'bold');
grid;
subplot(3,3,2);
plot(abs(E21), 'r');
title('signal spectrum after filtering', 'fontweight',
'bold');
grid;
subplot(3,3,3);
plot(s);
title('waveform before filtering', 'fontweight', 'bold');
grid;
subplot(3,3,4);
plot(C21);
title('waveform after filtering', 'fontweight', 'bold');
grid;
% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton20 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
%function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
This will help you get answer for your question. If not, Just try to modify changes because the version of software may be different. Please don,t give bad review to me because I tried my level best.