| [163] | 1 | % Cette routine permet de comparer trois méthodes de traitement
|
|---|
| 2 | % des sinus glissants (glissement logarithmique)
|
|---|
| 3 | % Le signal d'excitation est généré selon la méthode proposée par Farina
|
|---|
| 4 | % les trois méthodes de traitement sont :
|
|---|
| 5 | % - Fonction de Transfert
|
|---|
| 6 | % - Déconvolution par filtre inverse
|
|---|
| 7 | % - Déconvolution par filtre inverse avec passage dans le domaine
|
|---|
| 8 | % fréquentiel
|
|---|
| 9 | % Le système de test est un filtre passe-bas (type RC)
|
|---|
| 10 | % les paramètres à faire varier sont :
|
|---|
| 11 | % f1 et f2, les fréquences encadrant le signal généré
|
|---|
| 12 | % nwin le nombre de points sur lequel on fenêtre le signal (en début et en fin)
|
|---|
| 13 | % tmax : la durée du sinus glissant
|
|---|
| 14 |
|
|---|
| 15 | clear all
|
|---|
| 16 | close all
|
|---|
| 17 | %input parameters
|
|---|
| 18 | f1=1; % start frequency (Hz)
|
|---|
| [190] | 19 | f2=5000; %end frequency(Hz)
|
|---|
| [163] | 20 | tmax=.5; % excitation signal duration (s)
|
|---|
| 21 | nwin=100; % windowing point number (half at the begining - half at the end)
|
|---|
| 22 |
|
|---|
| 23 | %chirp generation (Farina)
|
|---|
| 24 | fs=44100; % sampling frequency (Hz)
|
|---|
| 25 | dt=1/fs; % sampling period
|
|---|
| 26 | t=0:dt:tmax; % time vector
|
|---|
| 27 | om1=2*pi*f1; % begining pulsation
|
|---|
| 28 | om2=2*pi*f2; % ending pulsation
|
|---|
| 29 | K=tmax*om1/log(om2/om1);
|
|---|
| 30 | L=tmax/log(om2/om1);
|
|---|
| 31 | yc=sin(K*(exp(t./L)-1)); % excitation signal (logarithmic swept signal)
|
|---|
| 32 |
|
|---|
| 33 | %chirp windowing
|
|---|
| 34 | win=hanning(nwin);
|
|---|
| 35 | siz=length(yc);
|
|---|
| 36 | wint=ones(1,siz);
|
|---|
| 37 | wint(1:nwin/2)=win(1:nwin/2);
|
|---|
| 38 | wint(siz-nwin/2+1:siz)=win(nwin/2+1:nwin);
|
|---|
| 39 | y=yc.*wint; %windowed swept sine
|
|---|
| 40 |
|
|---|
| 41 | %Test on a low pass filter: processing of the filtered signal (iterative
|
|---|
| 42 | % method)
|
|---|
| 43 | fc=400; % cut-off frequency
|
|---|
| 44 | RC=1/2/pi/fc;
|
|---|
| 45 | alf=dt/(dt+RC);
|
|---|
| 46 | yf(1)=y(1);
|
|---|
| 47 | for n=2:siz
|
|---|
| 48 | yf(n)=alf*y(n)+(1-alf)*yf(n-1); % filtered signal
|
|---|
| 49 | end
|
|---|
| 50 |
|
|---|
| 51 | %plot of the input and filtered signals
|
|---|
| 52 | figure (1)
|
|---|
| 53 | plot(t,y,'b');
|
|---|
| 54 | xlabel('Time (s)');
|
|---|
| 55 | hold on
|
|---|
| 56 | plot(t,yf,'r')
|
|---|
| 57 | title('Input signals')
|
|---|
| 58 | grid on
|
|---|
| 59 | h = legend('Input signal','filtered signal',2);
|
|---|
| 60 | set(h,'location','SouthWest')
|
|---|
| 61 |
|
|---|
| 62 | % Impulse response: Inverse filter deconvolution (time domain)
|
|---|
| 63 | yinv=fliplr(y);
|
|---|
| 64 | fl=logspace(log10(f1),log10(f2),siz);
|
|---|
| 65 | yinv=yinv./fl; % inverse filter
|
|---|
| 66 | tic
|
|---|
| 67 | IR=conv(yf,yinv); % processed impulse response
|
|---|
| 68 | toc
|
|---|
| 69 | sizi=length(IR);
|
|---|
| 70 | is=fft(y).*conj(fft(yinv));
|
|---|
| 71 | norm=sqrt(sum(abs(is.^2))/siz);
|
|---|
| 72 | yeff=norm*sqrt(fs/2/(f2-f1));
|
|---|
| 73 | IR=IR*fs/yeff;
|
|---|
| 74 | t2=(-siz+1:1:siz-1).*dt;
|
|---|
| 75 | figure(2)
|
|---|
| 76 | subplot(3,1,1)
|
|---|
| 77 | plot(t2,IR,'b')
|
|---|
| 78 | grid on
|
|---|
| 79 | xlabel('samples')
|
|---|
| 80 | title('Impulse response')
|
|---|
| 81 | ylabel('Deconvolution')
|
|---|
| 82 | IRT=exp(-t2/RC)/RC;
|
|---|
| 83 | IRT(1:siz-1)=0;
|
|---|
| 84 | hold on
|
|---|
| 85 | plot(t2,IRT,'r')
|
|---|
| [173] | 86 | legend('Processed','Theory',3)
|
|---|
| [163] | 87 |
|
|---|
| 88 | % frequency response : Inverse filter deconvolution (time domain)
|
|---|
| 89 | FR=fft(IR)/fs;
|
|---|
| 90 | FR=FR(1:sizi/2);
|
|---|
| 91 | fconv=0:fs/sizi:fs/2;
|
|---|
| 92 | fconv=fconv(1:sizi/2);
|
|---|
| 93 | LFR=20*log10(abs(FR));
|
|---|
| 94 | figure(3)
|
|---|
| 95 | subplot(3,1,1)
|
|---|
| 96 | semilogx(fconv,LFR)
|
|---|
| [191] | 97 | ylabel('Transfer function (deconvolution)')
|
|---|
| [163] | 98 | title('Frequency response (dB)')
|
|---|
| 99 | axis([10 20000 -40 +5])
|
|---|
| 100 | grid on
|
|---|
| 101 | hold on
|
|---|
| 102 | FRT=abs(1./(1+j*2*pi*fconv*RC));
|
|---|
| 103 | LFRT=20*log10(FRT);
|
|---|
| 104 | semilogx(fconv,LFRT,'r')
|
|---|
| 105 | xlabel('Frequency (Hz)')
|
|---|
| 106 | legend('Processed','Theory',3)
|
|---|
| [173] | 107 | imin=round(f1/fs*sizi)+1;
|
|---|
| 108 | imax=round(f2/fs*sizi)+1;
|
|---|
| 109 | E1=sqrt(sum(abs(FRT(imin:imax)-FR(imin:imax)).^2./(abs(FRT(imin:imax)).^2)))*100/(imax-imin+1);
|
|---|
| [191] | 110 | E1t = strcat('Quadratic error :',num2str(E1,2),' %');
|
|---|
| [173] | 111 | text(3000,-5,E1t);
|
|---|
| [163] | 112 |
|
|---|
| 113 | %Transfer function method
|
|---|
| 114 | specy=fft(y);
|
|---|
| 115 | specyf=fft(yf);
|
|---|
| 116 | TF=specyf./specy;
|
|---|
| 117 | IR2=ifft(TF)*fs;
|
|---|
| 118 | figure(2)
|
|---|
| 119 | subplot(3,1,2)
|
|---|
| [173] | 120 | % pad=zeros(1,siz-1);
|
|---|
| 121 | % IR2=[pad IR2];
|
|---|
| 122 | plot(t,IR2,'b')
|
|---|
| [163] | 123 | grid on
|
|---|
| 124 | hold on
|
|---|
| 125 | plot(t2,IRT,'r')
|
|---|
| 126 | xlabel('samples')
|
|---|
| 127 | ylabel('Inverse Transfer Function')
|
|---|
| [173] | 128 | legend('Processed','Theory',3)
|
|---|
| [163] | 129 | TF2=TF(1:siz/2);
|
|---|
| [173] | 130 | f=0:fs/siz:fs/2-fs/siz;
|
|---|
| [163] | 131 | LFR2=20*log10(abs(TF2));
|
|---|
| 132 | figure(3)
|
|---|
| 133 | subplot(3,1,2)
|
|---|
| 134 | semilogx(f,LFR2)
|
|---|
| 135 | axis([10 20000 -40 +5])
|
|---|
| 136 | grid on
|
|---|
| 137 | hold on
|
|---|
| 138 | FRT2=abs(1./(1+j*2*pi*f*RC));
|
|---|
| 139 | LFRT2=20*log10(FRT2);
|
|---|
| 140 | semilogx(f,LFRT2,'r')
|
|---|
| 141 | xlabel('Frequency (Hz)')
|
|---|
| 142 | ylabel('Transfer Function')
|
|---|
| 143 | legend('Processed','Theory',3)
|
|---|
| [173] | 144 | % imin=round(f1/fs*sizi)+1;
|
|---|
| 145 | % imax=round(f2/fs*sizi)+1;
|
|---|
| 146 | % E2=sqrt(sum(abs(FRT(imin:imax)-TF2(imin:imax)).^2./(abs(FRT(imin:imax)).^2)))*100/(imax-imin+1);
|
|---|
| 147 | % E2t = strcat('Erreur quadratique :',num2str(E2,2),' %');
|
|---|
| 148 | % text(3000,-5,E2t);
|
|---|
| [163] | 149 |
|
|---|
| 150 | % Impulse response: Inverse filter deconvolution (freq domain)
|
|---|
| 151 | % yinv=fliplr(yc);
|
|---|
| 152 | % fl=logspace(log10(f1),log10(f2),siz);
|
|---|
| 153 | % yinv=yinv./fl; % inverse filter
|
|---|
| 154 | % yinvf=yinv.*wint; %windowed inverse filter
|
|---|
| 155 | % IR=conv(yf,yinvf); % processed impulse response
|
|---|
| 156 | tic
|
|---|
| 157 | iRF=fft([yf, zeros(1,siz-1)]).*fft([yinv, zeros(1,siz-1)])/yeff;
|
|---|
| 158 | IR3=real(ifft(iRF))*fs;
|
|---|
| 159 | toc
|
|---|
| 160 | % norm=sqrt(sum(abs(is.^2))/siz);
|
|---|
| 161 | % yeff=norm*sqrt(fs/2/(f2-f1));
|
|---|
| 162 | % scal=fs/yeff;
|
|---|
| 163 | t2=(-siz+1:1:siz-1).*dt;
|
|---|
| 164 | figure(2)
|
|---|
| 165 | subplot(3,1,3)
|
|---|
| 166 | plot(t2,IR3,'b')
|
|---|
| 167 | grid on
|
|---|
| 168 | xlabel('samples')
|
|---|
| 169 | title('Impulse response')
|
|---|
| 170 | ylabel('Deconvolution freq')
|
|---|
| 171 | IRT=exp(-t2/RC)/RC;
|
|---|
| 172 | IRT(1:siz-1)=0;
|
|---|
| 173 | hold on
|
|---|
| 174 | plot(t2,IRT,'r')
|
|---|
| [173] | 175 | legend('Processed','Theory',3)
|
|---|
| [163] | 176 |
|
|---|
| 177 | % frequency response : Inverse filter deconvolution (freq domain)
|
|---|
| 178 | FR3=iRF(1:sizi/2);
|
|---|
| 179 | fconv=0:fs/sizi:fs/2;
|
|---|
| 180 | fconv=fconv(1:sizi/2);
|
|---|
| 181 | LFR3=20*log10(abs(FR3));
|
|---|
| 182 | figure(3)
|
|---|
| 183 | subplot(3,1,3)
|
|---|
| 184 | semilogx(fconv,LFR3)
|
|---|
| 185 | ylabel('Transfert function (deconv freq)')
|
|---|
| 186 | title('Frequency response (dB)')
|
|---|
| 187 | axis([10 20000 -40 +5])
|
|---|
| 188 | grid on
|
|---|
| 189 | hold on
|
|---|
| 190 | FRT=abs(1./(1+j*2*pi*fconv*RC));
|
|---|
| 191 | LFRT=20*log10(FRT);
|
|---|
| 192 | imin=round(f1/fs*sizi)+1;
|
|---|
| 193 | imax=round(f2/fs*sizi)+1;
|
|---|
| 194 | E3=sqrt(sum(abs(FRT(imin:imax)-FR3(imin:imax)).^2./(abs(FRT(imin:imax)).^2)))*100/(imax-imin+1);
|
|---|
| 195 | E3t = strcat('Erreur quadratique :',num2str(E3,2),' %');
|
|---|
| 196 | text(3000,-5,E3t);
|
|---|
| 197 | semilogx(fconv,LFRT,'r')
|
|---|
| 198 | xlabel('Frequency (Hz)')
|
|---|
| 199 | legend('Processed','Theory',3)
|
|---|