当前位置:编程学习 > Matlab >>

帮我看看matlab程序!

%干涉信号构造 t=0:0.0000001:0.0040; dt=sin(2*300*pi*t); d1=0.4; d2=0.4+dt;%微小振动d(t)=5e-3*sin(2*10*pi*t) d3=0.2; d4=0.2; bc=5e-3; e0=50*cos(2*pi*8e5*t); subplot(411) plot(t,e0); xlabel('t');ylabel('原始光信号E0'); subplot(412); plot(t,dt); xlabel('t');ylabel('振动信号') em=50*cos(2*pi*8e5*t+2*pi*(d1+2*d3+d4)/bc); ep=50*cos(2*pi*8e5*t+2*pi*(d1+2*d2+d4)/bc); ef=em+ep; subplot(413) plot(t,ef); xlabel('t');ylabel('干涉信号'); %低通滤波器 wp=300;ws=350;fs=1000;rp=0.5;rs=20; [n,wn]=buttord(wp/(fs/2),ws/(fs/2),rp,rs); [b,a]=butter(n,wn); [h,w]=freqz(b,a); y=filtfilt(b,a,ef); subplot(414) plot(t,y); xlabel('t');ylabel('滤波所得振动信号'); 我低通滤波的波形不对,怎么改呀(低通滤波后得的波形要和第二个波形差不多),【把它的这个程序过程能不能帮我解释下】
答案:你的原始信号有问题
    t=0:99;
    e0=0.3*sin(0.8*pi*t);
    subplot(411)
    plot(t,e0);
    xlabel('t');ylabel('原始光信号E0');
    subplot(412);
    dt=0.6*sin(0.1*pi*t);
    plot(t,dt);
    xlabel('t');ylabel('振动信号')
    subplot(412)
    ef=e0+dt;
    subplot(413)
    plot(t,ef);
    xlabel('t');ylabel('干涉信号');


    %低通滤波器
    wp=300;ws=350;fs=1000;rp=0.5;rs=20;
    [n,wn]=buttord(wp/(fs/2),ws/(fs/2),rp,rs);
    [b,a]=butter(n,wn);
    [h,w]=freqz(b,a);

    y=filtfilt(b,a,ef);
    subplot(414)
    plot(t,y);
    xlabel('t');ylabel('滤波所得振动信号');
其他:function pca (path, trainList, subDim)
%
% PROTOTYPE
% function pca (path, trainList, subDim)
% 
% USAGE EXAMPLE(S)
% pca ('C:/FERET_Normalised/', trainList500Imgs, 200);
%
% GENERAL DESCRIPTION
% Implements the standard Turk-Pentland Eigenfaces method. As a final
% result, this function saves pcaProj matrix to the disk with all images
% projected onto the subDim-dimensional subspace found by PCA.
% 
% REFERENCES
% M. Turk, A. Pentland, Eigenfaces for Recognition, Journal of Cognitive
% Neurosicence, Vol. 3, No. 1, 1991, pp. 71-86
% 
% M.A. Turk, A.P. Pentland, Face Recognition Using Eigenfaces, Proceedings
% of the IEEE Conference on Computer Vision and Pattern Recognition,
% 3-6 June 1991, Maui, Hawaii, USA, pp. 586-591
%
% 
% INPUTS:
% path          - full path to the normalised images from FERET database
% trainList     - list of images to be used for training. names should be
%                 without extension and .pgm will be added automatically
% subDim        - Numer of dimensions to be retained (the desired subspace
%                 dimensionality). if this argument is ommited, maximum
%                 non-zero dimensions will be retained, i.e. (number of training images) - 1
%
% OUTPUTS:
% Function will generate and save to the disk the following outputs:
% DATA          - matrix where each column is one image reshaped into a vector
%               - this matrix size is (number of pixels) x (number of images), uint8
% imSpace       - same as DATA but only images in the training set
% psi           - mean face (of training images)
% zeroMeanSpace - mean face subtracted from each row in imSpace
% pcaEigVals    - eigenvalues
% w             - lower dimensional PCA subspace
% pcaProj       - all images projected onto a subDim-dimensional space
%
% NOTES / COMMENTS
% * The following files must either be in the same path as this function
%   or somewhere in Matlab's path:
%       1. listAll.mat - containing the list of all 3816 FERET images
%
% ** Each dimension of the resulting subspace is normalised to unit length
%
% *** Developed using Matlab 7
%
%
% REVISION HISTORY
% -
% 
% RELATED FUNCTIONS (SEE ALSO)
% createDistMat, feret
% 
% ABOUT
% Created:        03 Sep 2005
% Last Update:    -
% Revision:       1.0
% 
% AUTHOR:   Kresimir Delac
% mailto:   kdelac@ieee.org
% URL:      
%
% WHEN PUBLISHING A PAPER AS A RESULT OF RESEARCH CONDUCTED BY USING THIS CODE
% OR ANY PART OF IT, MAKE A REFERENCE TO THE FOLLOWING PAPER:
% Delac K., Grgic M., Grgic S., Independent Comparative Study of PCA, ICA, and LDA 
% on the FERET Data Set, International Journal of Imaging Systems and Technology,
% Vol. 15, Issue 5, 2006, pp. 252-260
%



% If subDim is not given, n - 1 dimensions are
% retained, where n is the number of training images
if nargin < 3
    subDim = dim - 1;
end;


disp(' ')

load listAll;

% Constants
numIm = 3816;


% Memory allocation for DATA matrix
fprintf('Creating DATA matrix\n')
tmp = imread ( [path char(listAll(1)) '.pgm'] );
[m, n] = size (tmp);                    % image size - used later also!!!
DATA = uint8 (zeros(m*n, numIm));       % Memory allocated
clear str tmp;

% Creating DATA matrix
for i = 1 : numIm
    im = imread ( [path char(listAll(i)) '.pgm'] );
    DATA(:, i) = reshape (im, m*n, 1);
end;
save DATA DATA;
clear im;

% Creating training images space
fprintf('Creating training images space\n')
dim = length (trainList);
imSpace = zeros (m*n, dim);
for i = 1 : dim
    index = strmatch (trainList(i), listAll);
    imSpace(:, i) = DATA(:, index);
end;
save imSpace imSpace;
clear DATA;

% Calculating mean face from training images
fprintf('Zero mean\n')
psi = mean(double(imSpace'))';
save psi psi;

% Zero mean
zeroMeanSpace = zeros(size(imSpace));
for i = 1 : dim
    zeroMeanSpace(:, i) = double(imSpace(:, i)) - psi;
end;
save zeroMeanSpace zeroMeanSpace;
clear imSpace;

% PCA
fprintf('PCA\n')
L = zeroMeanSpace' * zeroMeanSpace;         % Turk-Pentland trick (part 1)
[eigVecs, eigVals] = eig(L);

diagonal = diag(eigVals);
[diagonal, index] = sort(diagonal);
index = flipud(index);
 
pcaEigVals = zeros(size(eigVals));
for i = 1 : size(eigVals, 1)
    pcaEigVals(i, i) = eigVals(index(i), index(i));
    pcaEigVecs(:, i) = eigVecs(:, index(i));
end;

pcaEigVals = diag(pcaEigVals);
pcaEigVals = pcaEigVals / (dim-1);
pcaEigVals = pcaEigVals(1 : subDim);        % Retaining only the largest subDim ones

pcaEigVecs = zeroMeanSpace * pcaEigVecs;    % Turk-Pentland trick (part 2)

save pcaEigVals pcaEigVals;

% Normalisation to unit length
fprintf('Normalising\n')
for i = 1 : dim
    pcaEigVecs(:, i) = pcaEigVecs(:, i) / norm(pcaEigVecs(:, i));
end;

% Dimensionality reduction. 
fprintf('Creating lower dimensional subspace\n')
w = pcaEigVecs(:, 1:subDim);
save w w;
clear w;

% Subtract mean face from all images
load DATA;
load psi;
zeroMeanDATA = zeros(size(DATA));
for i = 1 : size(DATA, 2)
    zeroMeanDATA(:, i) = double(DATA(:, i)) - psi;
end;
clear psi;
clear DATA;

% Project all images onto a new lower dimensional subspace (w)
fprintf('Projecting all images onto a new lower dimensional subspace\n')
load w;
pcaProj = w' * zeroMeanDATA;
clear w;
clear zeroMeanDATA;
save pcaProj pcaProj;

上一个:基于MATLAB平台的高程控制网平差软设计谁会啊,给个小程序就行,间接平差的
下一个:请教高手,matlab程序里面的语句:[i,j]=find(bw==0); 表示什么意思?实现什么作用呢? bw是二值图像。

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,