Earlier I wrote a matlab script to modulate and demodulate an am radio wave and make a .wav file. I did it with a matlab script and it worked alright.
Now I'm trying to do the same thing, but I'm calling simulink from a script. The problem I'm having is that I'm only getting a 48 byte wav file at the end of my script. In my first script my wav file was 40Mb. Is anyone here familiar with simulink? Here's my code. I can put my simulink model up if necessary.
Rich (BB code):
close all;
clear all;
fs = 2e6;
t = [0:1/fs:5];
f_cut_off1 = 10000;
f_cut_off2 = 10;
f = 2000; %input frequency
fc = 940e3; %carrier frequency
k = length(t);
input_sig = (0.2)*cos(2 * pi * f * t); %input signal
wavwrite(input_sig,fs,32,'input_sig');
carrier_sig = (0.5)*cos( 2 * pi * fc * t); %carrier signal
mod_sig = input_sig .* carrier_sig + carrier_sig; %modulated signal
%interval to randonize noise
noise = rand(1, k) - .5; %random nosie
new_mod = mod_sig + noise; % mod signal + noise
%Apply HW Rectifier
for i = 1:k
if new_mod(i) <= 0
x(i) = 0;
else
x(i) = new_mod(i);
end
end
rc1 = 1 / (2 * pi * f_cut_off1);
rc2 = 1 / (2 * pi * f_cut_off2);
%Apply Low Pass Filter
num2 = [0 1];
den2 = [rc1 1];
subplot(324), bode(num2, den2)
sys2 = tf(num2, den2);
lpf = lsim(sys2, x, t);
%Apply High Pass Filter
num1 = [rc2 0];
den1 = [rc2 1];
sys1 = tf(num1, den1);
hpf = lsim(sys1, lpf, t);
vout = hpf;
%Apply Convolution
g = 20;
h = (1 / g) * ones(1, g);
y = conv(h ,vout);
wavwrite(y,fs,32,'vout')
Rich (BB code):
clear all
clc
fs = 2e6;
t = [0:1/fs:5];
t = t';
f_cut_off1 = 10000;
f_cut_off2 = 10;
f = 2000; %input frequency
fc = 940e3; %carrier frequency
%k = 1;%length(t);
rc1 = 1 / (2 * pi * f_cut_off1);
rc2 = 1 / (2 * pi * f_cut_off2);
input_sig = 1*cos(2 * pi * f * t); %input signal
input_sig1 = [t'; input_sig'];
save('input_sig1.mat', 'input_sig1');
carrier_sig = 1*cos( 2 * pi * fc * t); %carrier signal
carrier_sig1 = [t' ; carrier_sig'];
save('carrier_sig1.mat', 'carrier_sig1');
load_system('am_mod_simulinkORIGINAL');
set_param('am_mod_simulinkORIGINAL','Stoptime',num2str(t(size(t,1),1)));
set_param('am_mod_simulinkORIGINAL/LPF', 'Numerator', '[0 1]');
den1 = strcat('[',num2str(rc1),',','1',']')
set_param('am_mod_simulinkORIGINAL/LPF', 'Denominator', den1);
den2 = strcat('[',num2str(rc2),',','1',']')
set_param('am_mod_simulinkORIGINAL/HPF', 'Denominator', den2);
num2 = strcat('[',num2str(rc2),',','0',']')
set_param('am_mod_simulinkORIGINAL/HPF', 'Numerator', num2);
save_system('am_mod_simulinkORIGINAL');
sim('am_mod_simulinkORIGINAL');
p = load('outputsignal.mat');
data = p.ans;
g=20;
h = (1 / g) * ones(1, g);
y = conv(h ,data(2,:));
wavwrite('y',fs,32,'out_sig');