返回信息流【 以下文字转载自 StudyShare 讨论区 】
发信人: xcmmxcmm (xcmmxcmm), 信区: StudyShare
标 题: 谁能帮我看看这个程序?急!
发信站: 北邮人论坛 (Thu Jun 11 09:17:12 2009), 站内
程序不大,很急,不知道错在哪里。是一个matlab的程序,编的是低通滤波器
function[t st]=lpf(f,sf,B)
%This function filter an input data using a lowpass filter
%Inputs:f:frequency samples
% sf:input data spectrum samples
% B:lowpass's a bandwidth with a rectangle lowpass
%Outputs:t:time samples
% st:output data's time samples
df=f(2)-f(1);
T=1/df;
hf=zeros(1,length(f));
bf=[-floor(B/df):floor(B/df)]+floor(length(f)/2);
hf(bf)=1;
yf=hf.*sf;
[t,st]=F2T(f,yf);
st=real(st);
谁能帮我太感激了!太着急了。
这是一条镜像帖。来源:北邮人论坛 / matlab / #5804同步于 2009/6/11
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Matlab机器人发帖
谁能帮我看看这个程序?急! (转载)
wfzyl2007
2009/6/11镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
这是《通信原理--基于MATLAB的计算机仿真》P51页的源程序
一个字不差, 是函数不会用还是啥?问题没说明白。
注:要使用lpf,则其中的sf必须由P18的T2F得到
其实T2F和F2T中用到了fftshift这个函数,会产生误差,误差在1e-4左右
精确点的可以用下面这个程序
function [f,sf]=fly(t,st)
%计算信号的傅里叶变换
%--------------------------------------------------------------------------
%函 数 名:fly.m
%输入参数:t 时域信号的时间刻度
% st 时域信号
%输出参数:f 傅氏变换的频域刻度
% sf 时域信号的傅氏变换
%--------------------------------------------------------------------------
dt=t(2)-t(1); %时域分辨率
T=t(end); %时间长度
df=1/T; %频域分辨率
N=length(st); %时域抽样点数
f=-(N-1)/2*df:df:(N-1)/2*df;
sf=T/N*fft(st);
p=(N-1)/2;
for k=1:1:p
aps(1,k)=sf(1,p+1+k);
aps(1,p+1+k)=sf(1,k+1);
end
aps(1,p+1)=sf(1,1);
clear sf;
sf=aps;
function [t,st]=ffly(f,sf)
%计算信号的反傅里叶变换
%--------------------------------------------------------------------------
%函 数 名:ffly.m
%输入参数:f 傅氏变换的频域刻度
% sf 时域信号的傅氏变换
%输出参数:t 时域信号的时间刻度
% st 时域信号
%--------------------------------------------------------------------------
df=f(2)-f(1);
T=1/df;
N=length(f);
dt=T/(N-1);
t=0:dt:T;
p=(N-1)/2;
for k=1:1:p
a(1,k+1)=sf(1,p+1+k);
a(1,p+1+k)=sf(1,k);
end
a(1,1)=sf(1,p+1);
st=N/T*ifft(a);
function[t st]=lpf(f,sf,B)
%This function filter an input data using a lowpass filter
%Inputs:f:frequency samples
% sf:input data spectrum samples
% B:lowpass's a bandwidth with a rectangle lowpass
%Outputs:t:time samples
% st:output data's time samples
df=f(2)-f(1);
T=1/df;
hf=zeros(1,length(f));
bf=[-floor(B/df):floor(B/df)]+floor(length(f)/2);
hf(bf)=1;
yf=hf.*sf;
[t,st]=ffly(f,yf);