Power Spectrum Plotting of a Signal

12 次查看(过去 30 天)
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?

采纳的回答

Surya Talluri
Surya Talluri 2020-8-13
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by