Matlab R2015b snr output doesn't shows anything
    1 visualización (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
This following code is a simulation on FxLMS, developed by Agustinus Oey. I wanted to find the SNR of it. so, if i add snr command 
SNR_1 = snr(Yd-e_cont,Yd);
 at the end, it doesn't shows any output. what am i missing? 
% Developed by Agustinus Oey <oeyaugust@gmail.com>                        
% Center of Noise and Vibration Control (NoViC)                           
% Department of Mechanical Engineering                                    
% Korea Advanced Institute of Science and Technology (KAIST)              
% Daejeon, South Korea 
%--------------------------------------------------------------------------
% Set simulation duration (normalized) 
clear
T=1000; 
% We do not know P(z) and S(z) in reality. So we have to make dummy paths
Pw=[0.01 0.25 0.5 1 0.5 0.25 0.01];
Sw=Pw*0.25;
% Remember that the first task is to estimate S(z). So, we can generate a
% white noise signal,
x_iden=randn(1,T);
% send it to the actuator, and measure it at the sensor position, 
y_iden=filter(Sw, 1, x_iden);
% Then, start the identification process
Shx=zeros(1,16);     % the state of Sh(z)
Shw=zeros(1,16);     % the weight of Sh(z)
e_iden=zeros(1,T);   % data buffer for the identification error
% and apply least mean square algorithm
mu=0.1;                         % learning rate
for k=1:T,                      % discrete time k
    Shx=[x_iden(k) Shx(1:15)];  % update the state
    Shy=sum(Shx.*Shw);	        % calculate output of Sh(z)
    e_iden(k)=y_iden(k)-Shy;    % calculate error         
    Shw=Shw+mu*e_iden(k)*Shx;   % adjust the weight
end
% Lets check the result
subplot(2,1,1)
plot([1:T], e_iden)
ylabel('Amplitude');
xlabel('Discrete time k');
legend('Identification error');
subplot(2,1,2)
stem(Sw) 
hold on 
stem(Shw, 'r*')
ylabel('Amplitude');
xlabel('Numbering of filter tap');
legend('Coefficients of S(z)', 'Coefficients of Sh(z)')
% The second task is the active control itself. Again, we need to simulate 
% the actual condition. In practice, it should be an iterative process of
% 'measure', 'control', and 'adjust'; sample by sample. Now, let's generate 
% the noise: 
X=randn(1,T);
% and measure the arriving noise at the sensor position,
Yd=filter(Pw, 1, X);
% Initiate the system,
Cx=zeros(1,16);       % the state of C(z)
Cw=zeros(1,16);       % the weight of C(z)
Sx=zeros(size(Sw));   % the dummy state for the secondary path
e_cont=zeros(1,T);    % data buffer for the control error
Xhx=zeros(1,16);      % the state of the filtered x(k)
% and apply the FxLMS algorithm
mu=0.1;                            % learning rate
for k=1:T,                         % discrete time k
    Cx=[X(k) Cx(1:15)];            % update the controller state    
    Cy=sum(Cx.*Cw);                % calculate the controller output	
    Sx=[Cy Sx(1:length(Sx)-1)];    % propagate to secondary path
    e_cont(k)=Yd(k)-sum(Sx.*Sw);   % measure the residue (main path - secondary path)
    Shx=[X(k) Shx(1:15)];          % update the state of Sh(z) %%previously Shx=[x_iden(k) Shx(1:15)];
    Xhx=[sum(Shx.*Shw) Xhx(1:15)]; % calculate the filtered x(k),new Shx, old SSShw
    Cw=Cw+mu*e_cont(k)*Xhx;        % adjust the controller weight
end
% Report the result
figure
subplot(2,1,1)
plot([1:T], e_cont)
ylabel('Amplitude');
xlabel('Discrete time k');
legend('Noise residue')
subplot(2,1,2)
plot([1:T], Yd) 
hold on 
plot([1:T], Yd-e_cont, 'r:')
ylabel('Amplitude');
xlabel('Discrete time k');
legend('Noise signal', 'Control signal')
0 comentarios
Respuestas (1)
  Jerome Blair
 el 7 de Jul. de 2022
        You have  a semicolon after the command. That tells MATLAB to not show teh answere.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

