How do I calculate power for each signal?
33 次查看(过去 30 天)
显示 更早的评论
So, I have an audio signal with fs=8192 and total samples=73113, which gives the total duration of the signal as 8.9249 seconds. My aim is to calculate the power of this signal for each second and plot it. Basically what I mean is to calculate the power of signal between 0th sec and 1st second and so on and then plot them with time on x axis. I tried calculating power element wise but I am not getting element wise power using "power=rms(y_b).^2", I am not getting correct vector so I am unable to move forward, I cannot think of a way, can someone plese help.
[y,fs]=audioread('h.wav');
y_b=bandpass(y,[300 2000],fs);
N=length(y);
time=N/fs;
t = linspace(0, time, N);
subplot(2,1,1);
plot (t,y_b);
% how to calculate power for each signal?
%....code....
subplot (2,1,2);
plot(time1,power);
Thank you
0 个评论
采纳的回答
Star Strider
2021-4-28
编辑:Star Strider
2021-4-28
Use the buffer function to segment the signal into 1-second increments. Since you want 1-second samples, the vector length is simply ‘Fs’, so —
y = randn(73113,1); % Create Signal To Test Code (One Channel)
fs = 8192; % Sampling Frequency (Also Frame Length)
N = size(y,1); % Signal Length
time = linspace(0, N, N-1)/fs; % Time Vector
y_b = bandpass(y,[300 2000],fs); % Filter Signal
y_seg = buffer(y_b,fs); % Matrix Of Signal Segments
y_pwr = sum(y_seg.^2); % Calculate Power
figure
for k = 1:numel(y_pwr)-1
tv = time((1:fs)+fs*(k-1));
subplot(5,2,k)
plot(tv,y_seg(:,k))
grid
title(sprintf('Segment %d Power %.1f',k,y_pwr(k)))
end
subplot(5,2,k+1)
tv = time(fs*k:end);
plot(tv,y_seg(1:numel(tv),k+1))
grid
title(sprintf('Segment %d Power %.1f',k+1,y_pwr(k+1)))
EDIT — (28 Apr 2021 at 12:40)
Corrected typoographical error.
5 个评论
Star Strider
2021-4-29
Since I am not certain how your code plotted them, the easy solution is to use xticklabels to change the labels. Alternatively, a stairs or bar plot (either of which would likely be more representative, anyway) could work, perhaps in addition to the xticklables change.
更多回答(1 个)
Mathieu NOE
2021-4-28
hello
if you want to compute a running rms value , you can use the movstd function - see help movstd
and use K = fs=8192 to average the computation over 1 second interval;
movstd Moving standard deviation value.
Y = movstd(X,K) for a vector X and positive integer scalar K computes a
centered moving standard deviation by sliding a window of length K
along X. Each element of Y is the local standard deviation of the
corresponding values of X inside the window, with Y the same size as X.
When K is even, the window is centered about the current and previous
elements of X. The sliding window is truncated at the endpoints where
there are fewer than K elements from X to fill the window.
now this will give you a rms calculation with the same time increment as your data, you can decide afterwards to plot only values with 1 second interval (so index values multiple of fs = 8192 )
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!