itaAudioAnalyticRational.m 8.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
classdef itaAudioAnalyticRational < itaAudioAnalyticSuper
    %ITAAUDIOAnalytic - super class for analytic audio data files
    %
    %
    % These objects can be used for all data with is directly convertable
    % between frequency domain and time domain. Equally spaced samples or
    % bins.
    %
    % itaAudio Properties:
    %   samplingRate
    %
    %   Reference page in Help browser
    %        <a href="matlab:doc itaAudio">doc itaAudio</a>
    
    % <ITA-Toolbox>
    % This file is part of the application PoleZeroProny for the ITA-Toolbox. All rights reserved.
    % You can find the license for this m-file in the application folder.
    % </ITA-Toolbox>
    
    % Author: Pascal Dietrich - pdi@akustik.rwth-aachen.de
    
    properties(Access = private, Hidden = true)
        mAnalyticData = itaPZ;
    end
    
    properties(Dependent = true, Hidden = false)
        analyticData;
    end
    
    properties
       timeDomain = false; 
    end
    
    methods
        
        function this = itaAudioAnalyticRational(varargin)
            % itaAudio - generates itaAudio Object
            %
            % itaAudio() - empty itaAudio object
            %    example: a = itaAudio;
            %
            % itaAudio(domainData, sr, domain) - generates itaAudio
            %        with the data specified in domainData, sampling rate
            %        sr and in the domain defined with the string domain
            %    example:      audioObj = itaAudio(timeData, 44100, 'time')
            this.domain     = 'freq';
            this.signalType = 'energy'; %this is most obvious
            if nargin == 1
                token = varargin{1};
                if isa(token,'itaAudioAnalyticSuper');
                    this = token;
                elseif isa(token,'itaPZ')
                    this.analyticData = token;
                    for idx = 1:numel(token)
                        this.channelUnits{idx} = token(idx).unit.unit;
                        this.channelNames{idx} = token(idx).comment;
                        
                    end
                elseif isstruct(token)
                    error('itaAudioAnalyticRational::this type is not allowed!')
                else
                end
            end
            
        end
66
        function varargout = plot_single_components(this,varargin)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            % plot all resonators as separate channels
            x = this;
            
            newanalyticData = this.analyticData(1);
            idxx            = find(newanalyticData.f >= 0);
            newanalyticData = newanalyticData.ch(idxx); %#ok<FNDSB>
            %             newanalyticData = newanalyticData.sort('freq');
            for idx = 1:length(newanalyticData.f)
                data = newanalyticData.ch(idx);
                x.analyticData(idx) = data;
                mode_decay = (data.T);
                if abs(mode_decay) < 0.01
                    mode_decay = [num2str(mode_decay*1000) 'ms'];
                else
                    mode_decay = [num2str(mode_decay) ''];
                end
                x.channelNames{idx} = [num2str(data.f) 'Hz, ' mode_decay ', ' num2str(round(20*log10(abs(data.C)))) 'dB'];
            end
            %             -6.9 ./ newanalyticData.sigma;
            if nargout == 1
                varargout{1} = x;
            else
89
                x.plot_spk(varargin{:})
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
                clear varargout;
            end
            
        end
        function this = set.analyticData(this,value)
            %             if isa(value,'rfmodel.rational') %cast to itaPZ
            %                 for idx = 1:numel(value)
            %                     valuePZ(idx) = itaPZ(value(idx));
            %                 end
            %             end
            this.mAnalyticData = value;
            this.dimensions    = numel(this.mAnalyticData);
        end
        
        function res = get.analyticData(this)
            res =  this.mAnalyticData;
        end
        
        %% Get/Set Functions - Trick 17 + 4 - overloaded from itaAudio
        function res = ifft(this)
            res = ifft(compile(this)); %make itaAudio first, then transform
        end
        
        function res = merge(this)
            % merge together
            res = this(1,1);
            res.analyticData = repmat(itaPZ,1,numel(this));
            count = 0;
            for idx = 1:size(this,1)
                for jdx = 1:size(this,2)
                    count = count + 1;
                    res.analyticData(count) = this(idx,jdx).analyticData;
                    if ~isempty(this(idx,jdx).channelNames)
                        res.channelNames{count} = this(idx,jdx).channelNames{1};
                    end
                end
            end
        end
        
        function this = mtimes(this,value)
            % multiply
            if isnumeric(value) || isa(value,'itaValue')
                if size(value) ~= size(this)
                    value = repmat(value(1,1),size(this));
                end
                for idx = 1:size(this,1)
                    for jdx = 1:size(this,2)
                        this(idx,jdx).analyticData = this(idx,jdx).analyticData * value(idx,jdx);
                    end
                end
            else
                ita_verbose_info('sorry, mtimes not implemented yet for itaAudioAnalyticRational',0)
            end
            
        end
        
        function res = fft(this)
            % normal fft by going to itaAudio
            res = this.compile; %itaAudio;
            res = fft(res);
        end
        function res = compile(this)
            
            if sum(size(this))>2
                res = ita_AudioAnalyticRationalMatrix2itaAudioMatrix(this);
            else %normal case, no matrix given
                
                res  = itaAudio(this);                
                if this.timeDomain
                    time = zeros(this.nSamples,numel(this.analyticData));
                    for cdx = 1:numel(this.analyticData)
                        time(:,cdx) = this.analyticData(cdx).timeresp(this.timeVector)/this.samplingRate;
                    end
                    res.time = time;

                else %normal freq domain
                    freq = zeros(this.nBins,numel(this.analyticData));
                    for cdx = 1:numel(this.analyticData)
                        freq(:,cdx) = this.analyticData(cdx).freqresp(this.freqVector);
                    end
                    res.freq = freq;
                    
                end
                
                res = ita_metainfo_copy(res,this);
            end
            
        end
    end
    
    %% Hidden Methods
    methods(Hidden = true)
        function this = set_nSamples(this, nSamples)
            this.mNSamples = ita_nSamples(nSamples);
        end
        
        %%
        function this = set_data(this,value)
            this.analyticData = value;
            
            %             % set_data that is called from itaSuper
            %             if this.isTime
            %                 if (rem(size(value,1),2) == 1)
            %                     this.mEvenSamples = false;
            %                 else
            %                     this.mEvenSamples = true;
            %                 end
            %             end
            %             this = set_data@itaSuper(this,value);
        end
        
        function result = get_nBins(this)
            result = this.nSamples2nBins;
        end
        
        function result = get_nSamples(this)
            result = this.mNSamples;
        end
        
        
    end
    
       
    %% Static Methods
    methods(Static)
        function this = loadobj(sObj)
            ita_verbose_info('loadobj:itaAudioAnalyticRational',0)
            
            sObj = rmfield(sObj,{'classrevision', 'classname'}); % Remove these fields cause no more needed, but we could use them for special case handling (e.g. old versions)
            analyticData = sObj.data;
            sObj.data = zeros(1,numel(analyticData));
            this = itaAudio(sObj); % Just call constructor, he will take care
            this = itaAudioAnalyticRational(this);
            this.analyticData = analyticData;
            switch this.dataType(1:3)
                case {'int'}
                    this.dataTypeOutput = 'single'; %Save solution
                otherwise
                    this.dataTypeOutput = this.dataType;
            end
        end
    end
end