Tags: allformat, andsettings, are-u, clear, desktop, dimensions, documents, graph, longx, matlab, matrix, minus, nbitswavread, programming, representation, roar1, sound, wav

Minus Matrix dimensions must agree

On Programmer » Matlab

4,572 words with 0 Comments; publish: Tue, 29 Apr 2008 16:18:00 GMT; (20093.75, « »)

clear all

format long

[x, fs, nbits]=wavread('C:\Documents and

Settings\are-u\Desktop\roar1.wav');

sound(x,fs);

%graph representation of the original audio in time domain

t=0:1/fs:(length(x)-1)/fs;

figure;

plot(t,x);

title(' original audio in time domain');

ylabel('amplitude');

xlabel('length(in seconds)');

hold on;

%fragment segmentation of the audio signal

len_frame=floor(0.012*fs);

format long

num_frame=floor(length(x)/len_frame);

for i=1:num_frame

xf((i-1)*len_frame+1:i*len_frame)=fft(x((i-1)*len_frame+1:i*len_frame)

);

end

%graph representation of audio signal in frequency domain

figure;

plot(abs(xf));

title('Audio Signal in Frequency Domain');

ylabel('Magnitude');

xlabel('Frequency (Hz)');

%hz to bark scale

FFTlength=512; %FFT length, naturally

f=[1:FFTlength/2]*(fs/FFTlength); %array of Hz corresponding to

bins

b=hz2bark_scale(f);

%scale function hz2bark_scale-array

%Bark

%corresponding to bins

%get absolute threshold hearing

ATH=3.64.*(f./1000).^(-.8)-6.5.*exp(-0.6.*(f./1000-3.3).^2)+0.01*(f./1

000).^4;

figure;

subplot(2,1,1);

plot(f,ATH);

xlabel('frequency (Hz)');

ylabel(' SPL (db)')

title('Absolute threshold of hearing (Hz Scale)');

subplot(2,1,2);

plot(b,ATH);

xlabel('frequency [Bark]');

ylabel('SPL [dB]')

title('Absolute Threshold of hearing (Bark scale)');

%obtain masking threshold

%step 1:get power density spectrum

powernormalizationconstant=90.302;

power=psd(x, FFTlength, powernormalizationconstant);

%only need the first half since signal is real

power=power(1:FFTlength/2);

figure;

subplot(2,1,1);

plot(f,power);

hold on;

plot(f, power);

hold on;

plot(f,ATH,'r--');

xlabel('Frequency (Hz)');

ylabel('Magnitude');

title(' Power Density Spectrum of roar1.wav');

subplot(2,1,2);

plot(b,power);

hold on;

plot(b,ATH,'r--');

xlabel('Frequency (Bark)');

ylabel('Magnitude');

title(' Power Density Spectrum of roar1.wav');

%step 2:find tones

tone_psd=find_tones(power);

figure;

toneloc=find(tone_psd);

subplot(2,1,1);

stem(f(toneloc), tone_psd(toneloc), 'x');

hold on;

plot(f, power, 'g');

plot(f, ATH,'r--');

xlabel(' Frequency (Hz)');

ylabel('Magnitude');

title('Tone Maskers');

subplot(2,1,2);

stem(b(toneloc), tone_psd(toneloc), 'x');

hold on;

plot(b, power,'g');

plot(b, ATH,'r--');

xlabel('Frequency (Bark)');

ylabel('Magnitude');

title('Tone Maskers');

% step 3: find noise maskers within critical band

noise_psd=zeros(1,length(tone_psd));

lowbin=1;

highbin=max(find(b<1));

% reminder of critical bands can be done with loop

for band = 1:24,

[noise_psd_at_loc, loc] = noise_masker(power, tone_psd, lowbin,

highbin); % call function

%noise_masker

if (loc ~= -1)

noise_psd(floor(loc))=noise_psd_at_loc;

end

lowbin=highbin;

highbin=max(find(b<(band+1)));

end

figure;

noiseloc=find(noise_psd);

subplot(2,1,1);

stem(f(noiseloc), noise_psd(noiseloc), 'o');

hold on;

plot(f, power, 'b');

plot(f, ATH, 'r--');

xlabel('Frequency (Hz)');

ylabel(' Magnitude');

title('Noise Maskers');

subplot(2,1,2);

stem(b(noiseloc), noise_psd(noiseloc), 'o');

hold on;

plot(b, power, 'b');

plot(b, ATH, 'r--');

xlabel('Frequency (Bark)');

ylabel('Magnitude');

title('Noise Maskers');

%Remove maskers that are near each other

[tone_psd, noise_psd]=check_maskers(tone_psd, noise_psd, ATH, b);

%call function chack_masker

figure;

toneloc=find(tone_psd);

subplot(2,1,1);

stem(f(toneloc), tone_psd(toneloc), 'x');

hold on;

plot(f, power,'b');

plot(f,ATH,'r--');

xlabel('Frequency (Hz)');

ylabel('Magnitude');

title('Checked Tone Maskers');

subplot(2,1,2);

stem(b(toneloc), tone_psd(toneloc)

All Comments

Leave a comment...

  • 0 Comments