Gaussian Noise Error message

 Accepted Answer

Image Analyst
Image Analyst on 24 Nov 2022
The error seems clear. You're tying to use "signal" in a function where it does not exist. I didn't look at the code but nowhere did you either pass in "signal" or create it in the function. You need to do one or the other.

7 Comments

I'll add
% ...
sigEner = norm(signals(:))^2; % energy of the signal
noiseEner = sigEner/(10^(reqSNR/10)); % energy of noise to be added
noiseVar = noiseEner/(length(signal(:))-1); % variance of noise to be added
St = sqrt(noiseVar); % std. deviation of noise to be added
noise = St*randn(size(signal)); % noise
noisySig = signal+noise; % noisy signal
% ...
There is a variable called signals which appears to suddenly change its name to signal
I tried adding s to signals to make it signals. My signals has been defined in the "Process Data" script
Replacing "signal" with "signals" in getmswtfeat fixes the signal problem but you have an index out of range error. I trust you can figure that one out, right?
%% load the data first
load('John_3PhaseFault0ohm.mat')
%% does this signal has any NaNs, if so remove
SteadyStateNoneFaultState = rmmissing(SteadyStateNoneFaultState);
Data3Phase0hmsFaultData = rmmissing(Data3Phase0hmsFaultData);
SSTime = SteadyStateNoneFaultState.Time;
SSNFS = SteadyStateNoneFaultState.SteadyStateNoneFaultState;
DPTime = Data3Phase0hmsFaultData.Time;
DPFD = Data3Phase0hmsFaultData.Data3Phase0hmsFaultData;
%% Define the filtering and inspect
n = 8; %% defines window length
w = [-ones(n,1); ones(n,1)];
SSNFS = filter(w, n, SSNFS);
DPFD = filter(w, n, DPFD);
%% Normalize signals
med_training = prctile(SSNFS,50);
iqr_training = iqr(SSNFS);
SSNFS = (SSNFS-med_training)./iqr_training;
med_fault = prctile(DPFD,50);
iqr_fault = iqr(DPFD);
DPFD = (DPFD-med_fault)./iqr_fault;
% Plot & Observe the data
subplot(2,1,1)
plot(DPTime, DPFD)
title('filtered Data3Phase0hmsFaultData')
subplot(2,1,2)
plot(SSTime, SSNFS)
title('filtered SteadyStateNoneFaultState')
%% Let's observe the FFT power spectrum for differences
feat_fault = getmswtfeat(DPFD,32,16,100000);
Index in position 2 exceeds array bounds. Index must not exceed 52.

Error in getmswtfeat (line 117)
prob = percentENER(:,st:en);%./repmat(sum(percentENER(:,st:en),2),1,longs(k)) + eps;
feat_Good = getmswtfeat(SSNFS,32,16,100000);
Actually the main problem figuring and fixing the index error? How do you do that?
@john amoo otoo I'd start here:
I don't have the Wavelet Toolbox and it's not possible to debug just by running code here in Answers. So the only way is for you to learn how to debug and debug it yourself. It's a skill you will need to learn eventually anyway. "Debugging via Answers" and waiting to see if someone who has the Wavelet Toolbox is willing to do your debugging for you is very slow and not reliable. It will be much faster to do it yourself.
What I am trying ti get at is to de-noise the signal and extract the features with getfeat
Yes, debugging will definitely allow you to do that. Did you learn how to debug yet from the tutorial I showed you? If not, why not?

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!