From: yomguy Date: Tue, 15 Apr 2008 11:54:59 +0000 (+0000) Subject: * get the right scale for frequency X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=34cf5755f5abe0848030028b1868cf78c4f2fcfc;p=cnaq.git * get the right scale for frequency * get the harmonic levels git-svn-id: http://svn.parisson.org/svn/CNAQ/trunk@182 5fc3e0e6-29bc-4d03-b52b-c088cb822bde --- diff --git a/tools/spectro2hd.m b/tools/spectro2hd.m index c3fd69b..6ae867b 100644 --- a/tools/spectro2hd.m +++ b/tools/spectro2hd.m @@ -3,7 +3,7 @@ function [S, f, t, f_1, h] = spectro2hd(s, f_s, f_min, f_max, n_harm) ncmap = 128; % number of points for colormap step = 10; % spectral slice period (ms) % step_length = fix(5*Fs/1000); - window = 50; % filter window (ms) + window = 250; % filter window (ms) % window = fix(40*Fs/1000); noise_floor = -60; % (dB) n_harm = 4; @@ -12,9 +12,9 @@ function [S, f, t, f_1, h] = spectro2hd(s, f_s, f_min, f_max, n_harm) S = 20*log10(S); colormap(jet(ncmap)); - size(t) - size(f) - size(S) +% size(t) +% size(f) +% size(S) t_0 = t(1); t_n = t(length(t)); f_0 = f(1); @@ -23,15 +23,17 @@ function [S, f, t, f_1, h] = spectro2hd(s, f_s, f_min, f_max, n_harm) S=flipud(S); f=flipud(f'); % - figure(1) + figure(1); % img = imagesc(t, f, S); - - mesh(t, f, S); + mesh(t, f, S); view([0,90]); shading interp; colorbar; axis([t_0 t_n f_0 f_n]); set(gca,'YScale','log'); + xlabel('Time (s)'); + ylabel('Frequency (Hz)'); + title(['Spectrogram (dB normalized)']); for t_i=1:length(t) f_1(t_i)=f_0*exp((t(t_i)/t_n)*log(f_n/f_0)); @@ -42,13 +44,22 @@ function [S, f, t, f_1, h] = spectro2hd(s, f_s, f_min, f_max, n_harm) end end - figure(2) - semilogx(f_1,h(1,:),'k') - hold on - semilogx(f_1,h(2,:),'r') - semilogx(f_1,h(3,:),'b') - semilogx(f_1,h(4,:),'g') - + colors = ['k';'r';'b';'g';'m';'c';'y']; + figure(2); + hold on; + leg = []; + for i=1:n_harm + semilogx(f_1,h(i,:),colors(i)); + leg = [leg;['Harmonic ' num2str(i)]]; + end + axis([f_0 f_n -120 0]); + set(gca,'XScale','log'); + xlabel('Frequency (Hz)'); + ylabel('Amplitude (dB)'); + title(['Modulus of the harmonic levels']); + legend(leg); + grid on; + % pcolor(abs(S)); % colorbar; diff --git a/tools/spectrogram.m b/tools/spectrogram.m index fd02d8b..3899cbf 100644 --- a/tools/spectrogram.m +++ b/tools/spectrogram.m @@ -101,6 +101,7 @@ function [S, f, t] = spectrogram(x, Fs, window, step, minF, maxF, shape, minE) %% generate window from duration and shape function name win_n = fix(window*Fs/1000); + if shape(length(shape)) == ')' shape = sprintf(shape, win_n); else @@ -140,7 +141,7 @@ function [S, f, t] = spectrogram(x, Fs, window, step, minF, maxF, shape, minE) S = max(S, 10^(minE/10)); % clip below minF dB. S = min(S, 10^(maxE/10)); % clip above maxF dB. - f = [minF:nF]*Fs/fft_n; + f = [minF:Fs/fft_n:maxF]; t = offset/Fs; % if nargout==0 % imagesc(f,t,20*log10(flipud(S)));