Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Minus Matrix dimensions must agree

Subject: Minus Matrix dimensions must agree

From: falaah

Date: 18 Feb, 2007 00:02:39

Message: 1 of 1

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)

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us