Facing error in generalizing hamming window.
3 views (last 30 days)
Show older comments
%Reading the audio
y=audioread('speech.wav');
%sound(y);
subplot(2,3,1);
plot(y);
xlabel('Samples');
ylabel('Magnitude');
title('Original speech signal');
%Adding noise
x=awgn(y,5);
z=y+x;
z=z / max(abs(z));
%sound(z);
subplot(2,3,2);
plot(z);
xlabel('Samples');
ylabel('Magnitude');
title('Noise added to speech signal');
% Framing
f_duration = 0.025;
fs=8000;
f_size = (f_duration.*fs);
n = length(y);
n_f = floor(n/f_size); %no. of frames
temp = 0;
for i = 1 : n_f
frames(i,:) = z(temp + 1 : temp + f_size);
window=hamming(200);
window_framing(i,:)=frames(i,:).*window;
temp = temp + f_size;
end
I am trying to generalize the code for hamming windowing for every frame. But it is giving me "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side." this error. Please resolve my query.
0 Comments
Answers (1)
Soumya
on 24 Jun 2025
The ‘hamming(200)’ function returns a column vector of size ‘200×1’, whereas ‘frames(i,:)' is a row vector of size ‘1×200’ When element-wise multiplication is performed between a row vector and a column vector, it produces a ‘200×200’ matrix instead of a ‘1×200’ vector. This causes a size mismatch while assigning the result to ‘window_framing(i,:)' who expects a row vector.
To resolve the issue, the Hamming window should be transposed so that it becomes a row vector:
window = hamming(200)';
This ensures both vectors are the same size, and the multiplication operates elementwise as intended.
Please refer to the following documentation to get more information on the array operations:
I hope this helps!
0 Comments
See Also
Categories
Find more on Hamming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!