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 66 67 68 69 70 71 72 73
| clear all, close all, clc
%% param
mainpanel = figure('Position',[1 35 1680 990],'color','w','toolbar','none','menubar','none');
fs = 50000;
vt = 0:1/fs:1-1/fs;
nfft = 2^nextpow2(length(vt));
vecf = fs/2*linspace(0,1,nfft/2)';
ordre_filtre = 10;
[b,a] = butter(ordre_filtre,5000/(48000/2), 'low');
%% réponse impulsionnelle en utilisant impz
[h,t] = impz(b,a,fs);
subplot(234)
plot(vt,h);
xlabel('Time [s]');
title('Theoretical Impulse Response (by impz)');
xlim([0 0.001])
ylim([-0.1 0.5])
%% frequency reponse of the filter
% subplot(231)
% figure('Position',[-20 553 560 420]);
uicontrol('parent',mainpanel,'position',[210 800 400 100],'style','text',...
'string',sprintf('butterworth ordre %i',ordre_filtre),'Fontsize',20,'Fontweight','bold','fontname','times new roman','backgroundcolor','w');
% ylim([-150 0])
%% signaux
signal1 = randn(length(t),1); % input
signal2 = filter(b,a,signal1); % output
%% fonction de transfert par calcul
SIG1 = fft(signal1,nfft);
SIG2 = fft(signal2,nfft);
FT = SIG2./SIG1;
subplot(233)
plot(vecf,abs(FT(1:nfft/2,1)))
xlabel('Freq [Hz]');
title('Transfer Function (by FFT)');
ylim([0 1.8])
%% fonction de transfert par tfestimate
win = window(@gausswin,512);
noverlap = 0.75*length(win);
[Txy,F] = tfestimate(signal1,signal2,win,noverlap,nfft,fs);
% figure('Position',[1114 52 560 469]);
subplot(236)
plot(F,abs(Txy))
xlabel('Freq [Hz]');
title('Transfer Function (by Tfestimate)');
ylim([0 1.8])
%% réponse impulsionnelle par fft
RI = ifft(Txy);
% figure('Position',[546 553 560 467]);
subplot(232)
plot(linspace(0,1,length(RI)),real(RI))
% pg
title('Impulse Response (by fft)');
xlabel('Time [s]');
xlim([0 0.001])
ylim([-0.1 0.5])
%% réponse impulsionnelle par xcorr
xc = xcorr(signal2,signal1,'unbiased');
% figure('Position',[548 52 560 469])
subplot(235)
plot(linspace(0,1,length(xc(end/2:end,1))),xc(end/2:end,1));
title('Impulse Response (by xcorr)');
xlabel('Time [s]');
xlim([0 0.001])
ylim([-0.1 0.5]) |
Partager