Home > SUpDEq-v5.0.0 > evaluation > supdeq_plotTF.m

supdeq_plotTF

PURPOSE ^

% SUpDEq - Spatial Upsampling by Directional Equalization

SYNOPSIS ^

function supdeq_plotTF( tf1, tf2, fs, singleSided)

DESCRIPTION ^

% SUpDEq - Spatial Upsampling by Directional Equalization

 function supdeq_plotTF( tf1, tf2, fs, singleSided)

 This function plots magnitude, phase, and group delay 
 of one or two transfer functions

 Output:
 Figure with 3 subplots

 Input:
 tf1           - Transfer Function 1 - For example HRTF left
 tf2           - Transfer Function 2 - For example HRTF right
 fs            - Sampling rate
                 Default: 48000
 singleSided   - Boolen with true/false - 
                 Defines if spectrum is single or both sided
                 Default: true - single sided spectrum only  

 Dependencies: -

 (C) 2018 by JMA, Johannes M. Arend
             TH Köln - University of Applied Sciences
             Institute of Communications Engineering
             Department of Acoustics and Audio Signal Processing

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% SUpDEq - Spatial Upsampling by Directional Equalization
0002 %
0003 % function supdeq_plotTF( tf1, tf2, fs, singleSided)
0004 %
0005 % This function plots magnitude, phase, and group delay
0006 % of one or two transfer functions
0007 %
0008 % Output:
0009 % Figure with 3 subplots
0010 %
0011 % Input:
0012 % tf1           - Transfer Function 1 - For example HRTF left
0013 % tf2           - Transfer Function 2 - For example HRTF right
0014 % fs            - Sampling rate
0015 %                 Default: 48000
0016 % singleSided   - Boolen with true/false -
0017 %                 Defines if spectrum is single or both sided
0018 %                 Default: true - single sided spectrum only
0019 %
0020 % Dependencies: -
0021 %
0022 % (C) 2018 by JMA, Johannes M. Arend
0023 %             TH Köln - University of Applied Sciences
0024 %             Institute of Communications Engineering
0025 %             Department of Acoustics and Audio Signal Processing
0026 
0027 %%
0028 function supdeq_plotTF( tf1, tf2, fs, singleSided)
0029 
0030 plotTF2 = true;
0031 if nargin < 2
0032     plotTF2 = false;
0033     tf2 = [];
0034 end
0035 
0036 if nargin < 3 || isempty(fs)
0037     fs = 48000;
0038 end
0039 
0040 if nargin < 4 || isempty(singleSided)
0041     singleSided = true;
0042 end
0043 
0044 %Check size of tf
0045 if size(tf1,2) > size(tf1,1)
0046     tf1 = tf1';
0047 end
0048 
0049 if plotTF2
0050     if size(tf2,2) > size(tf2,1)
0051         tf2 = tf2';
0052     end
0053 end
0054 
0055 %% Get phase and group delay
0056 
0057 NFFTtf1 = length(tf1);
0058 if plotTF2
0059     NFFTtf2 = length(tf2);
0060 end
0061 
0062 if singleSided
0063     fVec_tf1    = linspace(0,fs/2,NFFTtf1);
0064     fVec2_tf1   = linspace(0,fs/2,NFFTtf1-1);
0065     if plotTF2
0066         fVec_tf2    = linspace(0,fs/2,NFFTtf2);
0067         fVec2_tf2   = linspace(0,fs/2,NFFTtf2-1);
0068     end
0069 else
0070     fVec_tf1    = linspace(0,fs,NFFTtf1);
0071     fVec2_tf1   = linspace(0,fs,NFFTtf1-1);
0072     if plotTF2
0073         fVec_tf2    = linspace(0,fs,NFFTtf2);
0074         fVec2_tf2   = linspace(0,fs,NFFTtf2-1);
0075     end
0076 end
0077     
0078 phitf1  = unwrap(angle(tf1));
0079 if plotTF2
0080     phitf2  = unwrap(angle(tf2));
0081 end
0082 if singleSided
0083     grtf1   = -diff(phitf1) / (2*pi) * NFFTtf1/(fs/2);
0084     if plotTF2
0085         grtf2   = -diff(phitf2) / (2*pi) * NFFTtf2/(fs/2);
0086     end
0087 else
0088     grtf1   = -diff(phitf1) / (2*pi) * NFFTtf1/fs;
0089     if plotTF2
0090         grtf2   = -diff(phitf2) / (2*pi) * NFFTtf2/fs;
0091     end
0092 end
0093 
0094 %% Plot
0095 
0096 figure;
0097 set(gcf,'Color','w');
0098 linewidth = 1.1;
0099 
0100 subplot(2,2,[1,2])
0101 semilogx(fVec_tf1,20*log10(abs(tf1)),'k','Linewidth',linewidth);
0102 if plotTF2
0103     hold on;
0104     semilogx(fVec_tf2,20*log10(abs(tf2)),'r','Linewidth',linewidth);
0105     legend('TF1','TF2','Location','NorthWest');
0106 end
0107 xlim([20, fs/2]);
0108 title('Magnitude Spectrum');
0109 xlabel('Frequency in Hz');
0110 ylabel('Magnitude in dB');
0111 grid on;
0112 
0113 subplot(2,2,3)
0114 semilogx(fVec_tf1,phitf1,'k','Linewidth',linewidth);
0115 if plotTF2
0116     hold on;
0117     semilogx(fVec_tf1,phitf1,'r','Linewidth',linewidth);
0118 end
0119 xlim([20, fs/2]);
0120 xlabel('Frequency in Hz');
0121 ylabel('Phase in degrees');
0122 title('Phase');
0123 grid on;
0124 
0125 subplot(2,2,4)
0126 semilogx(fVec2_tf1,grtf1*1000,'k','Linewidth',linewidth);
0127 if plotTF2
0128     hold on;
0129     semilogx(fVec2_tf2,grtf2*1000,'r','Linewidth',linewidth);
0130 end
0131 xlim([20, fs/2]);
0132 title('Group Delay');
0133 xlabel('Frequency in Hz');
0134 ylabel('Group Delay in ms');
0135 grid on;
0136 
0137 end
0138

Generated on Wed 30-Nov-2022 14:15:00 by m2html © 2005