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

📄 aliasing.m

📁 很多matlab的源代码
💻 M
字号:
function aliasing(f,fs)
% ALIASING Movie of aliasing and leakage.
%
%	ALIASING(F,FS) generates a move of aliasing and leakage 
%	F = [F1 F2] in HERTZ defines the frequency range of the sinusoid 
%	FS is the sampling frequency in HERTZ
%
%       ALIASING (with no input arguments) invokes the following example:
%
%	% Show how the aliased frequencies change as the signal frequency 
%	% changes from 225Hz to 400Hz if the sampling frequency is 120Hz
%         >>aliasing([225 400],120)


% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998


if nargin==0,help aliasing,disp('Strike a key to see results of the example')
pause,aliasing([225 400],120),return,end

l=length(f);if l==1,f1=0;f2=f;
elseif l==2,f1=f(1);f2=f(2);
else,error('frequency range must have TWO elements'),return,end
r=10*round(fs/20);s=[-r r 0 0.6]; 
if exist('version')==5,ml=4;er='erasemode';xo='xor';xd='xdata';yd='ydata';
else,ml=3;end
subplot,hold off
 vx=matverch;
 if vx < 4, eval('clg');else,eval('clf');end

axis(s);plot([-fs/2 -fs/2],[0 0.6],[fs/2 fs/2],[0 0.6],'-'),axis(s);hold on
if ml==4,eval('grid on'),else,grid,end
fa=num2str(f1);fb=num2str(f2);fc=num2str(fs);
title(['Spectrum: Sinusoids between ' fa 'Hz & ' fb 'Hz sampled at ' fc 'Hz'])  

X1=0;sf1=0;if ml==4,plt=eval('plot(sf1,X1,er,xo)');end
ts=1/fs;nn=64;t=0:ts:(nn-1)*ts;df=1/(ts*nn);sf=[-nn/2:nn/2-1]*df;
if ml==3,sc=100;else,sc=500;end
for k=f1:(f2-f1)/sc:f2,
x=cos(2*pi*k*t);X=fft(x)/nn;X=abs(fftshift(X));
if ml==4,eval('set(plt,xd,sf,yd,X);drawnow'),else
plot(sf1,X1,'i'),plot(sf,X),grid,sf1=sf;X1=X;end
end
hold off,subplot

⌨️ 快捷键说明

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