MATLAB Answers

Please, help to draw plot between

1 view (last 30 days)
EDAN
EDAN on 2 Dec 2013
Answered: Walter Roberson on 2 Dec 2013
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)

Answers (2)

Laura Proctor
Laura Proctor on 2 Dec 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 Comment
EDAN
EDAN on 2 Dec 2013
thanks! yet, this code occur error...I could not solve this dimensions problem. how about you?

Sign in to comment.


Walter Roberson
Walter Roberson on 2 Dec 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

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!