# Determining highest power frequency in noise signal

4 views (last 30 days)
Walter Cromer on 26 Jul 2022
Commented: Walter Cromer on 27 Jul 2022
I am a newbie to signal analysis with Matlab. I have voltage data in a CSV file. I want to use MatLab to identify the predominate frequency in the noise so I can design filtering to remove it. Generally, our SNR is ok for this application but sometimes we get big jumps in the noise and the SNR is not ok then. (We are simultaneously trying to figure out the source of this noise and eliminate it.)
I've tried to use some code posted by others in their questions but my results show that there isn't really a predominate frequency in the noise. But being a newbie, I'm not sure if I did this correctly. I would greatly appreciate review and comment to confirm that this is correct please.
The CSV data file is attached.
Here is my code...
T = readtable('{full path omitted}\Analog - 7-25-2022 2-41-32.623 PM for MatLab.csv','Delimiter',',');
plot(T.AI0)
T2 = T(65000:75000,:); % grab subset of readings where noise increases and SNR is unacceptable.
%plot(T2.AI0)
fs = 100; %sampling frequency
n = length(T2.AI0); % number of samples
T2.AI0 = T2.AI0 - mean(T.AI0);
Y = fft(T2.AI0);
P2 = abs(Y/n);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(n/2))/n; % frequency range
plot(f,P1)
Here is the first plot. This is the full data set. Here is the subset of data. Finally, here is the last plot. It looks like the highest power is at 0 (DC). If I could remove it, then I'd potentially see some of the other frequencies at higher powers but still nothing that just stands out as a major player.
I appreciate any help or thoughts on this! Again, a newbie so please be kind.
##### 2 CommentsShowHide 1 older comment
Walter Cromer on 27 Jul 2022
Thank you!

Paul on 27 Jul 2022
Edited: Paul on 27 Jul 2022
Hi Walter,
The original code in the question subtracted the mean of the entire signal (T), not the mean of just the portion to be analyzed (T2), which results in that big peak at 0. Also, in the code below I just plotted the output of FFT, because it sounds like you're just trying to find the dominant frequencies, so that other scaling (divide by n, mutliply by 2) doesn't really do anything in a relative sense.
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
figure
plot(T.AI0) T2 = T(65000:75000,:); % grab subset of readings where noise increases and SNR is unacceptable.
figure
plot(T2.AI0) fs = 100; %sampling frequency
n = length(T2.AI0); % number of samples
%T2.AI0 = T2.AI0 - mean(T.AI0);
T2.AI0 = T2.AI0 - mean(T2.AI0);
Y = fft(T2.AI0);
%P2 = abs(Y/n);
%P1 = P2(1:n/2+1);
%P1(2:end-1) = 2*P1(2:end-1);
%f = fs*(0:(n/2))/n; % frequency range
f = (0:(n-1))/n*fs;
figure
plot(f,abs(Y))
xlim([0 50]) Can also experiment with functions like spectrogram to try and see how the frequencies change with time.
figure
spectrogram(T.AI0-mean(T.AI0),128,[],128,fs);
xlim([0 50]) ##### 1 CommentShowHide None
Walter Cromer on 27 Jul 2022
Thank you so much! This has been very helpful and it is giving me what I was looking for now! I appreciate your kind assistance!

R2022a

### Community Treasure Hunt

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

Start Hunting!