How can I remove negative values from vector (Half-Wave Rectification)

8 次查看(过去 30 天)
I need help removing the negative values from a vector. I I started with an EMG signal and converted the signal from the time domain to the frequency domain using fft. Next I applied a bandpass filter from 25-400 Hz to get a filtered signal. Now I need to apply a half wave rectification. I would like to use a for loop to remove the ngative values from v_mag_filtered. I'd appreciate the help, I'm a bit rusty on MATLAB
% Time Signal
max_index = 10000;
freq = 960;
t_step = 1/freq;
for i = 1:max_index
t(i) = (i-1)*t_step;
v(i) = EMG(i) * 1E-6;
end
% Power spectrum
for i = 1:max_index
freq_range(i) = (1/t_step)*(i-1)/max_index;
end
v_freq = fft(v,max_index); %complex vector of ECG singal
v_mag = 2*v_freq.*conj(v_freq)/(max_index)^2; %phase information of complex number removed
x = freq_range(1:max_index/2);
y = v_mag(1:max_index/2);
%band pass filter
v_freq_filtered = v_freq;
for i = 1:max_index
if ((freq_range(i)<25))
v_freq_filtered(i) = 0.0;
end
if ((freq_range(i)>400))
v_freq_filtered(i) = 0.0;
end
end
v_mag_filtered = 2*v_freq_filtered.*conj(v_freq_filtered)/(max_index)^2;

回答(3 个)

madhan ravi
madhan ravi 2020-11-3
vector = [1, -1];
vector( vector < 0 ) = 0 % [] to remove

Star Strider
Star Strider 2020-11-3
Try this:
t = linspace(0, 6*pi, 1E+5);
s = sin(t);
idx = s >= 0; % Conditional Logical Index
s_hwr = s.*idx; % Signal With Half-Wave Rectification
figure
plot(t, s_hwr)
grid
ylim([-1 1])
This will work regardless of your signal. Since ‘EMG’ is not provided, I use ‘s’ instead here.
  2 个评论
Star Strider
Star Strider 2020-11-4
Sure!
I chose 3 cycles to provide a representative waveform, and elements to produce a smooth plot. All of these (in this example) are arbitrary, so choose whatever values you want (within reason, and within the available memory capacity of your computer) to experiment with.

请先登录,再进行评论。


m.venkata manohar reddy
Find the Fourier series of the function obtained by
passing the sinusoidal voltage v(t) = v0 cos(100πt)
through a half wave rectifier given in figure that clips
the negative waves

类别

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