How to calculate user defined SNR, given only sampling frequency and a vector containing signal samples? - matlab

So I have the samples (hex values) of a sinus signal and I know the sampling frequency. Using this I can plot an fft or periodogram but then I would like to find out the SNR ratio. What would be the most accurate way to calculate the noise and signal power? I would prefer doing it in frequency domain. Is there a way to do this also in time domain?
Thanks a lot in advance!!!

So if there is noise on your signal and you know that your underlying signal is a sine wave, you can easily get your signal parameters i.e. amplitude,frequency and phase by least squares. If y(t) is your signal just minimize the L2 norm of (y(t)-A.sin(wt+b)) over A,w and b. Then you can easily get signal power from the underlying signal and the noise power from the error signal (y(t)-A.sin(wt+b)).

Related

SNR of original signal and quantized signal - MATLAB

If I wanted to get the SNR of a quantized audio signal, would I subtract the quantized signal from the original (which would give me the noise?) and then calculate the power of this noise and compare it to the power of the original signal?
Such as, SNR(dB)=10*log(original power/noise power)
Yes, that is the quantization noise. It is not just “noise” because the input has noise as well, and you don’t include that noise in your result.

Noise Comparison in MATLAB

Assuming I have two signals (raw data as excel file) measured from two different power supplies, I want to compare the noise-levels of these signals to find out which one of them the noisier one. Both power supplies produce signals with the same frequency but the amount of data points are different. Is there a way to do this in MATLAB?
You could calculate the signal-to-noise ratio for each signal. This is just a ratio of the average signal power and average noise power, usually measured in decibels. An ideal noiseless signal would have SNR = infinity.
Recall that signal power is just the square of the signal amplitude, and to get the value x in decibels, we just take 10*log10(x).
SNR = 10*log10( mean(signal.^2)/mean(noise.^2) );
To separate the signal from the noise, you could run a low-pass filter over the noisy signal.
To get the noise you could just subtract the clean signal from the noisy signal.
noise = noisy_signal - signal;

Strengthening the low amplitude signal using Matlab WITHOUT changing the original shape of the signal

I have a problem in signal processing with Matlab.
I would like to analyze some signal using Matlab but there is a huge difference between the amplitude of signals.
The problem is that the shape of the signal in low amplitude is similar to the shape of the signal in high amplitude. but to analyse the signal, I have to have same range amplitude signal.
how can I have that without destroying the shape and properties of the signal?
Sorry I couldn't send an example plot to clear that.
Something like:
signal1;
signal2;
signal1=(signal1- min(signal1(:))/(max(signal1(:))-min(signal1(:)))
signal2=(signal2- min(signal2(:))/(max(signal2(:))-min(signal2(:)))
% Now both signals are 0-1 range
Without more information this is all what we can offer!

How can filter data to remove noise in matlab?

I have 2 arrays of 800000 input and output data samples of a system. The system in a kind of oven that works among 0 and 10 volts. The sample time is 0.001s.
I have to identify the model of this system, but first of all, given that the data are clearly dirty, I would like to filter the noise.
How can I do it with the System Identification Toolbox of Matlab?
Moreover, how can I estimate the cutoff frequency to remove the noise?
Thank you in advance.
PS: given that this is a bit out of topic, please, post your answer here thank you.
The cutoff frequency is directly given by you sampling time or sampling frequency.
you sampling frequency is 1/(sampling time) and must at least 2 the factor of the highest frequency of interest:
http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem
f_s = 1/T_s >= 2*f_cutOff
You can then simply to same frequency domain processing in the case you sampling frequency is realy high enough. The easiest way would to have a look at the frequency domain (with function fft() ). And check first where you have high noise components. Then filter out these components (zeroing) and then transform it back into time domain ( with function ifft() ).
Noise is modeled as a white Gaussian distribution in the simplest case. If you estimate the noise energy, you can make a dummy noise by calling
noise = A*randn(1,N);
Here, A is the amplitude and N is the sample count. then just take the fft of this signal and subtract it from the fft of input signal and take the inverse fft (ifft)

How to get coefficients for sine/cosine function from complex FFT in Matlab?

I'm working on a control system that measures the movement of a vibrating robot arm. Because there is some deadtime, I need to look into the future of the somewhat noisy signal.
My idea was to use the frequencies in the sampled signal and produce a fourier function that could be used for extrapolation.
My question: I already have the FFT of the signal vector (containing 60-100 values e.g.) and can see the main frequencies in the amplitude spectrum. Now I want to have a function f(t) which fits to the signal, removes some noise, and can be used to predict the near future of the signal. How do I calculate the coefficients for the sine/cosine functions out of the complex FFT data?
Thank you so much!
AFAIR FFT essentially produces output as a sum of sine functions with different frequencies. The importance of each frequency is the height of each peak. So what you really want to do here is filter out some frequencies (ie. high frequencies for the arm to move gently) and then come back to the time domain.
In matlab this should be like going through the vector of what you got from fft, setting some values to 0 (or doing something more complex to it) and then use ifft to come back to time domain and make the prediction based on what you get.
There's also one thing you should consider while doing this - Nyquist frequency - this means that the highest frequency that you get on your fft is half of the sampling frequency.
If you use an FFT for data that isn't periodic within the FFT aperture length, then you may need to use a window to reduce spurious frequencies due to "spectral leakage". Frequency estimation techniques to better estimate "between bin" frequency content may also be appropriate. The phase of each cosine sinusoid, relative to the edge of the window, is usually atan2(imag[i], real[i]). The frequency depends on the sample rate and bin number versus the length of the FFT.
You might also want to look into using a Kalman filter instead of an FFT.
Added: If your signal isn't exactly integer periodic in the FFT length, then you may want to do an fftshift before the FFT to move the resulting phase measurement reference point to the center of your data vector, instead of a possibly discontinuous circular edge.