divide audio signal into frames
148 views (last 30 days)
Naz on 21 Dec 2011
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
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.
More Answers (2)
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.
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
[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
S=[zeros(p,1)]; %state vector
P0=[zeros(p,p)]; %error covatiance
% 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