Error using .* Matrix dimensions must agree.
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to plot spectrogram of audio signal usinf fft using the followinf codes
astft.m
function [ X ] = astft( x,wl )
disp('Overlapping of window is 50%');
disp('1 Rectangular Window, 2 Hamming Window, 3 Hanning Window');
window=input('Enter your choice - ');
L=length(x);
if L<wl
z=wl-L;
x=[x,zeros(1,z)];
end
switch window
case 1
win=ones(1,wl);
case 2
win=hamming(wl)';
case 3
win=hanning(wl)';
otherwise
win=ones(1,wl);
disp('Not a right option, By default rectangular window is taken.');
end
L=length(x);
hop=ceil(wl/2);
if hop<1
hop=wl;
end
i=1; str=1; len=wl; X=[];
while(len<=L || i<2)
if i==1
if len>L
z=len-L;
x=[x,zeros(1,z)];
i=i+1;
end
x1=x(str:len);
*X=[X;fft(x1.*win)];*
str=str+hop; len=str+wl-1;
end
end
figure,subplot(2,1,1)
imagesc(abs(X));
subplot(2,1,2)
surf(abs(X));
end
-------------------------------------------
Example.m
clear, clc, close all
% load a .wav file
[x, fs] = audioread('record.wav'); % get the samples of the .wav file
x = x(:, 1); % get the first channel
xmax = max(abs(x)); % find the maximum abs value
x = x/xmax;
wl=256;
[Y]=astft(x,wl);
Matrix dimension are same then also it is showing error.. 'record.wav' is a short duration audio and length(x)=25600
採用された回答
Henric Rydén
2014 年 6 月 2 日
Transpose win
X=[X ; fft(x1.*win')]
and append x correctly:
x=[x ; zeros(z,1)];
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Time-Frequency Analysis についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!