how to multiply data to the aplitude of each pluse of multiple cycles of a signal??little emergency please reply fast

2 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Adam Danz
Adam Danz el 3 de Nov. de 2019
Editada: Adam Danz el 4 de Nov. de 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 comentarios

Iniciar sesión para comentar.

Más respuestas (1)

Shwetha Padmanabha
Shwetha Padmanabha el 5 de Nov. de 2019
this represent the pulse train
pulse.png
clc;
clear all;
close all;
fs=44100;
ts=(1/fs);
fc=4000;
tp=2.2676e-3;
tsingle = 0:ts:tp;
for n=1:500
t = 0:ts:n*tp;
p = abs(sin(pi*440*t));
subplot(3,1,2)
plot(t,p)
end
data = randi([0,1],1,20);
a=[];
for k=1:2:20
if data(k)==0 && data(k+1)==0
a=[a 1+i];
elseif data(k)==0 && data(k+1)==1
a=[a -1+i];
elseif data(k)==1 && data(k+1)==0
a=[a -1-i];
elseif data(k)==1 && data(k+1)==1
a=[a 1+i];
end
end
well let me be clear this the actual code each pulse should carry one symboli.e. is 'a' tried all possible ways i couldnt solve even ohers couldnt deadline is near it would be great help if you cansolve
  1 comentario
Adam Danz
Adam Danz el 5 de Nov. de 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

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by