how to multiply data to the aplitude of each pluse of multiple cycles of a signal??little emergency please reply fast
3 次查看(过去 30 天)
显示 更早的评论
i have a pulse train of 500 cycles of half cycle sinus i need to multiply data(1)*amplitude of first pulse of p ,data[2] *amplitude of second pulse so on.....
please help me out im struggling to solve this from many days its little emergency please help me out ... thanks in advance
fs=44100;
ts=(1/fs);
fc=4000;
tp=2.2676e-3;
for n=1:10
ak=ones(10);
t = 0:ts:n*tp;
p = abs(sin(pi*440*t));
subplot(3,1,2)
plot(t,p)
end
data = randi([0,1],1,10);
采纳的回答
Adam Danz
2019-11-3
编辑:Adam Danz
2019-11-4
Before we get into the solution, here's a few comments about the code.
- Your loop isn't doing anything useful. It's overwritten on each iteration and the final result only shows the last iteration when n=10. So, the code below just shows the results when n=10.
- The amplitude of each peak is clearly 1 +/- some tiny variation.
- Since your 'data' vector is only 0s and 1s and since you're multiplying that by the amplitudes which are all ~1, then the 'data' vector won't change unless you want to account for the tiny variation.
If you'd like to get the actual amplitude of your peaks which include the tiny variations around 1, you can use findpeaks().
% your code, simplified
fs=44100;
ts=(1/fs);
fc=4000;
tp=2.2676e-3;
n = 10;
t = 0:ts:n*tp;
p = abs(sin(pi*440*t));
subplot(3,1,2)
plot(t,p)
data = randi([0,1],1,10);
% Find the amp of each peak
amps = findpeaks(p);
% multiply data(n) and peak(n)
out = data .* amps;
8 个评论
更多回答(1 个)
Shwetha Padmanabha
2019-11-5
1 个评论
Adam Danz
2019-11-5
@ Shwetha Padmanabha, the problem is still very unlcear. I really have no idea what the goals is or the question.
I took a guess at what you're trying to do and added a comment in my answer above. I hope that's helpful. A mini lesson here is the importance of clearly defining a problem and fully understanding it before seeking a solution.
"If I had only one hour to save the world, I would spend fifty-five minutes defining the problem, and only five minutes finding the solution." -Albert Einstein
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!