trying to make frequency spectra with OCTAVE

64 views Asked by At

Pls help, whenever i try to call the function grabacion, this error occurs: error: horizontal dimensions mismatch (32768x32768 vs 1x1) i really dont know anything about Octave, my teacher sent me this code and its not working, and he wont help at all. i need to get the energy density and frecuency spectra of an audio

function grabacion(fmax,Amax)
%
[x, rate] = audioread('prueba.wav');   
%   
%fs=44100;             % frecuencia de muestreo [muestras/segundo]
%ts=1/rate;              % tiempo de muestreo [segundos/muestras]
nsample = size(x, 1);   % [muestras]
nsample = pow2(nextpow2(nsample));  
x=[x;zeros(nsample - length(x)),1];  %genera un tamaño potencia de 2
%
%eje de frecuencias
dur = nsample / rate;  %duraci\'on [seg]
fs = 1 / rate;      %tasa de muestreo [seg]
t = 0:fs:dur;       %eje de tiempo [seg]
tam = length(t);    
f = (rate/2) * (1:tam/2) / (tam/2); %eje frecuencia [Hz]
N_min = round(nsample * 20 / rate) + 1;
N_max = round(nsample * fmax / rate) + 1;
f = f(N_min:N_max);
%
x = x .* hanning(length(x));
fftx = abs(fft(x));
fftx = fftx(N_min:N_max);
l = N_max - N_min + 1;
fft_x = 20 * log10(fftx);   %unidad en dB
%
% Espectro de densidad de energía  
figure;
subplot(2,1,1)
plot(f, fft_x', 'linewidth', 2);
set(gca, 'linewidth', 2, 'fontsize', 14);
axis([20 fmax 0 Amax]);
title(['Densidad Espectral de Energía'] );
xlabel(['Frecuencia [Hz]']);
ylabel(['Amplitud [dB]']);
grid;
%size(t)
nx=size(x,1);
subplot(2,1,2)
plot(t(1:nx),x', 'linewidth', 2);
set(gca, 'linewidth', 2, 'fontsize', 14);
%axis([20 fmax 0 Amax]);
title(['función en el tiempo [seg]',] );
xlabel(['Tiempo [seg]']);
ylabel(['Amplitud [V]']);
grid;
endfunction  
0

There are 0 answers