Not able to add white noise to signals

4 visualizaciones (últimos 30 días)
Rohan Gulur
Rohan Gulur el 4 de En. de 2024
Respondida: Siraj el 9 de En. de 2024
for i = 1:numFreqs
curSig=signals(:, i);
sysamp1num1=amp1.gettransferfunction();
cursnr(:, i)=snr(signals(:, i), noiseamount);
curnoisysignal(:, i)=awgn(signals(:, i), cursnr(:, i));
outputs(:, i) = lsim(sysamp1num1,curnoisysignal(:, i), t);
end
Essentially i have a swept band of signals with diff. frequencies (as indcated by the for loop), and I do have a noise figure value that is consistent for all of the signals I am looking to add the awgn to (noiseamount in my code). However, for every output signal for each "i" respective frequency the output signal happens to be the same exact signal, when I can clearly see that the vector of cursnr has a different value for each value of its array.
Anyone have any solution ideas?
  5 comentarios
Walter Roberson
Walter Roberson el 6 de En. de 2024
It turns out that it is defined to use snr(signals(:, i), noiseamount) and is treated the same as snr(signals(:, i), noiseamount, 6)
Note that noiseamount would be treated as Fs (sampling frequency) in this syntax.
Rohan Gulur
Rohan Gulur el 6 de En. de 2024
So interestingly enough, I took that scalar value for noise that I created and like you mentioned earlier I made an array with the same dimensions of the input signal and filled it like I did below.
arrayofnoise = repmat(amp1.returnnoise(), 1001, 10);
cursnr(:, i)=snr(signals(:, i), arrayofnoise(:, i));
curnoisysignal(:, i)=awgn(signals(:, i), cursnr(:, i));
outputs(:, i) = lsim(sysamp1num1,curnoisysignal(:, i), t);
When I do this, I get a drastically different response in my output signal.

Iniciar sesión para comentar.

Respuesta aceptada

Siraj
Siraj el 9 de En. de 2024
Hi!
It is my understanding that you are processing a collection of signals at various frequencies and wish to consistently introduce the same level of white noise to each. However, despite the distinct SNR values for each frequency, you're observing identical output signals after each iteration, suggesting that the noise is not being added as expected.
This can sometimes occur if the SNR values are set to be really high. When the SNR is high, the added noise level is relatively low compared to the signal strength, which may result in output signals that seem very similar to each other.
Also I understand that the "snr" function can be quite versatile, with several ways to utilize it, and it seems there might be a bit of confusion regarding its usage. Walter Roberson has highlighted similar concerns. The function's behaviour can change depending on the inputs provided, and it might be helpful to review the different forms it can take. Here's a helpful link to the MathWorks documentation that outlines the acceptable inputs for the "snr" function and the default values it assumes when certain inputs are omitted: https://www.mathworks.com/help/signal/ref/snr.html#d126e197964
To assist with clarity, I've put together a simple example. In this example, I've created a set of sinusoidal signals with varying frequencies and a random signal that I'm using to determine the SNR before applying Gaussian noise with the "awgn" function.
rng = 0;
% Define the number of frequencies
numFreqs = 4;
% Create a matrix of signals, one column per frequency
% For this example, let's create sinusoidal signals
t = 0:0.001:1; % time vector
signals = zeros(length(t), numFreqs);
for i = 1:numFreqs
signals(:, i) = sin(2 * pi * i * t); % i Hz signal
end
% Any random signal to calculate snr with
SNR = 20;
randomSignal = randn(size(signals(:,1)))*std(signals(:,1))/db2mag(SNR);
% Preallocate the output matrix
outputs = zeros(size(signals));
for i = 1:numFreqs
curSig = signals(:,i);
cursnr = snr(curSig, randomSignal);
curnoisysignal = awgn(curSig,cursnr);
outputs(:,i) = curnoisysignal;
end
figure;
subplot(2, 1, 1);
plot(t, signals(:, 1));
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2, 1, 2);
plot(t, outputs(:, 1));
title('Noisy Signal');
xlabel('Time (s)');
ylabel('Amplitude');
It's also worth noting that the "awgn" function has its own set of input variations, which can influence its behavior. I encourage you to take a look at the documentation to ensure that the correct parameters are being used for your specific needs. Here's the link to the "awgn" function documentation for your reference:
I hope this helps.

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by