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

Need help to make zero padding. It says error, have to concatenate the matrix. c

ID: 3764045 • Letter: N

Question

Need help to make zero padding. It says error, have to concatenate the matrix.

clear all

close all
%*******************************************************************
%**************************Input/Output*****************************
%*******************************************************************
[sig,Fs]=audioread('sound1.wav');
save dwave.txt sig -ascii   
load -ascii dwave.txt;
dsiz=length(dwave);
%*******************************************************************
%**************************Parameter Setting************************
%*******************************************************************
xlength=dsiz;
Ts=1/Fs;   
Vdwave=dsiz*Ts;   
Frx=(1/Vdwave);   
txdwave=0:Ts:Vdwave-Ts;
fxdwave=-(Fs/2):Frx:(Fs/2)-Frx;   
wm=(2*(700)/Fs);
wm1=(2*(850)/Fs);
wm2=[wm wm1];
N=floor((2*(.025*dsiz)))+1;   
tfilter=0:Ts:(N-1)*Ts;
xdwave=dwave;   
ylength=(dsiz+N)-1;
tydwave=0:Ts:(ylength-1)*Ts;   
Fry=(1/(ylength*Ts));   
fydwave=-(Fs/2):Fry:(Fs/2)-Fry;
Frh=(1/(N*Ts));   
fhLow=-(Fs/2):Frh:(Fs/2)-Frh;   
%*******************************************************************
%************Signal Filtering Using Linear Convolution**************
%*******************************************************************
hLow=fir1(N-1,wm2,'bandpass');
ydwave=conv(xdwave,hLow);
xpad = [xdwave zeros(1,dsiz)];
ypad = [hLow zeros(1,ylength)];
ccirc = ifft(fft(xpad).*fft(ypad));
diffpcm = [store, diffpcm'];
Fxdwav=fft(xdwave);   
Fydwav=fft(ydwave);   
output=length(ydwave);
FhLow=fft(hLow);
sFxdwa=fftshift(Fxdwav);   

sFydwa=fftshift(Fydwav);

sFhLow=fftshift(FhLow);

asFxdw=abs(sFxdwa);

asFydw=abs(sFydwa);
  
asFhLow=abs(sFhLow);
  
%*********************************************************************
%**************************SPECTROGRAM********************************
figure
spectrogram(xdwave,round(dsiz/400),round(dsiz/948),1985,Fs,'yaxis'),colorbar;
title('Original Signal')
ylim([0 9000])
figure
spectrogram(ydwave,round(output/400),round(output/948),1985,Fs,'yaxis'),colorbar;
title('input Signal with Bandpass')
ylim([0 9000])
figure

%*********************************************************************
%*********************************************************************
figure
plot(txdwave,xdwave)
grid   
xlabel('Time in Seconds')   
ylabel('Magnitude')
title('Input Signal xdwave(t)')
%*********************************************************************
figure
plot(tydwave,ydwave)
grid
xlabel('Time in Seconds')   
ylabel('Magnitude')

title('Output (FILTERED INPUT)Signal ydwave(t)')
%*********************************************************************
%*********************************************************************
figure
plot(tfilter,hLow)
grid
xlabel('Time in Seconds')   
ylabel('Magnitude')
title('Impulse Response of Bandpass Filter hBandpass(t)')
%*********************************************************************
figure
plot(fxdwave,asFxdw)

grid   
xlabel('Frequency in Hertzs')
ylabel('Magnitude')
title('Spectrum of Input xdwave')
%*********************************************************************
figure
plot(fydwave,asFydw)   
grid   
xlabel('Frequency in Hertzs')
ylabel('Magnitude')
title('Spectrum of Output (FILTERED SIGNAL) ydwave')
%*********************************************************************
figure
plot(fhLow,asFhLow)   
grid   
xlabel('Frequency in Hertzs')
ylabel('Magnitude')
title('Magnitude of Frequency Response HBandpass')
%*********************************************************************

%**************************SOUNDS*************************************
%*********************************************************************
sound(xdwave,Fs)
pause(11)
sound(yxdwave,Fs)
pause(11)
sound(ydwave,Fs)   
pause(11)
sound(ydwave1,Fs)

Explanation / Answer

For two vectors, the circular convolution is equal to the inverse DFT of the product of the vectors' DFTs. Knowing the conditions under which linear and circular convolution are equivalent allows you to use the DFT to efficiently compute linear convolutions.

If there is a vector with A points, and the other one with B points, the linear convulation has the length A+B-1

If you want to calculate circular convolution of A and B to be equivalent, pad the vectors with zeros to length at least N + L - 1 before you take the DFT. After you invert the product of the DFTs, retain only the first N + L - 1 elements.

Hope this helps.