Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Problem. The output does not sound. What is the error. Need help, thanks!

ID: 669414 • Letter: M

Question

MATLAB Problem. The output does not sound. What is the error. Need help, thanks!

clear all %Clear working space
close all
%*******************************************************************
%**************************Input/Output*****************************
%*******************************************************************
[sig,Fs]=audioread('coqui1.wav'); %Get overall sampling frequency
save dwave.txt sig -ascii %Save signal as dwave.txt file
load -ascii dwave.txt; %Load ascii file dwave.txt
dsiz=length(dwave); %Get the length of the dwave signal
%*******************************************************************
%**************************Parameter Setting************************
%*******************************************************************
xlength=dsiz; %Set length of input signal
Ts=1/Fs; %Set overall time resolution
Vdwave=dsiz*Ts; %Set time observation window
Frx=(1/Vdwave); %Set frequency resolution for xdwave
txdwave=0:Ts:Vdwave-Ts; %Set time axis for xdwave
fxdwave=-(Fs/2):Frx:(Fs/2)-Frx; %Set frequency axis for xdwave
wm1=2*(1200)/Fs; %Set normalized cut-off frequency
wm2=2*(1700)/Fs;
wm3=2*(2200)/Fs;
wm4=[wm2 wm3];
ordfil=floor((2*(0.025*dsiz)))+1; %Set filter length
tfilter=0:Ts:(ordfil-1)*Ts; %Set time axis for filter hLow
xdwave=dwave; %Set name of input signal
ylength=(dsiz+ordfil)-1; %Set length of output signal
tydwave=0:Ts:(ylength-1)*Ts; %Set time axis for output signal
Fry=(1/(ylength*Ts)); %Set output frequency resolution   
fydwave=-(Fs/2):Fry:(Fs/2)-Fry; %Set frequency axis of output signal
Frh=(1/(ordfil*Ts)); %Set filter frequency resolution
fhLow=-(Fs/2):Frh:(Fs/2)-Frh; %Set frequency axis of filter
%*******************************************************************
%************Signal Filtering Using Linear Convolution**************
%*******************************************************************
hLowpass=fir1(ordfil-1,wm1,'low'); %Compute filter coefficients
hbandpass=fir1(ordfil-1,wm4,'bandpass');
ydwave=conv(xdwave,hLowpass); %Compute the convolution operation
ydwave1=conv(xdwave,hbandpass);
Fxdwav=fft(xdwave); %Take the FFT of input signal
Fydwav=fft(ydwave); %Take the FFT of output signal
Fydwav1=fft(ydwave1);
FhLow=fft(hLowpass); %Take the FFT of impulse response
FhLow1=fft(hbandpass);
sFxdwa=fftshift(Fxdwav); %Set negative frequency format for X
sFydwa=fftshift(Fydwav); %Set negative frequency format for Y
sFydwa1=fftshift(Fydwav1);
sFhLow=fftshift(FhLow); %Set negative frequency format for H
sFhLow1=fftshift(FhLow1);
asFxdw=abs(sFxdwa); %Compute absolute value of spectrum X
asFydw=abs(sFydwa); %Compute aboslute value of spectrum Y
asFydw1=abs(sFydwa1);
asFhLow=abs(sFhLow); %Compute absolute value of Spectrum H
asFhLow1=abs(sFhLow1);
%*********************************************************************
%**************************PLOTS**************************************
%*********************************************************************
figure
plot(txdwave,xdwave) %Plot input signal in time
grid %Set a grid
xlabel('Time in Seconds') %Label the time axis
ylabel('Magnitude') %Label the magnitude axis
title('Input Signal xdwave(t)') %Place the title name
%*********************************************************************
figure
plot(tydwave,ydwave1) %Plot output signal in time
grid %Set a grid
xlabel('Time in Seconds') %Label the time axis
ylabel('Magnitude') %Label the magnitude axis
title('Output (FILTERED INPUT)Signal ydwave(t)') %Place the title name
%*********************************************************************
figure
plot(tfilter,hLowpass) %Plot impulse response in time
grid %Set a grid
xlabel('Time in Seconds') %Label the time axis
ylabel('Magnitude') %Label the the magnitude axis
title('Impulse Response of Low Pass Filter hLow(t)') %Place the title name
%*********************************************************************
figure
plot(fxdwave,asFxdw) %Plot input signal's spectrum
grid %Set a grid
xlabel('Frequency in Hertzs') %Label the frequency axis
ylabel('Magnitude') %Label the magnitude axis
title('Spectrum of Input xdwave') %Place the title name
%*********************************************************************
figure
plot(fydwave,asFydw1) %Plot output signal's spectrum
grid %Set a grid
xlabel('Frequency in Hertzs') %Label the frequency axis
ylabel('Magnitude') %Label the magnitude axis
title('Spectrum of Output (FILTERED SIGNAL) ydwave') %Place the title name
%*********************************************************************
figure
plot(fhLow,asFhLow1) %Plot output signal's spectrum
grid %Set a grid
xlabel('Frequency in Hertzs') %Label the frequency axis
ylabel('Magnitude') %Label the magnitude axis
title('Magnitude of Frequency Response HLow') %Place the title name
%*********************************************************************
%**************************SOUNDS*************************************
%*********************************************************************
sound(xdwave,Fs) %Listen to input signal xdwave
pause(3)
sound(ydwave,Fs) %Listen to output signal ydwave
pause(3)
sound(ydwave1,Fs)

Explanation / Answer

I have correct the program

please copy coquil.wav in the same directory of the program and run it.

there are some error in the program which i have corrected.

clear all %Clear working space
close all
%*******************************************************************
%**************************Input/Output*****************************
%*******************************************************************
[sig,Fs]=audioread('coquil.wav'); %Get overall sampling frequency
save dwave.txt sig -ascii %Save signal as dwave.txt file
load -ascii dwave.txt; %Load ascii file dwave.txt
dsiz=length(dwave); %Get the length of the dwave signal
%*******************************************************************
%**************************Parameter Setting************************
%*******************************************************************
xlength=dsiz; %Set length of input signal
Ts=1/Fs; %Set overall time resolution
Vdwave=dsiz*Ts; %Set time observation window
Frx=(1/Vdwave); %Set frequency resolution for xdwave
txdwave=0:Ts:Vdwave-Ts; %Set time axis for xdwave
fxdwave=-(Fs/2):Frx:(Fs/2)-Frx; %Set frequency axis for xdwave
wm1=2*(1200)/Fs; %Set normalized cut-off frequency
wm2=2*(1700)/Fs;
wm3=2*(2200)/Fs;
wm4=[wm2 wm3];
ordfil=floor((2*(0.025*dsiz)))+1; %Set filter length
tfilter=0:Ts:(ordfil-1)*Ts; %Set time axis for filter hLow
xdwave=dwave; %Set name of input signal
ylength=(dsiz+ordfil)-1; %Set length of output signal
tydwave=0:Ts:(ylength-1)*Ts; %Set time axis for output signal
Fry=(1/(ylength*Ts)); %Set output frequency resolution   
fydwave=-(Fs/2):Fry:(Fs/2)-Fry; %Set frequency axis of output signal
Frh=(1/(ordfil*Ts)); %Set filter frequency resolution
fhLow=-(Fs/2):Frh:(Fs/2)-Frh; %Set frequency axis of filter
%*******************************************************************
%************Signal Filtering Using Linear Convolution**************
%*******************************************************************
hLowpass=fir1(ordfil-1,wm1,'low'); %Compute filter coefficients
hbandpass=fir1(ordfil-1,wm4,'bandpass');
ydwave=conv(xdwave,hLowpass); %Compute the convolution operation
ydwave1=conv(xdwave,hbandpass);
Fxdwav=fft(xdwave); %Take the FFT of input signal
Fydwav=fft(ydwave); %Take the FFT of output signal
Fydwav1=fft(ydwave1);
FhLow=fft(hLowpass); %Take the FFT of impulse response
FhLow1=fft(hbandpass);
sFxdwa=fftshift(Fxdwav); %Set negative frequency format for X
sFydwa=fftshift(Fydwav); %Set negative frequency format for Y
sFydwa1=fftshift(Fydwav1);
sFhLow=fftshift(FhLow); %Set negative frequency format for H
sFhLow1=fftshift(FhLow1);
asFxdw=abs(sFxdwa); %Compute absolute value of spectrum X
asFydw=abs(sFydwa); %Compute aboslute value of spectrum Y
asFydw1=abs(sFydwa1);
asFhLow=abs(sFhLow); %Compute absolute value of Spectrum H
asFhLow1=abs(sFhLow1);
%*********************************************************************
%**************************PLOTS**************************************
%*********************************************************************
figure
plot(txdwave,xdwave) %Plot input signal in time
grid %Set a grid
xlabel('Time in Seconds') %Label the time axis
ylabel('Magnitude') %Label the magnitude axis
title('Input Signal xdwave(t)') %Place the title name
%*********************************************************************
figure
plot(tydwave,ydwave1) %Plot output signal in time
grid %Set a grid
xlabel('Time in Seconds') %Label the time axis
ylabel('Magnitude') %Label the magnitude axis
title('Output (FILTERED INPUT)Signal ydwave(t)') %Place the title name
%*********************************************************************
figure
plot(tfilter,hLowpass) %Plot impulse response in time
grid %Set a grid
xlabel('Time in Seconds') %Label the time axis
ylabel('Magnitude') %Label the the magnitude axis
title('Impulse Response of Low Pass Filter hLow(t)') %Place the title name
%*********************************************************************
figure
plot(fxdwave,asFxdw) %Plot input signal's spectrum
grid %Set a grid
xlabel('Frequency in Hertzs') %Label the frequency axis
ylabel('Magnitude') %Label the magnitude axis
title('Spectrum of Input xdwave') %Place the title name
%*********************************************************************
figure
plot(fydwave,asFydw1) %Plot output signal's spectrum
grid %Set a grid
xlabel('Frequency in Hertzs') %Label the frequency axis
ylabel('Magnitude') %Label the magnitude axis
title('Spectrum of Output (FILTERED SIGNAL) ydwave') %Place the title name
%*********************************************************************
figure
plot(fhLow,asFhLow1) %Plot output signal's spectrum
grid %Set a grid
xlabel('Frequency in Hertzs') %Label the frequency axis
ylabel('Magnitude') %Label the magnitude axis
title('Magnitude of Frequency Response HLow') %Place the title name
%*********************************************************************
%**************************SOUNDS*************************************
%*********************************************************************
sound(xdwave,Fs) %Listen to input signal xdwave
pause(3)
sound(ydwave,Fs) %Listen to output signal ydwave
pause(3)
sound(ydwave1,Fs)