MSK

Modulace PAM #1 - jednorozměrná
clc
clear all
close all

% parametry pro vykresleni
font_size = 16;
font_size_label = 18;

T_max = 1e-3; % doba trvani simulace [s]
Fs = 50e6; % vzorkovaci frekvence [Hz]
Tpulzu = 10e-6; % doba trvani pulzu [s]
Fzdvih = 1e6; % frekvencni zdvih pro Linearni Frekvencni Modulaci [Hz]

Ts = 10e-6; % doba trvani jednoho symbolu
Tr = 100e-6; % doba trvani jednoho ramce

n_Ts = round(Ts * Fs); % pocet vzorku v jednom datovem intervalu
n_Tr = round(Tr * Fs); % pocet vzorku v jednom ramci 

n_data = round(n_Tr / n_Ts);
bit = randi([0, 1], n_data, 1); % vygenerovani uniformne rozlozenych n-pocet bitu
% bit = [0, 1]
t_axis = 0 : 1/Fs : (Tr - 1/Fs); % casova osa
no_samples = length(t_axis);


q = bit;


%%% FFSK
for ii = 1 : n_data
 dolni_mez = ((ii-1) * n_Ts + 1);
 horni_mez = ii * n_Ts; % n_Ts je pocet vzorku v jednom Ts
 if q(ii) == 0
 A1(dolni_mez : horni_mez) = 1;
 A2(dolni_mez : horni_mez) = 0;
 else
 A1(dolni_mez : horni_mez) = 0;
 A2(dolni_mez : horni_mez) = 1;
 end
end

%% MSK
f1 = 10 * 1/(2*Tpulzu);
f2 = 11 * 1/(2*Tpulzu);
faze = 0;

t = t_axis;
s_msk = A1.*sin(2*pi*t*f1) + A2.*sin(2*pi*t*f2 + faze );

S= 10*log10((abs(fftshift(fft(s_msk)))).^2);% energetické spektrum signálu 
fx = Fs/2 * linspace(-1,1,length(s_msk)); 

figure;
subplot(2,1,1); plot(t,s_msk); title('MSK'); xlabel('t [s]'); ylabel('A [V]');
subplot(2,1,2); plot(fx,S); title('Spektrum');xlabel('f [Hz]'); ylabel('Se [dB]'); 
 ylim([-20 max(S)*1.2 ]); xlim([-3E6 3E6]);

Download 

INVZE

Instalace Eclipse ww.eclipse.org

Eclipse IDE for C/C– Developers

Eclipse umístíme do adresáře /opt/eclipse…

cd /opt
tar xzf eclipse-cpp-indigo-SR1-incubation-linux-gtk.tar.gz
rm eclipse-cpp-indigo-SR1-incubation-linux-gtk.tar.gz

Aktualizace JAVA pro Eclipse

apt-get install python-software-properties
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java7-installer

Překlad programu x86

make main.c -o main % preklad
./main % spustit
./main param1 ... % s parametrem

// více vlaknové...
gcc main.c -o main -lpthread

 

Překlad programu ARM

arm-none-linux-gnueabi-gcc -static main.c -o main

Nastaveni HTTP serveru

// ma IP
ifconfig

// uprava serveru
gedit /etc/mini-httpd.conf
// upravit localhost a data_dir

// spusteni
/etc/init.d/mini-httpd start

// kontrola
netstat -tvanp

 

Stažení a spuštění programu v ARMu

// smazani
rm program
// přejmenovani
mv stary novy

// stažení
wget 192.168.2.67/program

// zmena na spustitelny soubor
chmod +x program

// spusteni
./program

Serial Port

// výpis
ll /dev/ | grep ttyS

// nastaveni BauRate
stty -F /dev/tttyS3 9600

// vypis nastaveni
stty -F /dev/tttyS3

// odeslat
echo "test" > /dev/ttyS3

// příjem
cat /dev/ttyS3

Práce s LED

// dostupne
ll /sys/class/leds
// vypnuti vychozi funkce
echo none > /sys/class/leds/led_stat/trigger 
// LED ON
echo 255 > /sys/class/leds/led_stat/brightness</pre>
<pre>// LED OFF
echo 0 > /sys/class/leds/led_stat/brightness</pre>
<pre>

Modulace BPSK a QPSK

Modulace BPSK

%% BPSK
% Tomas Krejci, 11.4.2015

clc
close all
clear all

data = [1 1 0 1 0 0 0 1 1 1];
% = randi([0 1], n_data, 1)

%% BPSK

fs = 100E6;
Ts = 10E-6; % interval symbolu

n_data = length(data);
Tr = n_data * Ts; % delka celeho signalu
nn = fs*Ts; % pocet vzorku v symbolovem intervalu
t = 0 : 1/fs : Tr - 1/fs; 

y_c = zeros(1, nn * n_data);
y_s = zeros(1, nn * n_data);

for ii = 1 : n_data

 if data(ii) == 0
 y_c((ii-1)*nn+1 : ii*nn ) = 1;
 y_s((ii-1)*nn+1 : ii*nn ) = 1;
 else
 y_c((ii-1)*nn+1 : ii*nn ) = -1;
 y_s((ii-1)*nn+1 : ii*nn ) = -1;
 end

end
f = 1E6; % frekvence nosne
s = y_c .* cos(2*pi*f*t) + y_s .* sin(2*pi*f*t); % vysledny signal

S= 10*log10((abs(fftshift(fft(s)))).^2);% energetické spektrum signálu
fx = fs/2 * linspace(-1,1,length(s)); 

figure;
subplot(2,1,1); plot(t,s); title('BPSK'); xlabel('t [s]'); ylabel('A [V]');
subplot(2,1,2); plot(fx,S); title('Spektrum');xlabel('f [Hz]'); ylabel('Se [dB]');
 ylim([-20 max(S)*1.2 ]); xlim([-3E6 3E6]);

 

Modulace QPSK

%% QPSK
% Tomas Krejci, 11.4.2015

clc 
close all
clear all
 
data = [1 1 0 1 0 0 0 1 1 1];

fs = 100E6; 
Ts = 10E-6; % interval symbolu
Nb = 2; % Q=4 -&gt; 4=2^2
n_data = length(data);
Tr = n_data/Nb * Ts; % delka celeho signalu
nn = fs*Ts; % pocet vzorku v symbolovem intervalu
t = 0 : 1/fs : Tr - 1/fs; 

y_c = zeros(1, nn * n_data/Nb);
y_s = zeros(1, nn * n_data/Nb);
jj = 1;
for ii = 1 : Nb : n_data-1 
 if data(ii)==0 &amp;&amp; data(ii+1)==0
 y_c( (jj-1)*nn+1 : jj*nn ) = 0.5;
 y_s( (jj-1)*nn+1 : jj*nn ) = 0.5;
 end
 if data(ii)==0 &amp;&amp; data(ii+1)==1
 y_c( (jj-1)*nn+1 : jj*nn ) = -0.5;
 y_s( (jj-1)*nn+1 : jj*nn ) = 0.5;
 end 
 if data(ii)==1 &amp;&amp; data(ii+1)==0
 y_c( (jj-1)*nn+1 : jj*nn ) = -0.5;
 y_s( (jj-1)*nn+1 : jj*nn ) = -0.5;
 end 
 if data(ii)==1 &amp;&amp; data(ii+1)==1
 y_c( (jj-1)*nn+1 : jj*nn ) = 0.5;
 y_s( (jj-1)*nn+1 : jj*nn ) = -0.5;
 end 
 jj = jj + 1;
end


f = 1E6; % f nosne
s = y_c .* cos(2*pi*f*t) + y_s .* sin(2*pi*f*t); % vysledny signal

S= 10*log10((abs(fftshift(fft(s)))).^2);% energetické spektrum signálu 
fx = fs/2 * linspace(-1,1,length(s)); 

figure;
subplot(2,1,1); plot(t,s); title('QPSK'); xlabel('t [s]'); ylabel('A [V]');
subplot(2,1,2); plot(fx,S); title('Spektrum');xlabel('f [Hz]'); ylabel('Se [dB]'); 
 ylim([-20 max(S)*1.2 ]); xlim([-3E6 3E6]);&lt;/pre&gt;
&lt;pre&gt;

Download 

QPSK BPSK

Modulace ASK

Modulace ASK. Signály RC a RRC.
%% ASK
% Tomas Krejci, 11.4.2015

clc
close all
clear all

data = [1 1 0 1 0 0 0 1];

%% PAM - jedno rozmerna
fs = 1E9; % vzorkovaci frek, pro "udelani spojite s(t)", v prednskach jako fh=1/Tv
Ts = 1E-6; % symbolovy interval, (jak dlouho potrva jeden datovy syombol (1 nebo 0 z data) po modulaci jako s(t) ?)
nn = fs*Ts;
kMax = length(data); % kolik je symbolovych intervalu (pro jedno rozmernou odpovida datovych intervalu)

c_m = [0 1]; % dvou-stavová
M = length(c_m);
c_m_k = zeros(1, kMax);
for kk = 1:kMax

 switch (data(kk))
 case 0
 c_m_k(kk) = c_m(1);
 case 1
 c_m_k(kk) = c_m(2);
 otherwise
 c_m_k(kk) = 0;
 end
end

%% REC
h_xy = ones(1, nn);
%% BiP
h_xy = [ones(1, nn/2) -ones(1, nn/2)];
%% RC
trc = -1:1/(nn/2):1-1/(nn/2);
h_xy = sRC(0.5,trc,nn-1);
%% RRC
h_xy = sRRC(0.5,trc,nn-1);

%% PAM expanzni cast
s_PAM = zeros(1, nn * kMax);

for kk = 1:kMax
 s_PAM( (kk-1)*nn+1 : kk*nn ) = c_m_k(kk) * h_xy(1,:);
end

%% ASK
f0 = 100E6;
w0 = 2*pi*f0;
t0 = 0:1/fs:kMax*Ts-1/fs;
% ASK
s_t = s_PAM .* cos(w0*t0);
% spektrum
S_PAM = 10*log10((abs(fftshift(fft(s_t)))).^2);% energetické spektrum signálu
fx = fs/2 * linspace(-1,1,length(s_t)); 

h_figure = figure; set(h_figure(:),'color',[1 1 1]);
subplot(211); hold all;
 plot(t0, s_t, 'Color', 'red', 'LineWidth', 2);
 ylim([min(s_t)*1.2 max(s_t)*1.2 ]); title(['ASK M=' num2str(M)]);
 xlabel('Time [s]'); ylabel('A [V]'); %legend('PAM s(t)', 'c_m_(_k_)','Location','NorthEastOutside');
subplot(212); hold all;
 plot(fx, S_PAM, 'Color', 'blue');
 ylim([-40 max(S_PAM)*1.2 ]); title('Spektrum');
 xlabel('f [Hz]'); ylabel('Se [dB]');

 

Signál RC

function s_RC = sRC(alfa, t, N)
s_RC = zeros(1,N+1);
for n = 1:N+1,
 if abs(t(1,n))<= (1-alfa)/2,
 s_RC(1,n) = 1;
 end;
 if abs(t(1,n))<= (1+alfa)/2,
 if abs(t(1,n))>= (1-alfa)/2,
 s_RC(1,n)=(cos((pi/4/alfa)*(2*abs(t(1,n))-1+alfa)))^2;
 end;
 end;
end;

Signál RRC

function s_RRC = sRRC(alfa, t, N)
s_RRC = zeros(1,N+1); 
for n = 1:N+1,
 if t(1,n) ==0, s_RRC(1,n) = 1-alfa+4*alfa/pi;
 elseif abs(t(1,n))==1/4/alfa, s_RRC(1,n) = (alfa/pi/1.414)*((pi-2)*cos(pi/4/alfa)+(pi+2)*sin(pi/4/alfa));
 else s_RRC(1,n) = ((sin((1-alfa)*pi*t(1,n)))/pi/t(1,n)+(4*alfa*cos((1+alfa)*pi*t(1,n)))/pi)/(1-16*alfa*alfa*t(1,n)*t(1,n)); 
 end;
end;

Download 

ASK

sRC sRRC

Modulace PAM #2

Modulace PAM #2 - vícerozměrná
%% PAM #2
% Tomas Krejci, 11.4.2015

clc 
close all
clear all

data = [0 1 0 0 0 0 0 1 ... % A
 0 1 1 0 1 0 0 0 ... % h
 0 1 1 0 1 1 1 1 ... % o
 0 1 1 0 1 0 1 0]; %j


%% PAM - vice rozmerna

fs = 1E6; % vzorkovaci frek, pro "udelani spojite s(t)", v prednskach jako fh=1/Tv
Ts = 1E-3; % symbolovy interval, (jak dlouho potrva jeden datovy syombol (1 nebo 0 z data) po modulaci jako s(t) ?)
nn = fs*Ts;

N = 4; % kolik rozmer mod.
Nb = log2(N); % za prepokladu dat ve dvojkove soustave, pocet bitu predstavuji jednu modulacni fci h neboli stav q
kMax = length(data)/Nb; % kolik je symbolovych intervalu (pro jedno rozmernou odpovida datovych intervalu (poctu dat))
M = 2; % uvazujeme dvou svavovou modulaci 


%% REC
h_m = [ones(1, Nb*nn); 
 [ones(1, nn) -ones(1, nn)]; 
 [ones(1, nn/2) -ones(1, nn) ones(1, nn/2)];
 [ones(1, nn/2) -ones(1, nn/2) ones(1, nn/2) -ones(1, nn/2)] ];
q = zeros(1,kMax);
jj =1;
for ii = 1:Nb: length(data)-1
 
 if data(ii)==0 && data(ii+1)==0
 q(jj) = 1;
 end
 if data(ii)==0 && data(ii+1)==1
 q(jj) = 2;
 end 
 if data(ii)==1 && data(ii+1)==0
 q(jj) = 3;
 end 
 if data(ii)==1 && data(ii+1)==1
 q(jj) = 4;
 end 
 jj = jj+1;
 
end


%% PAM expanzni cast
s_t = zeros(1, nn * length(data));

for kk = 1:kMax
 s_t( (kk-1)*nn*Nb+1 : kk*nn*Nb ) = h_m(q(kk),:); 
end

t_osa = 0 : 1/fs : kMax*Ts*Nb-1/fs;
c_osa = 0 : Nb*nn/fs : kMax*Ts*Nb-1/fs;
q_osa = 0 : Nb*nn/fs : kMax*Ts*Nb-1/fs;
h_figure = figure; set(h_figure(:),'color',[1 1 1]);
subplot(211); hold all; 
 % [hAx,hLine1,hLine2] = plotyy(t_osa,s_t,c_osa,q,'plot','stem');
 plot(t_osa, s_t, 'Color', 'red', 'LineWidth', 2); 
 stem(c_osa, q/4, 'Color', 'blue', 'LineStyle', '--', 'Marker', '>', 'LineWidth', 2);
 % hLine2.LineStyle = '--'; hLine2.Marker = '>'; hLine2.LineWidth = 2;
 ylim([min(s_t)*1.2 max(s_t)*1.2 ]); title(['PAM M=' num2str(M)]);
 xlabel('Time [s]'); ylabel('A [V]'); legend('PAM s(t)', 'q_m_k','Location','NorthEastOutside');
subplot(212); hold all; 
 stem([0:1:Nb*kMax-1], data, 'Color', 'Black', 'LineStyle', '-', 'Marker', 'x', 'LineWidth', 2);
 ylim([min(data)*1.2 max(data)*1.2 ]); title('data');
 xlabel('Time [n]'); ylabel('[-]'); legend(' data', 'Location','NorthEastOutside');

Download 

PAM_2