How to find the noisy signal using fourier transform for this data?

I was given the values M3 and t and told to analyze the noisy signal for every 5Hz, please check attached the values.

Answers (1)

Here's what I put together. The input signal is somewhat noisy, but it is also periodic @ 34.4 Hz.
f = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/684143/SPEED%20SENSOR.xlsx';
A = readmatrix(f);
t = A(:,2);
y = A(:,1); % M3 sensor values
n = length(y);
% remove NANs
nanLogical = isnan(t) | isnan(y);
t(nanLogical) = [];
y(nanLogical) = [];
% recale signal to +/- 1
y = rescale(y, -1, 1);
% determine sampling interval and rate
sInterval = mean(diff(t));
sRate = 1 / sInterval;
% perform fast fourier transform
Y = fft(y);
% get frequency spectrum
P2 = abs(Y/n);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sRate*(0:(n/2))/n;
% plot signal and frequency spectrum
tiledlayout('flow');
nexttile;
plot(y(1:500)); % first 500 samples only (so wavefrom is visible)
title('Signal');
nexttile;
plot(f,P1);
title('Frequency Spectrum');

6 Comments

Its giving me the following:
Warning: Integer operands are required for colon operator when used as index.
> In sensoranalyzing (line 19)
Undefined function or variable 'tiledlayout'.
Error in sensoranalyzing (line 23)
tiledlayout('flow');
tiledlayout was introduced in R2019a. I supposed you are running an older version of MATLAB. To use subplot (the predecessor of tiledlayout), change the plotting section of the script to...
% plot signal and frequency spectrum
subplot(2,1,1)
plot(y(1:500)); % first 500 samples only (so wavefrom is visible)
title('Signal');
subplot(2,1,2);
plot(f,P1);
title('Frequency Spectrum');
Thank you, I will share this result with the person who assigned this to me, and will come back to you incase of any further questions.
Could you please explain the frequency spectrum code that you wrote?
The two plots actually contain the same information but with a different perspective.
The top plot is a "time domain" plot, with the x-axis representing time and y-axis representing the amplitude of the signal at each time point. To improve the look of the plot, I only plotted the 1st 500 samples. There are actually 70,000+ samples in total.
The bottom plot is a "frequency domain" plot of the same signal. The sampling frequency for your sensor was 100 Hz, so the x-axis of this plot goes from 0 to half this, or 50 Hz. The y-axis is the amplitude of the signal at each frequency. You can see some noise along the bottom, but there is a big spike at 34.4 Hz. This means the signal includes a periodic waveform at that frequency.
As for the code generating the frequency spectrum plot, it's mostly just copied from the examples in the documentation for the fft function. Have look there if you want the play-by-play details.
BTW, what is your sensor measuring?
I hope I am not too late here,
Can you tell me how do I find noise if I don't have the time stamps of the data? I only have recorded data from the sensor but the signal is noisy and now I discovered that I need time stamps to use FFT is there any work around for that?

Sign in to comment.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Asked:

on 14 Jul 2021

Commented:

on 26 Aug 2022

Community Treasure Hunt

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

Start Hunting!