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

supdeq_plotIR

PURPOSE ^

% SUpDEq - Spatial Upsampling by Directional Equalization

SYNOPSIS ^

function supdeq_plotIR( ir1, ir2, logIR, fs, FFToversize)

DESCRIPTION ^

% SUpDEq - Spatial Upsampling by Directional Equalization

 function supdeq_plotIR( ir1, ir2, logIR, fs, FFToversize)

 This function plots magnitude, phase, and group delay 
 of one or two impulse responses

 Output:
 Figure with 4 subplots

 Input:
 ir1           - Impulse Response 1 - For example HRIR left
 ir2           - Impulse Response 2 - For example HRIR right
 logIR         - True/False - plot ir logarithmic or linear
                 Default: false
 fs            - Sampling rate
                 Default: 48000
 FFToversize   - Factor to increase FFT resolution. 
                 2^nextpow2(length(ir)) * FFToversize

 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_plotIR( ir1, ir2, logIR, fs, FFToversize)
0004 %
0005 % This function plots magnitude, phase, and group delay
0006 % of one or two impulse responses
0007 %
0008 % Output:
0009 % Figure with 4 subplots
0010 %
0011 % Input:
0012 % ir1           - Impulse Response 1 - For example HRIR left
0013 % ir2           - Impulse Response 2 - For example HRIR right
0014 % logIR         - True/False - plot ir logarithmic or linear
0015 %                 Default: false
0016 % fs            - Sampling rate
0017 %                 Default: 48000
0018 % FFToversize   - Factor to increase FFT resolution.
0019 %                 2^nextpow2(length(ir)) * FFToversize
0020 %
0021 % Dependencies: -
0022 %
0023 % (C) 2018 by JMA, Johannes M. Arend
0024 %             TH Köln - University of Applied Sciences
0025 %             Institute of Communications Engineering
0026 %             Department of Acoustics and Audio Signal Processing
0027 
0028 %%
0029 function supdeq_plotIR( ir1, ir2, logIR, fs, FFToversize)
0030 
0031 plotir2 = true;
0032 if nargin < 2
0033     plotir2 = false;
0034     ir2 = [];
0035 end
0036 
0037 if isempty(ir2)
0038     plotir2 = false;
0039 end
0040 
0041 if nargin < 3 || isempty(logIR)
0042     logIR = false;
0043 end
0044 
0045 if nargin < 4 || isempty(fs)
0046     fs = 48000;
0047 end
0048 
0049 if nargin < 5 || isempty(FFToversize)
0050     FFToversize = 1;
0051 end
0052 
0053 %Check size of ir
0054 if size(ir1,2) > size(ir1,1)
0055     ir1 = ir1';
0056 end
0057 
0058 if plotir2
0059     if size(ir2,2) > size(ir2,1)
0060         ir2 = ir2';
0061     end
0062 end
0063 
0064 %% Get spec, phase, group delay
0065 
0066 NFFT = length(ir1);
0067 if plotir2
0068     if length(ir2) > NFFT
0069         NFFT = length(ir2);
0070     end
0071 end
0072 
0073 NFFT    = (2^nextpow2(NFFT));
0074 if FFToversize > 1
0075     NFFT = NFFT*FFToversize;
0076 end
0077 
0078 fVec    = linspace(0,fs/2,NFFT/2+1);
0079 fVec2   = linspace(0,fs/2,NFFT/2);
0080 tVecir1 = linspace(0, length(ir1)/fs, length(ir1));
0081 if plotir2
0082     tVecir2 = linspace(0, length(ir2)/fs, length(ir2));
0083 end
0084 
0085 specir1 = fft(ir1,NFFT);
0086 specir1 = specir1(1:end/2+1,:);
0087 phiir1  = unwrap(angle(specir1));
0088 grir1   = -diff(phiir1) / (2*pi) * NFFT/fs;
0089 
0090 if plotir2
0091     specir2 = fft(ir2,NFFT);
0092     specir2 = specir2(1:end/2+1,:);
0093     phiir2  = unwrap(angle(specir2));
0094     grir2   = -diff(phiir2) / (2*pi) * NFFT/fs;
0095 end
0096 
0097 %% Plot
0098 
0099 figure;
0100 set(gcf,'Color','w');
0101 linewidth = 1.1;
0102 
0103 subplot(2,2,1)
0104 if logIR
0105     plot(tVecir1,20*log10(abs(ir1)),'k','Linewidth',linewidth);
0106 else
0107     plot(tVecir1,ir1,'k','Linewidth',linewidth);
0108 end
0109 if plotir2
0110     hold on;
0111     if logIR
0112         plot(tVecir2,20*log10(abs(ir2)),'r','Linewidth',linewidth);
0113     else
0114         plot(tVecir2,ir2,'r','Linewidth',linewidth);
0115         legend('IR1','IR2','Location','NorthEast');
0116     end
0117 end
0118 xlabel('Time in s');
0119 if logIR
0120     ylabel('Magnitude in dB');
0121     title('Log Impulse Response');
0122 else
0123     ylabel('Amplitude');
0124     title('Impulse Response');
0125 end
0126 grid on;
0127 
0128 subplot(2,2,2)
0129 semilogx(fVec,20*log10(abs(specir1)),'k','Linewidth',linewidth);
0130 if plotir2
0131     hold on;
0132     semilogx(fVec,20*log10(abs(specir2)),'r','Linewidth',linewidth);
0133 end
0134 xlim([20, fs/2]);
0135 title('Magnitude Spectrum');
0136 xlabel('Frequency in Hz');
0137 ylabel('Magnitude in dB');
0138 grid on;
0139 
0140 subplot(2,2,3)
0141 semilogx(fVec,phiir1,'k','Linewidth',linewidth);
0142 if plotir2
0143     hold on;
0144     semilogx(fVec,phiir2,'r','Linewidth',linewidth);
0145 end
0146 xlim([20, fs/2]);
0147 xlabel('Frequency in Hz');
0148 ylabel('Phase in degrees');
0149 title('Phase');
0150 grid on;
0151 
0152 subplot(2,2,4)
0153 semilogx(fVec2,grir1*1000,'k','Linewidth',linewidth);
0154 if plotir2
0155     hold on;
0156     semilogx(fVec2,grir2*1000,'r','Linewidth',linewidth);
0157 end
0158 xlim([20, fs/2]);
0159 title('Group Delay');
0160 xlabel('Frequency in Hz');
0161 ylabel('Group Delay in ms');
0162 grid on;
0163 
0164 end
0165

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