]> git.parisson.com Git - cnaq.git/commitdiff
* get the right scale for frequency
authoryomguy <yomguy@5fc3e0e6-29bc-4d03-b52b-c088cb822bde>
Tue, 15 Apr 2008 11:54:59 +0000 (11:54 +0000)
committeryomguy <yomguy@5fc3e0e6-29bc-4d03-b52b-c088cb822bde>
Tue, 15 Apr 2008 11:54:59 +0000 (11:54 +0000)
* get the harmonic levels

git-svn-id: http://svn.parisson.org/svn/CNAQ/trunk@182 5fc3e0e6-29bc-4d03-b52b-c088cb822bde

tools/spectro2hd.m
tools/spectrogram.m

index c3fd69be7e418d793a80775072012583ab9b8857..6ae867b593131ba58d97cd4ad3431eb1cac08ef4 100644 (file)
@@ -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;
index fd02d8b7c63edd97e6bb311122b48ec23588c940..3899cbf688aac6001249b8320266d1b4a22811fd 100644 (file)
@@ -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)));