Facing error in generalizing hamming window.

조회 수: 3 (최근 30일)
Jaya Sodhani
Jaya Sodhani 2022년 7월 7일
답변: Soumya 2025년 6월 24일
%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.

답변 (1개)

Soumya
Soumya 2025년 6월 24일
Hi @Jaya Sodhani,
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!

카테고리

Help CenterFile Exchange에서 Hamming에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by