a b/spectrogram_analysis.m
1
[file, path] = uigetfile('*.wav', 'Select a wave file');
2
nameoffile = fullfile(path,file);
3
4
[signal,fs] = audioread(nameoffile);
5
signal = signal(:,1);
6
7
velocity = 1; %Average Peak Systolic Velocity, '1' : yes | '0' : no
8
9
type = 'velocity';      %'freq' or 'velocity' on y-axis
10
11
time = 5;               %plot for specific time period (in seconds)
12
t=1:fix(time*fs);
13
%signal=signal(t);
14
15
frame = 21.3;             %size for spectrogram (ms)
16
17
s_length = length(signal);
18
sampleTime = ( 1:s_length )/fs;
19
frameSize = fix(frame*0.001*fs);
20
21
figure()
22
23
if ( strcmp(type, 'freq') )
24
        [B,f,T] = spectrogram(signal,hanning(frameSize),round(frameSize/2),frameSize*2,fs);
25
        B = 20*log10(abs(B));
26
        imagesc(T,f,B);axis xy;colorbar;ylim([0 5000]);caxis([-25 25]);%datacursormode on;
27
        t=colormap(gray);
28
        colormap(1-t);
29
        h = zoom;
30
        h.motion = 'horizontal';
31
        h.enable = 'on';
32
        xlabel('Time (s)');ylabel('Frequency (Hz)'); 
33
end
34
35
if ( strcmp(type, 'velocity') )
36
        [B,f,T] = spectrogram(signal,hann(frameSize),round(frameSize/2),frameSize*2,fs);
37
        B = 20*log10(abs(B));
38
        v = f*0.040526;
39
        imagesc(T,v,B);axis xy;ylim([0 100]);colorbar;caxis([-25 25]);
40
        t=colormap(gray);
41
        colormap(1-t);
42
        g = zoom;
43
        g.motion = 'horizontal';
44
        g.enable = 'on';
45
        xlabel('Time (s)');ylabel('Velocity (cm/s)');
46
end
47
48
set(gcf, 'Position', get(0,'Screensize'));
49
50
if velocity
51
    
52
[a,b] = find(B>-5);
53
vel = v(a);
54
Time = T(b);
55
56
[p,loc] = findpeaks(vel,'MinPeakHeight',0.7*max(vel),'MinPeakDistance',500);
57
58
figure()
59
plot(Time,vel,Time(loc),p,'o');xlabel('Time (s)');ylabel('velocity (cm/s)');ylim([0 0.040526*4000]);
60
set(gcf, 'Position', get(0,'Screensize'));
61
62
max_velocity = max(p);
63
Velocity = mean(p);
64
65
fprintf('\nMax Systolic Peak Velocity     = %.2f cm/s\n',max_velocity);
66
fprintf('\nAverage Systolic Peak Velocity = %.2f cm/s\n\n',Velocity);
67
68
end