how to multiply data to the aplitude of each pluse of multiple cycles of a signal??little emergency please reply fast
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shwetha Padmanabha
le 3 Nov 2019
Modifié(e) : Adam Danz
le 15 Nov 2019
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);
Réponse acceptée
Adam Danz
le 3 Nov 2019
Modifié(e) : Adam Danz
le 4 Nov 2019
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 commentaires
Plus de réponses (1)
Shwetha Padmanabha
le 5 Nov 2019
1 commentaire
Adam Danz
le 5 Nov 2019
@ 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
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!