cannot demodulate correctly, what am I doing wrong?
Show older comments
clear
close all
clc
%% defines the functions and their periods
syms t n t1 t2
One(t1,t2) = heaviside(t-t1) - heaviside(t-t2);
u(t) = heaviside(t);
r(t) = t*u(t);
A = 1;
t0 = 1;
m1 = A/(5-t0);
m2 = -A/t0;
m3 = -A/(5-t0);
m4 = A/t0;
y = m1*(r(t)-r(t-(5-t0)) ) + m2*(r(t-(5-t0))-r(t-5) ) + m3*(r(t-5)-r(t-(10-t0))) + m4*(r(t-(10-t0))-r(t-10));
T = 10;
I = [ 0 T ]; % Intervals per row
figure
fplot( t , y , [0 , T] )
title('Original Function')
xlabel('t')
ylabel('v(t)')
grid minor
%% Complex form
% Number of harmonics
N = 24;
for i = 1 : length(T)
% The symbolic Coefficients
Cn(i) = (1/T(i))*int(y(i)*exp(-1j*(2*pi*n*t/T(i))), t, I(i,1), I(i,2));
for j = 1 : 2*N+1
nj = -N+(j-1); % it goes from -N to N passing through 0
w0i = 2*pi/T(i);
% The numeric Coefficients
CnV(i,j) = eval(limit( Cn(i) , n , nj ));
if nj < 0
Exp(i,j) = 2*abs(CnV(i,j))*cos( -w0i*nj*t - angle(CnV(i,j)) );
end
end
% The fourier series is coseine expresion, [-N,-N+1,-N+2,...]
FS(i) = sum( Exp(i,:) ) + CnV(i,N+1);
end
%%plots the frequency spectrum and the fourier signal
figure
subplot(2,2,[1,3])
fplot( t , FS(1) )
title('Fourier signal')
xlabel('time')
ylabel('Signal')
grid minor
subplot(2,2,2)
stem( -N:N , abs(CnV(1,:)) )
title('Magnitude')
xlabel('n')
ylabel('|C_n|')
grid minor
subplot(2,2,4)
stem( -N:N , angle(CnV(1,:)) )
title('Phase')
xlabel('n')
ylabel('\angle C_n')
grid minor
Am=5; % Amplitude of modulating signal
fa=2000; % Frequency of modulating signal
fc =10*fa;
Ta=1/fa; % Time period of modulating signal
t=0:Ta/999:6*Ta; % Total time for simulation
ym=Am*cos(2*pi*fa*t); % Equation of modulating signal
figure(3);
subplot(3,1,1);
plot(t,ym), grid minor;
title ('Carrier Signal');
xlabel ('Time(sec)');
ylabel ('Amplitude(V)');
m =.5;
Ac=eval(FS);
y=Ac.*(1+m.*sin(2*pi*fa.*t)).*sin(2*pi*fc.*t);
%modulated signal
subplot(3,1,2);
plot(t,y);
title ('Modulated Signal');
xlabel ('Time(sec)');
ylabel ('Amplitude(V)');
grid minor;
md = y.*(cos(2*pi*fc.*t));
[b,a]= butter(2,0.1);
mf = filter(b,a,md);
subplot(3,1,3);
grid("minor");
plot(t,mf);
fs=45e3;
x = y.*cos(2*pi*fc*t);
[b,a] = butter(5,fc/fs);
x = filtfilt(b,a,x);
figure(4);
plot(t,x)
grid("minor")
xx = demod(y,fc,fs,"amssb");
figure(5);
plot(t,xx);
1 Comment
Arrian Esteki
on 6 Dec 2021
Answers (0)
Categories
Find more on Waveform Generation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!