Effacer les filtres
Effacer les filtres

Combine a signal with AM noise

6 vues (au cours des 30 derniers jours)
Ayoub
Ayoub le 23 Sep 2023
Commenté : Star Strider le 23 Sep 2023
i have a signal and i want to add some AM noise to it.
the signal looks like this:
the code for the signal is :
Fs = 1E+9;
L = 2E-6;
t = linspace(0, L*Fs, L*Fs+1)/Fs;
k = log(0.6)/0.2E-6;
s = -4*(exp(k*t) .* sin(2*pi*2.5/5E-7*t));
sd=s.*heaviside(t-0.5E-6);
figure
plot(t, sd,'r','linewidth',1)
grid
the AM noise i'm using made by this code:
duration = 3; % seconds
samplingRate = 8192; % per second
samplingInterval = 1 / samplingRate;
t = 1:samplingInterval:duration;
y1 = cos(2*pi*300*t); % signal
y2 = cos(2*pi*600000*t); % modulating signal (frequency = 600k Hz, adjust as desired)
y2 = rescale(y2,0.25,1); % modulation amplitude min/max factor
y = y1 .* y2; % create amplitude-modulated signal
% plot about 1 second of the signal (to show amplitude modulation)
plot(y(1:9000))
set(gca,'ylim', [-1.2, 1.2]);
i want an AM noise that looks like this one:
them merge the plots into one single plot so the signal gets interfered by AM noise
  2 commentaires
Image Analyst
Image Analyst le 23 Sep 2023
OK. Good luck. What is your actual question, if you have one?
Ayoub
Ayoub le 23 Sep 2023
i mainly want to merge 2 plots into one plot

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 23 Sep 2023
Modifié(e) : Star Strider le 23 Sep 2023
The array sizes are not compatible, and the signals must be sampled at the same rate. That is the problem, because that would require ‘y’ to be upsampled to ‘Fs’ and that:
[yr,tr] = resample(y, t, Fs);
throws this error:
Requested 1x2000122071 (14.9GB) array exceeds maximum array size preference (5.0GB). This might cause MATLAB to become unresponsive.
You need to revise your code so that both vectors are the same sizes, will fit into available memory, and have the desired qualities. Then:
AM = (yr-min(yr(:))) .* sd;
should work to do the A3 (double sideband transmitted carrier) modulation. (I would also change the first ‘t’ to ‘t1’ and the second ‘t’ to ‘t2’ to avoid confusing or overwriting them.)
The plot-within-a-plot is not difficult. You can do that with —
Fs = 1E+9;
L = 2E-6;
t = linspace(0, L*Fs, L*Fs+1)/Fs;
k = log(0.6)/0.2E-6;
s = -4*(exp(k*t) .* sin(2*pi*2.5/5E-7*t));
sd=s.*heaviside(t-0.5E-6);
figure
plot(t, sd,'r','linewidth',1)
grid
y = sum(cos(1000*[300; 600000]*2*pi*t));
AM = (y-min(y(:))) .* sd; % DSB-TC
figure
plot(t, y)
grid
xlabel('Time [\mus]')
ylabel('Amplitude [mV]')
title('AM Radio Interference (‘QRM’)')
xlim([0 2E-7])
ylim([min(ylim) 1.5*max(ylim)])
Ax1 = gca;
pos1 = Ax1.Position;
Ax2 = axes;
Ax2.Position = pos1+[0.32 0.65 -0.35 -0.68];
plot(Ax2, t, AM)
grid
xlabel('Time [\mus]', 'FontSize',7)
ylabel('Amplitude [mV]', 'FontSize',7)
Human-created radio interference is designated in radiotelegraphy as ‘QRM’ while natural interference (‘static’, lightening,etc.), is designated ‘QRN’.
EDIT — (23 Sep 2023 at 16:33)
Changed signal code for second plot, added modulation.
.
  2 commentaires
Ayoub
Ayoub le 23 Sep 2023
i changed the line
plot(y(1:9000))
into thie
plot(y(1:2001))
then extracted the ydata from the plot using this:
a2 = get(gca,'Children');
AMydata = get(a2, 'YData');
then did this last:
[yr,tr] = resample(AMydata, t1, Fs);
AM = (yr-min(yr(:))) .* sd;
plot(AM)
this is a good result for me but i would prefer if the original signal doesn't change but will have extra AM noise on it,
in other words the shape of first plot will have same shape with the other plot on top of it
Star Strider
Star Strider le 23 Sep 2023
See my newly-edited code. I apparently posted it about the same time you posted your latest Comment.
You can use your signals or mine in the plots. All you need to change are the plot arguments to your signals to use them, although you might need to change the xlim call to fit your signals. That xlim call only affects the ‘outer’ plot, not the inset.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by