Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Please, help to draw plot between

1 vue (au cours des 30 derniers jours)
EDAN
EDAN le 2 Déc 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi, I wonder why this code occur error and how can i fix this code to make AM modulate.
I think sampling is the problem for this case.
---------code------
% wavread
[m,f]=wavread('test.wav');
% time
dt = 1/f; % sampling Time
t = (1:dt:1000); % t axis; I don't know what i set
% Define carrier frequency and amplitude for modulation
fc = 1000;
Ac = 1;
c = Ac * cos(2*pi*fc*t); % Carrier wave, unmodulated
% AM modulation
ka = 0.009;
sAM = (1 + ka*m).* c;
plot(t,sAM)

Réponses (2)

Laura Proctor
Laura Proctor le 2 Déc 2013
There seemed to be an issue with the dimensions of variables m and c. The following code shouldn't error.
% wavread
[m,f]=wavread('test.wav');
% time
dt = 1/f; % sampling Time
tf = dt*(length(m)-1);
t = (0:dt:tf)';
% Define carrier frequency and amplitude for modulation
fc = 1000;
Ac = 1;
c = Ac * cos(2*pi*fc*t); % Carrier wave, unmodulated
% AM modulation
ka = 0.009;
sAM = (1 + ka*m).* c;
plot(t,sAM)
  1 commentaire
EDAN
EDAN le 2 Déc 2013
Modifié(e) : EDAN le 2 Déc 2013
thanks! yet, this code occur error...I could not solve this dimensions problem. how about you?

Walter Roberson
Walter Roberson le 2 Déc 2013
wavread() returns a matrix which going down is samples and going across is channels.
Your code does not account for multiple channels.
Your code tries to do an element-by-element multiplication between "m", the actual samples, and t, which has been created as if there are 999 seconds worth of samples, plus one extra. For example if f = 4, dt = 1/4, then 1:dt:2 would be [1 5/4 3/2 7/4 2] which would be 1 second (2-1) of data plus one extra sample. The length of t should instead be determined by the number of samples. Try
t = (0:size(m,1)-1) ./ f;

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by