Asked by Rusmaya Luthfina
on 21 Dec 2011

hi all,

i've 2second audio signal, i want to divide it into 20 frames and each frame is 100ms length.

for i = 1:100:2000 %do process end

did i write the right code? or is there any other way to divide it? really need ur help...

thank u

*No products are associated with this question.*

Answer by Naz
on 21 Dec 2011

Accepted answer

If you know for sure that your signal is 2 seconds long, then the sampling frequency can be found from dt*N=2, where dt=1/fs is sampling period and N is number of samples, which you don't need.

IF you already have an array of sampled signal, it has particular length (number of samples). In addition, you know that the 'duration' of that array is 2 seconds, so, you must break your array onto 2000ms/100ms=20 pieces:

x=[your array of N samples]; n=round(length(x)/20); %find how many samples will each frame contain P=zeros(n,20); %preallocate the matrix for 20 colums of Nsamples/20 in each

for k=0:19 P(:,k+1)=x(1+n*k:n*(k+1)); end

Not sure if this works, but the idea is there. There could be an easier way to break your signals into frames: just know that the array of samples must be broken onto 20 pieces.

Rusmaya Luthfina
on 22 Dec 2011

thx for your answer, i get the idea of your answer, actually i'm extracting audio features in time domain such as average energy, zcr, and silence ratio. i've implemented ur idea but with simple code i understand.. anyway,, thank u so much for ur answer..

__maya__

Answer by Walter Roberson
on 21 Dec 2011

That code is probably not correct, as it does not take in to account the sampling frequency and instead implicitly assumes that the data was sampled at 1 ms per sample which would be a sampling rate of 1000 Hz.

When Fs designates your sampling frequency, 100 ms would be Fs/10 . That will probably be an integer, but better would not be to assume that.

But being lax for a moment,

windowsize = Fs/10; trailingsamples = mod(length(YourSignal), windowsize); sampleframes = reshape( YourSignal(1:end-trailingsamples), windowsize, []);

Now the columns of sampleframes will be the individual frames, such as sampleframes(:,3) for the third frame.

prasanna patil
on 12 Mar 2013

sir, i am getting trouble in last line of ur code.

sampleframes = reshape( YourSignal(1:end-trailingsamples), windowsize, []);

the error is ->> Error using reshape & Size arguments must be real integers.

and then i tried

>>sampleframes = reshape(x(1:end-trailingsamples), windowsize, [:,3]);

then i got this error.

Error: Unexpected MATLAB operator.

can u plz help me sir?

Walter Roberson
on 12 Mar 2013

Answer by saibaba
on 6 Apr 2013

i am doing a project on "speech enhancement" am also using the same process but am not understanding it clearly what am i using u use round for the length of the signal but i use the floor does it make any difference. i want to post my code can anyone explain what is happening in it......

actually my aim is to reduce the noise using kalman filter and i got the output too... i want how its happening inner view of it... can anyone explain

matlab code:

[x,Fs4,bits4]=wavread('DEKF_white_stat_7db__noisy.wav'); xx=x; N=256; % frame length m=N/2; % of each frame of the moving distance lenth=length(x); % the length of the input signal count=floor(lenth/m)-2; x=x/max(abs(x)); t=(0:length(x)-1)/Fs4; s=1; p=11; a=zeros(1,p); w=hamming(N); y_temp=0; F=zeros(11,11); F(1,2)=1; F(2,3)=1; F(3,4)=1; F(4,5)=1; F(5,6)=1; F(6,7)=1; F(7,8)=1; F(8,9)=1; F(9,10)=1; F(10,11)=1; H=zeros(1,p); S0=zeros(p,1); P0=zeros(p); S=zeros(p); H(11)=1; s=zeros(N,1); G=H'; P=zeros(p); y_temp=cov(x(1:7680)); x_frame=zeros(256,1); x_frame1=zeros(256,1); T=zeros(lenth,1); for r=1:count x_frame=x((r-1)*m+1:(r+1)*m); if r==1 [a,VS]=lpc(x_frame(:),p); else [a,VS]=lpc(T((r-2)*m+1:(r-2)*m+256),p); end if (VS-y_temp>0) VS=VS-y_temp; else VS=0.0005; end

F(p,:)=-1*a(p+1:-1:2); if r==1 S=[zeros(p,1)]; %state vector P0=[zeros(p,p)]; %error covatiance else

P0=P; end

for j=1:256 if(j==1) S=F*S0; Pn=F*P*F'+G*VS*G'; else S=F*S; Pn=F*P*F'+G*VS*G'; end K=Pn*H'*(y_temp+H*P*H').^(-1); P=(eye(p)-K*H)*Pn; S=S+K*[x_frame(j)-H*S]; T((r-1)*m+j)=H*S; end

% End cycle calculation LPC parameters

end rt=137.78/128; figure(1); subplot(2,1,1); plot(t,x); xlabel('Time'); ylabel('Amplitude'); title('Original'); sound(x,Fs4,bits4); x1=T./rt; wavwrite(x1,Fs4,bits4,'kalman_denosed.wav'); [x1,Fs4,bits4] = wavread('kalman_denosed.wav'); x1=x1/max(abs(x1)); t=(0:length(x1)-1)/Fs4; subplot(2,1,2); plot(t,x1); xlabel('Time'); ylabel('Amplitude'); title('Denoised Kalman'); display('done'); sound(x1,Fs4,bits4);

sr=sum(x.^2) %Speech Power nro=sum((x-x1).^2) %Output Noise Power % nri=sum((speech-x).^2); %Input Noise Power % SNRi=10*log10(sr/nri) %Input SNR SNRo=10*log10(sr/nro) %Output SNR

Opportunities for recent engineering grads.

## 0 Comments