📄 sample1.asv
字号:
%注意:调用子函数时一定要在另外的文件下面调用,而且该子函数的文件名一定要用子函数名,
%就是说只要写好函数自己保存就可以了,文件会自动生成相应的正确名称。
%file c7_jakes.m
%generate and test the impulse response of the filter
fd=100; %maximum doppler
impw=jakes_filter(fd) %call to jakes filter,为子函数调用
fs=16*fd;ts=1/fs; %sampling frequency and time
time=[1*ts:ts:128*ts]; %time vector for plot
subplot(2,1,1)
stem(time,impw,'.');grid;
xlabel('time');ylabel('impulse response')
%square the fft and check the power transfer function
[h,f]=linear_fft(impw,128,ts); %generate H(f) for filter为子函数调用
subplot(2,1,2)
plot(f,abs(h.*h));grid;
xlabel('frequency');ylabel('psd')
%put gaussian noise through and check the output psd
x=randn(1,1024); %generate gaussian input
y=filter(impw,1,x) %filter gaussian input
[output_psd ff]=log_psd(y,1024,ts); %log of psd figure;
subplot(2,1,1)
plot(ff,output_psd);grid;
axis([-500 500 -50 0])
xlabel('frequency');ylabel('psd')
%filter complex noise and look at the envelope fading
z=randn(1,1024)+i*randn(1,1024); %generate complex noise
zz=filter(impw,1,z); %filter complex noise
time=(0.0:ts:1024*ts); %new time axis
%normalize output and plot envelope
zz=zz/max(max(abs(zz))); %normalize to one
subplot(2,1,2)
plot(time(161:480),10*log10(abs(zz(161:480))));grid;
axis([0.1 0.3 -20 0])
xlabel('time');ylabel('log amplitude')
%end of function file
%file:jakes_filter.m
% jakes_filter.m
% function [impw]=jakes_filter(fd)
% n=512;nn=2*n;
% fs=0:fd/64:fd;
% H=zeros(1,n);
% for k=1:(n/8+1)
% jpsd(k)=1/((1-((fs(k))/fd)^2)^0.5);
% end
% [inv,time]=linear_fft(H,nn,fd/64);
% imp=real(inv(450:577));
% impw=inp.*hanning(128)';
% energy=sum(impw.^2);
% impw=impw/(energy^0.5);
%file:linear_fft.m
% linear_fft.m
% function [fftx,freq]=linear_fft(x,n,ts)
% y=zeros(1,n);
% for k=1:n
% freq(k)=(k-1-(n/2))/(n*ts);
% y(k)=x(k)*((-1.0)^(k+1));
% end
% fftx=fft(y)/n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -