fg_07_08.m

来自「英文书《Digital Signal Processing with Examp」· M 代码 · 共 52 行

M
52
字号
% fg_07_08          Frequency functions of sine and image.
sp_fig(1);
N=65536;
x=zeros(2,N);

% Sine wave in x(1,:).
x(1,:)=7.499*sin(2*pi*(1:N)/(N/2));
subplot(2,2,1);
line([0:N-1]/(N/2),x(1,:),'color','r'); grid on;
set(gca,'fontsize',16);
title('x=7.5sin4\pit');
xlabel('t'); ylabel('x(t)');
axis([0 2 -8 8]);

% Lena in array xx, then x(2,:).
xx=zeros(256,256);
fid=fopen(['lena.txt']);
for row=(1:256)
 xx(1:256,row)=fscanf(fid, ...
  '%4d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d\n',256);
end
xx=xx'+20;
fclose(fid);
subplot(2,2,2);
colormap(gray(256));
image(xx); axis square;
set(gca,'fontsize',16);
set(gca,'xtick',[1 100 200],'ytick',[1 100 200]);
title('Grey-scale image');
x(2,:)=row_vec(xx);

% Frequency plots.
ax=[-8 8 0 .2; 0 256 0 .015];
clr=['r','k'];
tl=['Uniform; \sigma=4.33 ';'Gaussian; \sigma=2.00'];
for ip=1:1,
   [f,x1,x2]=freq(x(ip,:));
   subplot(2,2,ip+2);
   axis(ax(ip,:));
   set(gca,'fontsize',16);
   xa=x1:x2;
   xlabel('n'); ylabel('       f_n');
   if(ip==1),
      set(gca,'xtick',[-8:2:8]);
      line([xa;xa],[zeros(1,x2-x1+1);f],'color','k'); grid;
      line(xa,f,'color',clr(ip),'linestyle','none','marker','*');
   else
      set(gca,'xtick',[0:64:256]);
      line(xa,f,'color','k'); grid on;
   end
end

⌨️ 快捷键说明

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