⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fir_filter_amp_delay.m

📁 当信号输入FIR滤波器后,将回产生时间延迟,这一现象是不利于通信系统的,我们可以通过MATLAB工具进行仿真,观察时间延迟.
💻 M
字号:
%file:fir_filter_amp_delay.m
function[h,times]=fir_filter_amp_delay(h,fs,n,fscale,fshift,dscale)
%this function returns the impulse response of an fir filter
%h=row vector of impulse response values at t=times
%h is rotated to center the impulse response array at n/2*ts
%it is assumed that there is no 'constant delay'in the freq response given
%h is an array of frequency response
%column 1:frequencies fk inascending order
%after translation and scaling frequencies must be -fs/2<f<fs/2
%column 2:20*log(|h(fk)|)
%column 3:group delay in units 1/frequency
%(i.e.,if freq is given in mhzmthen delay should be in micro seconds)
%otherwise use dscale to adjust delay =delay/dscale
%ex:if delay is given in ns then delay in microsecs=delay ns/1000
%phase response is obtainde by intrgration delay from f=0
%phase((k+1)df)=phase(kdf)+2*pi*(fs/nfft)delay(kdf)=phase(kdf)+(2*pi/nfft)(
%delay(kdf)/ts)
%fscale and fshift:f=(f-fshift)/fscale
%fs:sampling rate
%n:duration of the impulse response;the frequency response is resampled
%from (-fs/2+df/2 to fs/2-df/2 using df=fs/n)
ts=1/fs;df=fs/n;
%pick up the frequency,magnitude and phase response arrays
%convert dbs to real magnitudes;rescale frequencies
Hfreq=H(:,1);Hmag=H(:,2);Hdelay=H(:,3);
nn=max(size(Hmag));Hreal=10.^(Hmag/20);
Hfreq=(Hfreq-fshift)/fscale;Hdelay=Hdelay/dscale;
%set up index array for frequencies and times
index1=[0:1:(n/2)];index2=[-(n/2)+1:1:-1];index=[index1 index2]';
frequencies=(index*df);times=index*ts;
%use shift fft function to change rotate the time indices
times=shift_ifft(times,n);
%freq array goes from [0,df,2df]
%time array goes from 0 to n/2*ts
fmin=min(min(frequencies));fmax=max(max(frequencies));
Hfreq1=Hfreq;Hreal1=Hreal;Hdelay1=Hdelay;
if fmin<Hfreq(1,1)
    hfreq1=[fmin,Hfreq];
    Hreal1=[1e-10;Hreal];
    Hdelay1=[Hdelay(1,1);Hdelay];
end
if fmax>Hfreq(nn,1)
    Hfreq1=[Hfreq1;fmax];
    Hreal1=[Hreal1;1e-10];
    Hdelay=[Hdelay1;Hdelay(nn,1)];
end
Hreal_interpolated=interp1(Hfreq1,Hreal1,frequencies);
Hdelay_interpolated=interp1(Hfreq1,Hdelay1,frequencies);
sum=0;
Hphase(1)=0;
for k=2:(n/2)+1
    sum=sum+(Hdelay_interpolated(k,1)/ts)*(2*pi/n);
    Hphase(k,1)=sum;
end
sum=0.0;
for k=n:-1:(n/2)+2
    sum=sum+(Hdelay_interpolated(k,1)/ts)*(2*pi/n);
    Hphase(k,1)=sum;
end
Hcomplex=Hreal_interpolated.*exp(i*Hphase);
hh=ifft(Hcomplex);h=(shift_ifft(hh,n));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -