For loop iterations random noise

2 visualizzazioni (ultimi 30 giorni)
Christopher
Christopher il 25 Mar 2013
Hi everyone,
My problem has to do with for loops and random noise. What i am ultimately trying to do is add noise to a signal so i can find the phasors (but that's beyond the point) When i add noise in an equation i feel like the same noise coefficient is being used for the 100 iterations of the equation. Is there a way when i run a for loop that i get a different random coefficient? This is my code so far
%Synchrophasors Homework #4
%Chris Coronel
%Problem #1
clear all;
close all;
j = sqrt(-1); %imaginary variable
N =24; %Number of samples per cycle
f1 = 60; %Nomincal frequency
f2 = 60.5; %Off nominal frequency
del_w = 2*pi*(f2-f1); %Difference between off and nominal frequency
w_prime = 2*pi; % The rate of change of the frequency
del_T = 1/(N*f1); %Sampling interval at nominal frequency
phi_0 = 0.1; %Assumed initial position of phase angle
n = 0:95;
Phi_1 = (phi_0 + del_w*n*del_T + (1/2)*w_prime*(n*del_T).^2)';%Equation to sample at
%%%%%This produces the exact same phase angles as Table 4.1 w/o noise%%%%
Phi_2 = (phi_0 + del_w*n*del_T + (1/2)*w_prime*(n*del_T).^2 + normrnd(0,.01))'; %Equation to sample at
%%%%%This produces the sample of phase angles with noise distribution%%%%%
%%%%Create the Coefficient Matrix%%%%%%
for m=0:95; %Number of samples per cycle interval
B1 = 1.^m;
B2 = m*del_T;
B3 =(m*del_T).^2;
format short
B(m+1,:) = [B1 B2 B3]; %Coefficient Matrix starting at m = 0
end
B_T = B'; % Transpose of Coefficient Matrix
%%%%Solve recursively for the phase angle%%%%%%
for p =1:(96-N);
A1 = inv(B_T(:,p:N-1+p)*B(p:N-1+p,:))*B_T(:,p:N-1+p)*Phi_1(p:N-1+p,:);
A2 = inv(B_T(:,p:N-1+p)*B(p:N-1+p,:))*B_T(:,p:N-1+p)*Phi_2(p:N-1+p,:);
A_no_Guassian(p,:) = A1
A_Guassian(p,:) = A2
end
delta_f1 = mean(A_no_Guassian(:,2)/(2*pi)); %difference of off and nominal freq mean no noise
f_prime1 = mean(A_no_Guassian(:,3)/pi); % mean of rate of change of frequency no noise
delta_f2 = mean(A_Guassian(:,2)/(2*pi))%difference of off and nominal freq mean with noise
f_prime2 = mean(A_Guassian(:,3)/pi) % mean of rate of change of frequency with noise
You will notice that the delta_f2 matches the delta _f1 which is not suppose to be the case. The delta+f2 should have some error since we added white guassian noise. Can someone help please, it'll be much appreciated !
Warm regards Chris Coronel

Risposta accettata

Matt Tearle
Matt Tearle il 25 Mar 2013
Modificato: Matt Tearle il 25 Mar 2013
Phi_2 is Phi_1 plus a single random value. Without delving into the details of the ensuing math, I'm going to guess that's what's causing the problem. Try
Phi_2 = Phi_1 + normrnd(0,.01,size(Phi_1));
instead.
Also, pay attention to the Code Analyzer messages... Bad things are happening in that loop :)

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by