声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1350|回复: 8

[综合讨论] 哪位哥哥给解释一下这几个小脚本怎么修改!!急!急!急!

[复制链接]
发表于 2009-5-24 16:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
:@Q 1》》选择合适的窗函数设计一个FIR数字低通滤波器,要求:通带截至频率为w =0.2 ,R =0.25dB;阻带截至频率为w =0.3 ,A =50dB。求脉冲响应并描绘一张滤波器的频率响应图
                wp=0.2*pi;ws=0.3*pi;    %输入设计指标
        tr_width=ws-wp;         %计算过渡带的宽度
        M=ceil(6.6*pi/ tr_width)+1; %由海明窗的过渡带宽度选择合适的阶数
        n=[0:1:M-1];
        wc=(ws+wp)/2;             %理想低通的截止频率(取平均值)
hd=ideal_lp(wc,M);        %理想低通滤波器冲激响应
w_ham=(haming(M))’;
h=hd .* w_ham;          %给理想低通加海明窗
[db,mag,pha,grd,w]= freqz_m(h,[1]); %求出幅频响应
delta_w=2*pi/1000;
Rp=-(min(db(1:1:wp/delta_w+1)));    %检验通带波动
As=-round(max(db(ws/delta_w+1:1:501)));%检验最小阻带衰减
% plots(绘图)
subplot﹙2,2,1﹚,stem﹙n,hd﹚; title('Ideal Impulse Response');               
axis﹙0 M-1 -0.1 0.3﹚;xlabel﹙'n'﹚;ylabel('hd(n)');
subplot﹙2,2,2﹚;stem﹙n,w_ham);title('Hamming Window') ;         
axis﹙[0 M-1 0.1 1]﹚; xlabel﹙'n'﹚;ylabel('w(n)');
subplot﹙2,2,3﹚;stem﹙n,h﹚; title('Actual Impulse Response');           
axis﹙[0 M-1 -0.1 0.3]﹚; xlabel﹙'n'﹚;ylabel('h(n)');
subplot﹙2,2,4﹚;plot(w/pi,db);title('Magnitude Response in dB');grid
axis﹙[0 1 -100 10]﹚; xlabel﹙'frequency in pi units'﹚;
ylabel('Decibels');  
??? Undefined command/function 'ideal_lp'.

2》》用MATLAB的关系运算式来产生单位阶跃序列u﹙n﹚。

n1=-2;n2=8;n0=0;
     n=n1:n2;                      %生成离散信号的时间序列
     x=[n>=n0];                    %生成离散信号x﹙n﹚
     stem﹙n,x, 'filled'﹚;
     axis﹙[n1,n2,0,1.1*max﹙x﹚]﹚;
     title﹙'单位阶跃序列'﹚;
     xlabel﹙'时间﹙n﹚'﹚;ylabel﹙'幅度x﹙n﹚'﹚;
???      stem﹙n,x, 'filled'﹚;
             |
Error: Missing variable or function.


3》》编写产生a=1/2和a=2实指数连续信号和离散序列的程序
n1=-10;n2=10;a1=0.5;a2=2;
      na1=n1:0;x1=a1.^na1;
      na2=0:n2;x2=a2.^na2;
      subplot﹙2,2,1﹚,plot﹙na1,x1﹚;
      title﹙'实指数原信号﹙a<1﹚'﹚;
      subplot﹙2,2,3﹚,stem﹙na1,x1, 'filled'﹚;
      title﹙'实指数原信号﹙a<1﹚'﹚;
      subplot﹙2,2,2﹚,plot﹙na2,x2﹚;
      title﹙'实指数原信号﹙a>1﹚'﹚;
      subplot﹙2,2,4﹚, stem﹙na2,x2, 'filled'﹚;
      title﹙'实指数原信号﹙a>1﹚'﹚;
???       na1=n1:0;x1=a1.^na1;
                         |
Error: Missing variable or function.
还有很多这样的例子,好久都没弄明白!不管怎么弄,就是不出图xiang!!!!
回复
分享到:

使用道具 举报

发表于 2009-5-24 16:59 | 显示全部楼层
先支持一下楼主:lol
发表于 2009-5-24 17:12 | 显示全部楼层

回复 楼主 mjlt11 的帖子

第一个缺少函数 ideal_lp
第二个^应为英文状态下的半角符号,你写的是全角符号。包括之后的单引号
 楼主| 发表于 2009-5-24 17:24 | 显示全部楼层
friendchj  那麻烦你给把第一个改下好吗?
另外  n1=30;a=-0.1;w=0.6;
      n=0:n1;
      x=exp( ( a+j*w )*n);
      subplot(2,2,1);plot(n,real(x);
      title('复指数原信号的实部');
      subplot(2,2,3);stem(n,real(x), 'filled');
      title('复指数原序列的实部)');
      subplot(2,2,2);plot(n,imag(x));
      title('复指数原信号的虚部)');
      subplot(2,2,4);stem(n, imag(x) , 'filled');
      title('复指数原信号的虚部');
???       x=exp( ( a+j*w )*n);
               |
Error: Missing variable or function. 怎么改??
发表于 2009-5-24 17:35 | 显示全部楼层

回复 地板 mjlt11 的帖子

第一个,关于函数ideal_lp,你的程序的出处应该有;
第二个,把中文括号改成英文括号。
 楼主| 发表于 2009-5-24 18:10 | 显示全部楼层
ideal_lp书上没有,不骗你!

[ 本帖最后由 ChaChing 于 2009-5-27 14:21 编辑 ]
发表于 2009-5-24 18:19 | 显示全部楼层
clc
clear
n1=30;a=-0.1;w=0.6;
      n=0:n1;
      x=exp((a+j*w)*n);
      subplot(2,2,1);plot(n,real(x));
      title('复指数原信号的实部');
      subplot(2,2,3);stem(n,real(x), 'filled');
      title('复指数原序列的实部)');
      subplot(2,2,2);plot(n,imag(x));
      title('复指数原信号的虚部)');
      subplot(2,2,4);stem(n, imag(x) , 'filled');
      title('复指数原信号的虚部');
untitled.jpg
发表于 2009-5-24 18:21 | 显示全部楼层
关于ideal_lp,网上搜了一个
%%%%%%%%%%%%%%%%%%%
function hd = ideal_lp(wc,M);
% Ideal LowPass filter computation
% --------------------------------
% [hd] = ideal_lp(wc,M)
%  hd = ideal impulse response between 0 to M-1
%  wc = cutoff frequency in radians
%   M = length of the ideal filter
%
alpha = (M-1)/2;
n = [0:1:(M-1)];
m = n - alpha + eps;
hd = sin(wc*m) ./ (pi*m);

评分

1

查看全部评分

发表于 2009-5-24 18:25 | 显示全部楼层
笫2个中是'filled'的引号用了汉字的;
笫3个中是^用了汉字的;
笫1个的函数ideal_lp给你如下:
function hd=ideal_lp(wc, M);
%Ideal Lowpass filter computation

alpha=(M-1)/2;
n=[0:(M-1)];
m=n-alpha+eps;
hd=sin(wc*m)./(pi*m);

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 11:24 , Processed in 0.057348 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表