Power Spectrum Plotting of a Signal

12 vues (au cours des 30 derniers jours)
Parth T.A.
Parth T.A. le 27 Juil 2020
I need to plot a power (y axis) vs frequency (x axis) graph to represent the power spectrum of a signal. Something looking like this:
Here is my code:
LFP = doFilter(Signal);
sampling_rate = 1000;
length_LFP = length(LFP);
time = [0:1:length_LFP-1] * (1/sampling_rate);
figure;
plot(time, LFP);
for i = 1:length(LFP) %filtering out certain values
if abs(LFP(i))>5900
LFP(i) = 0;
end
end
figure;
plot(time, LFP);
ylim([-30000 20000]);
figure;
pwelch(LFP, [], [], [], sampling_rate);
function y = doFilter(x)
%DOFILTER Filters input x and returns output y.
% MATLAB Code
% Generated by MATLAB(R) 9.8 and DSP System Toolbox 9.10.
% Generated on: 27-Jul-2020 14:11:04
%#codegen
% To generate C/C++ code from this function use the codegen command.
% Type 'help codegen' for more information.
persistent Hd;
if isempty(Hd)
% The following code was used to design the filter coefficients:
%
% N = 2; % Order
% F3dB1 = 0.1; % First
% F3dB2 = 100; % Second
% Fs = 1000; % Sampling Frequency
%
% h = fdesign.bandpass('n,f3db1,f3db2', N, F3dB1, F3dB2, Fs);
%
% Hd = design(h, 'butter', ...
% 'SystemObject', true);
Hd = dsp.BiquadFilter( ...
'Structure', 'Direct form II', ...
'SOSMatrix', [1 0 -1 1 -1.50961300935918 0.509921232956256], ...
'ScaleValues', [0.245039383521872; 1]);
end
s = double(x);
y = step(Hd,s);
end
I am unable to get power (in V) on the y axis. How can I rectify this?

Réponse acceptée

Surya Talluri
Surya Talluri le 13 Août 2020
I understand that you want to plot the power spectrum using pwelch. It can be achieved by mentioning spectrumtype input of "pwelch” function to ‘power’.
pwelch(LFP, [], [], [], sampling_rate, 'power');
Default units of power spectrum is dB. You can save the spectrum to a variable and then change the units.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by