image thumbnail

Spectrogram, STFT, with varied kinds of Plots

by

 

Plots STFT using line, Stem, Surface, Image. STFT calculation done using in built function

spectrogram_multiplot(plot_type, data, varargin)
function [S F T P] = spectrogram_multiplot(plot_type, data, varargin)
%
%[Function Description]
%This function is wrapper for the built in function spectrogram. It
%provides the option to plot stft in different plot types. For the
%description of each type of plots see the input list
%
%[Input Parameters]
%plot_type - It is a string parameter which takes the following
%            1. 'Line' - Creates one line for each frequency. Time Vs
%            amplitude. Very useful to watch the behavior of a particualar
%            frequency. Caution - Use this only when you are using the 'f'
%            parameter in "spectrogram" or else it might create a large set
%            of lines which are useless to read.
%            2. 'Stem' - Creates a 3D stem plot. x-axis = time, y-axis =
%            frequency, z-axis = amplitude.
%            3. 'Surface' - Creates a 3D surface plot. x and y axis being time
%            and frequency, the height being amplitude.
%            4. 'Image' - Creates a 2D image (Somewhat similar to the built
%            in type)
%            5. 'Default' - Outputs the default figure.
%data - The signal data for spectrogram
%varargin - The inputs for the built in function "Spectrogram" in the same
%order
%
%[Output Parameters]
%Same as the built in spectrogram function
%
%[Author]
%Shreyes

%calculate spectrogram from the standard function
[S F T P] = spectrogram(data, varargin {:});

switch(upper(plot_type))
    case 'LINE'
        figure;
        plot_data = S';
        plot_data = abs(plot_data);
        plot(T,plot_data);
        legend(num2str(F),'Location','Best');
        xlabel('Time');
        ylabel('Amplitude');
        title('Time Vs Amplitude, Each line is one Frequency');
    case 'STEM'
        figure;
        plot_data = abs(S);
        stem3(T,F,plot_data);
        xlabel('Time');
        ylabel('Frequency');
        zlabel('Amplitude');
        title('Spectrogram');
    case 'SURFACE'
        figure;
        plot_data = abs(S);        
        surf(T,F,plot_data);
        colorbar;
        xlabel('Time');
        ylabel('Frequency');
        zlabel('Amplitude');
        title('Spectrogram');   
    case 'IMAGE'
        figure;
        plot_data = abs(S);
        imagesc(T,F,plot_data);
        colorbar;
        xlabel('Time');
        ylabel('Frequency');
        zlabel('Amplitude');
        title('Spectrogram');
    otherwise
        spectrogram(data,varargin {:});
end

Contact us