How to calculate the SNR of SSVEP signal after Fourier transform?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Is there any problem with my code, as shown in the following figure, why can't I get the same result?I take the oz channel and use FFT to calculate the amplitude of the EEG signal. How to find the SNR below?
sig_raw=data(:,1);
fs=1000;
figure;
N = length(sig_raw);
n = 0:N-1;
x = fft(sig_raw);
mag = abs(x);
f = n * fs / N;
fre = f(1:N/2);
y = mag(1:N/2)*2/N ;
power_spectrum=mag(1:N/2).^2;
p=10*log(power_spectrum);
plot(fre, p, 'linewidth', 1);
0 Commenti
Risposte (1)
William Rose
il 19 Dic 2023
YOu say "why can't I get the same result?" Please explain more clearly what thing is not the same as what other thing.
The figure you posted has four panels. Your code make a single panel figure, so of course they are not the same. Did you generate the figure you posted? If yes, please provide the source code and data. If you did not generate the figure you posted, then explain where it came from.
We cannot tell from your posting how the SNR spectra in the lower panels was calculated. It appears that the SNR spectra in the lower panels could be simply the amplitude spectra from the upper panels, converted to dB. If so, that is an unusual definition of SNR, to say the least.
Provide your data ("data(:,1)") so that others can run your code.
Your code computes and plots the 2-sided spectrum. The figure you posted shows a 1-sided spectrum.
Since your sampling rate is fs=1000, your single sided spectra will go to 500 Hz. The spectra you plotted only extend to 60 Hz. You can use xlim([0,60]) to make plots that display the same frequency range as the figure you posted.
Subtract the mean value from the signal, before computing its fft, otherwise you may get a component at freq=0 that is much larger than the rest of the spectrum. Of course this will not be a problem if the signal already has mean=0.
If it is true that the plotted SNR is just the dB version of the power spectrum corresponding to the amplitude spectrum, then you can get a figure similar to the plotted figures by making two plots of single sided spectra: one is the amplitude spectrum and one is the power spectrum, expressed in dB.
The single sided power spectrum has twice the power of the one-sided spectrum at all frequencies except freq=0 and freq=fs/2. At f=0 and f=fs/2, the single-sided and two-sided spectra have the same power.
2 Commenti
William Rose
il 20 Dic 2023
Modificato: William Rose
il 20 Dic 2023
[edit: correct spelling errors]
It would help if you provide the paper itself, or a web link to the paper, so that others can see how the authors defined the signal to noise ratio.
You define the SNR as a spectrum. That is unusual. In my experience, SNR may be calculated at a target frequency - the frequency of the signal of interest. Therefore your way of computing SNR is unfamiliar to me.
The second thing about your calculation that is unusual is that you never compute a ratio. The R in SNR is for ratio. Therefore, if it is valid to define SNR as a spectrum, then the SNR spectrum will be the ratio of the signal power at each frequency to noise power at the same frequency. But you never take a ratio. You just compute the power spectrum of sig_raw, convert it to dB units, and call it the SNR. I have never seen SNR defined that way.
The third thing about your calculation that is unusual is related to the second thing. Since you do not take a ratio, the SNR you compute will change, if you change the units of measurement. For example, if you convert sig_raw from uV to V, by dividing sig_raw by 10^6, the SNR you compute will be 120 dB lower, even though nothing about your data has changed except the units in which it is reported. This is clearly an error.
The least important concern I have about your SNR calculation is that, when you convert to dB, you should use log10(power_spectrum), not log(power_spectrum), because decibels are defined using log base 10.
I am trying to provide constructive advice. I'm sorry if it sounds negative.
Vedere anche
Categorie
Scopri di più su EEG/MEG/ECoG in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!