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;
댓글 수: 0
답변 (3개)
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
Charlotte Anderson
2020년 11월 4일
Could you explain why you chose those values to input into the linspace function?
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
2021년 8월 1일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!