Effacer les filtres
Effacer les filtres

How can I divide a signal into blocks?

7 vues (au cours des 30 derniers jours)
zayed
zayed le 11 Déc 2011
I have a noise signal and I want -for some integer K- to break the signal into blocks of K samples, such that the first N samples make up the first block, the next K samples make up the second block, and so on,as below.I want to know if this algorithm correct or not :
x = radar_noise; % input signal
K = 1000; % K CAPITAL is Block Size
L = length(x) - mod(length(x),K); % only full blocks
zk = reshape(x(1:L), K, []);
%M=zeros(K,K); % M ZEROS covariance matrix L*L
M=[];
for i=1:size(zk,1) % LOOP covariance matrix calculation
Mz=zk(i,:)*zk(i,:)'; %
M=M+Mz;
end
M=M/K;

Réponse acceptée

Walter Roberson
Walter Roberson le 11 Déc 2011
x = radar_noise; % input signal
K = 1000; % K CAPITAL is Block Size
L = length(x) - mod(length(x),K); % only full blocks
zk = reshape(x(1:L), K, []);
This will create zk with each block going down a columns, as you have in your existing code.
It appears to me that in your existing code, once calculate K and L, you then immediately use them with their opposite purposes, using K as if it the number of blocks and using L as if it is a block size.
  6 commentaires
Walter Roberson
Walter Roberson le 11 Déc 2011
You are still confusing block size and number of blocks. zk() has blocks running down the columns, and since you defined the size of the block as being K, size(zk,1) is going to be K. Your vector zk(:,i) is then going to be K by 1, so its conjugate transpose zk(:,i)' would be 1 by K, and the matrix multiplication of (K by 1) by (1 by K) will give you a K by K output. You are then trying to add that K x K output to an array that you defined as L x L.
I am not at all sure that you are calculating your covariance matrices the way you want, and I do not know why you would sum them, but that is a different matter.
zayed
zayed le 11 Déc 2011
I have edited the code ,and it's run ok,but M is 1000*1000 with the same value (1.1180e+001) in all the matrix which is wrong.I don't know why.how can i get reasonable output.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 11 Déc 2011
What do you want to do with each block? If you want each block to just be a row in a new 2D matrix, simply call
zk = reshape(x, [K, L]);
  2 commentaires
Walter Roberson
Walter Roberson le 11 Déc 2011
The floor() in the definition of L shows us that he does not expect that x is necessarily an exact multiple of K in length; in that situation, the plain resize() would fail as K*L might not be length(x)
zayed
zayed le 11 Déc 2011
I want make a matrix out of our signal with one block of the signal per column.But first need to discard all samples beyond the first block_size*number_of_blocks samples of the input signal. reshape this shorter signal into a matrix with block_size rows and number_of_blocks columns.Also assign the output of reshape to something!

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by