Clear Filters
Clear Filters

Converting discrete signal to frequency domain

7 views (last 30 days)
Hi i am new to Matlab. My question is if i have a discrete signal (experiment data) stored in a variable like
onetrial = 1x200;
sampled a frequency of 100hz. How can i convert it into frequency domain and plot it.
Also how can i go about plotting its PSD(power spectral density)?
Thanks in advance.

Accepted Answer

Star Strider
Star Strider on 7 May 2022
The fft calculation an plotting is straightforward. (You can also use the pspectrum function and others.)
Fs = 100;
Fn = Fs/2;
Ts = 1/Fs;
t = linspace(0, 199, 200)/Fs; % Time Vector
onetrial = sin(2*pi*10*t) + randn(1,200)*0.1; % Signal Vector
L = numel(t);
NFFT = 2^nextpow2(L); % Fourier Transform Length Power-Of-Two For Efficiency
FT_onetrial = fft(onetrial - mean(onetrial), NFFT)/L; % Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FT_onetrial(Iv))-2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
To calculate the PSD there are several options, one of which is the pwelch function.
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!