www.pudn.com > CR_simulink.rar > fft_view.asv, change:2006-10-13,size:993b


 
function [sys, x0, str, ts] = fft_view(t, x, u, flag) 
 
switch flag, 
    case 0  
        [sys,x0, str, ts] = mdlInitializeSizes; 
    case 3 
        sys = mdlOutputs(t,x,u); 
    case {1,2,4,9} 
        sys = []; 
    otherwise 
        error(['Unhandled flag = ', num2str(flag)]); 
                 
end; 
 
function [sys, x0, str, ts] = mdlInitializeSizes 
sizes = simsizes; 
sizes.NumContStates = 0; 
sizes.NumDiscStates = 0; 
sizes.NumOutputs = 500; 
sizes.NumInputs = 500; 
sizes.DirFeedthrough = 1; 
sizes.NumSampleTimes = 1; 
sys = simsizes(sizes); 
x0=[]; 
str=[]; 
ts=[-1,0]; 
function sys = mdlOutputs(t,x,u) 
ts = 0.001; 
fs = 1/ts; 
ws = 2*pi*fs; 
 
f0=10; 
w0=2*pi*f0; 
x1=u; 
 
BW = fs/2; 
 
w = linspace(-BW, BW, length(x1)); 
dw = w(2)-w(1); 
 
F = fftshift(fft(x1))/fs; 
FT = abs(F); 
 
FT2 = dw*FT; 
 
fig1 = figure(3); 
plot(w, FT2) 
axis([0, max(w), 0, 0.5]) 
xlabel('w [radian/sec]') 
ylabel('|F(w)|') 
 
sys = FT2; 
set(fig1,'units','nor','pos',[0.01,0.5,0.5,0.3]);