You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to implement Airband (Aircraft band) in this MATLAB code
11 views (last 30 days)
Show older comments
I am researching Airband (Aircraft Band) for the Telecommunication course, but the professor didn't explain what to do exactly in simulation except saying that I have to do AM modulation scheme. I found a code online but don't know how to implement (108 - 132) Mhz in it or should I do something else in it? really need your guys help the only thing so far I can assume is the values for (Ac, Am, Fc, Fm, Fs, m ,t) are assumption by our part in the research.
clc
clear all
% Ac=input('Enter carrier signal amplitude: ');
% Am=input('Enter message signal amplitude: ');
% Fc=input('Enter carrier frequency: ');
% Fm=input('Enter message frequency: ');% fm<fc
% m=input('Enter modulation index: ');
% t=input('Enter time period: ');
%To plot Modulating,carrier and Amplitudede modulated signals
echo on
Ac= 10;
Am=6.5;
Fc=20000;
Fm = 2000;
Fs=2000;%sampling frequency
Ta= 1/Fs;
t= 0:Ta/1000:6*Ta;
Ym=Am*sin(2*pi*Fm.*t);
Yc= Ac*sin(2*pi*Fc.*t);
m=Am/Ac;
y= Ac*(1+m*sin(2*pi*Fm.*t)).*sin(2*pi*Fc.*t);
subplot(3,1,1),plot(t,Ym);
title('Modulating signal')
xlabel('time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(t,Yc);
title('Carrier signal')
xlabel('time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(t,y,'r');
title('Modulated signal')
xlabel('time(sec)');
ylabel('Amplitude');
36 Comments
Star Strider
on 19 Dec 2021
Aviation radio for communication and navigation is A1a, or double-sideband transmitted carrier communication, so just use the Signal Processing Toolbox modulate function. The frequencies are assigned as channels, so to get the correct ones, it will be necessary to do a bit of research.
Abdul Rahman Alam
on 19 Dec 2021
@Star Strider I apologize but can you elaborate more on this or can you provide an example. I ams till fairly new on this MATLAB and we haven't used it a lot.
as for the values of (Ac, Am, Fc, Fm, Fs, m ,t) should I leave it as it is or is it completely relevant?
Star Strider
on 19 Dec 2021
They are all relevant.
It will be necessary to choose the correct carrier frequency from among the channels available, and considering the type of communication (VOR, simplex radiotelephone). Arbitrary carrier frequencies will not work in aircraft communication and navigation, and some frequencies are reserved for radionavigation and others for communication. (TACAN and nondirectional beacons (NDB) are not relevant here, the first because it uses UHF and the second because they use MF and NDBs are now obsolete, at least in the U.S.)
.
Abdul Rahman Alam
on 19 Dec 2021
@Star Strider apologies for the confusion for the last question I meant to ask should I change the values or not for (Ac, Am, Fc, Fm, Fs, m ,t) or keep it as it is in the code. also how to determine the values we havn't taken anything related to that topic only general idea what is AM signals are.
I have small question will the Amplitude change from carrier signal to message signal .
"Arbitrary carrier frequencies will not work in aircraft communication and navigation, and some frequencies are reserved for radionavigation and others for communication."
so I cannot choose channels from these frequencies?
Star Strider
on 19 Dec 2021
To be completely accurate with respect to the international regulations regarding aircraft communications, it will be necessary to chooose an appropriate frequency and bandwidth fot the modulating signal so that the modulated signal conforms to the engineering requirements for aircraft communication.
Abdul Rahman Alam
on 19 Dec 2021
@Star Strider How would I get the values for that? the only values I know is (108 -132) Mhz which are the fequncy that airband works on.
aside from that I don't know how to detrmine the values for the (Ac, Am, Fc, Fm, Fs) in this.
Star Strider
on 19 Dec 2021
I went on the Internet and did a web search.
Also: typographical error in my first Comment. It should be ‘A3a’ not ‘A1a’.
Abdul Rahman Alam
on 20 Dec 2021
@Star Strider I think I misunderstood something withing Airband, eventhough I am using frequencies between (108-132) Mhz I am not suppose to pick one of them like Fc= 123 Mhz, it should be smaller since the space is dvided by 25 kHz I believe. So My values of (Fc, Fm, Fs) should be around in kHz right? is Fm = Fs? Please correct me if I am wrong.
Star Strider
on 20 Dec 2021
The carrier frequency must be one of the available channel frequencies, and the modulating signal must conform to the bandwidth requirements so that the entire signal remains within the frequency limits of the channel it uses. Also, the modulating signal must conform to the part of the spectrum it uses, so the lower part of the spectrum is used for radionavigation (VOR) and the upper part of the spectrum for radiotelephone (voice) communications.
Abdul Rahman Alam
on 20 Dec 2021
Edited: Abdul Rahman Alam
on 21 Dec 2021
@Star Strider My carrier frequncy Fc=123 Mhz is correct?
Star Strider
on 21 Dec 2021
If that is an available channel frequency (one of the local approach frequencies here is 132.25 so it appears to be on the correct interval), then yes.
Abdul Rahman Alam
on 21 Dec 2021
Edited: Abdul Rahman Alam
on 21 Dec 2021
@Star Strider Since my Fc in Mhz then my Fm should also be in Mhz but les then 123 Mhz right?
edit:
these are my values
Ac= 10;
Am= 6;
Fc=123*(10^(6));
Fm = 3*(10^(6));
Fs=2*(10^(6));%sampling frequency
Ta= 1/Fs;
t= 0:Ta/1000:6*Ta;
Star Strider
on 21 Dec 2021
I did not check it thoroughly. It certainly appears to be correct, with about 75% modulation.
However, this is a radiotelephone communications channel, and likely has a bandwidth of ±6 kHz maximum in order not to spill over into and interfere with adjacent channels. It might be worthwhile to check that to be certain, and change the modulation frequency to comply with the applicable engineering standards. Check the final modulated signal by taking its Fourier transform in order to check its bandwidth. Be certain it complies with the international engineering standard.
Abdul Rahman Alam
on 22 Dec 2021
@Star Strider I did little change in the code:
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
echo on
Am= 7; %Message signal amplitude
Ac= 10; %Carrier signal amplitude
Fm=3*(10^(6)); %Message frequency
Fc=123*(10^(6)); %Carrier frequency
Fs=2*(10^(6)); %sampling frequency
Ta= 1/Fs; %sampling period
T= 0:Ta/(1*(10^(6))):7*Ta; %Period
Ym=Am*sin(2*pi*Fm.*T); %Message signal equation
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
M=Am/Ac; %Modulation index
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
subplot(3,1,1),plot(T,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
and this sis the result I got
Star Strider
on 22 Dec 2021
As I mentioned earlier, it appears to be correct, however the modulaiton frequency (‘Fm’) is out-of-range for a voice communications channel. The generally-accepted bandwidth is ±6 kHz (that is likely the same for aircraft VHF radiotelephone applications, however I have not checked to be certain).
Star Strider
on 22 Dec 2021
My impression is that it is the message modulation frequency. For voice communications, that would be in the range of ±6 kHz.
Also, aircraft radiotelephone signals are (at least as far as I know) A3a, or double-sideband transmitted carrier (DSBTC). Do a Fourier transform on the transmitted signal to be certain the bandwidth is appropriate (so that it does not go into the guard bands of that channel and so does not interfere with neighbouring channels) and that the carrier is transmitted.
Abdul Rahman Alam
on 22 Dec 2021
@Star Strider so I have to make my Fm=6khz instead of 6Mhz? but that don't even give me correct sketch like I showed you before.
Star Strider
on 22 Dec 2021
It does give the correct sketch. It is simply necessary to change the x-axis limits of the plot. (The details of the carrier frequency will not be obvious, and only the modulated signal will be apparent.) Create a second plot with a different x-axis limit to demonstrate the details of the carrier.
Alternatively, produce two sets of plots, one with the ‘correct’ ±6 kHz modulation and decreased detail in the carrier, and a second with a higher modulation frequency that shows the details of both the carrier and the modulating signal. In the description, describe the differences in the two sets of plots, and the reason for creating both sets.
That is what I would do.
Abdul Rahman Alam
on 22 Dec 2021
@Star Strider So this what I did, could you tell me if I am going right track
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
echo on
Am= 7; %Message signal amplitude
Ac= 10; %Carrier signal amplitude
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fc=123*(10^(6)); %Carrier frequency
Fs=2*(10^(6)); %sampling frequency
Fsm=2*(10^(3)); %sampling frequency
Ta= 1/Fs; %sampling period
Tam= 1/Fsm; %sampling period
T= 0:Ta/(1*(10^(6))):7*Ta; %Period
Tm= 0:Ta/(1*(10^(3))):7*Tam; %Period
Ym=Am*sin(2*pi*Fm.*Tm); %Message signal equation
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
M=Am/Ac; %Modulation index
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
subplot(3,1,1),plot(T,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
The graph
Star Strider
on 22 Dec 2021
It appears to be correct, and the modulation is visible, however a longer x-axis (time) would show the modulated signal more clearly. Also, the modulation percentage needs to increase (it appears to be at most 10% here), and increasing the gain (amplitude) of the modulating signal would do that.
This is now certainly the correct approach, and would conform to the international engineering requirements.
Abdul Rahman Alam
on 23 Dec 2021
@Star Strider what about now?
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
echo on
Am= 7; %Message signal amplitude
Ac= 10; %Carrier signal amplitude
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fc=123*(10^(6)); %Carrier frequency
Fs=2*(10^(6)); %sampling frequency
Fsm=2*(10^(3)); %sampling frequency for message signal
Ta= 1/Fs; %sampling period
Tam= 1/Fsm; %sampling period for message signal
T= 0:Ta/(1*(10^(6))):6*Ta; %Period
Tm= 0:Ta/(1*(10^(3))):6*Tam; %Period for message signal
Ym=Am*sin(2*pi*Fm.*Tm); %Message signal equation
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
M=Am/Ac; %Modulation index
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
Y1= Ac*(1+M*sin(2*pi*Fm.*Tm)).*sin(2*pi*Fc.*Tm); %Amplitude modulation testing
subplot(3,1,1),plot(Tm,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y1,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
This the graph I obtained
Star Strider
on 23 Dec 2021
That looks good, and it looks as though it would meet the engineering specifications for aircraft radiotelephone communications. I would still do the fft on it to be certain that it is a double-sideband-transmitted-carrier signal.
Abdul Rahman Alam
on 23 Dec 2021
@Star Strider like plotting the fft?
I still don't understand how to use it
Star Strider
on 23 Dec 2021
With respect to the Fourier transform, I would do something like this —
t = ; % Time Vector
data = ; % Time-Domain Data
figure
plot(t, data)
grid
xlabel('t')
ylabel('Amplitude')
title('Time-Domain Plot')
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^nextpow2(L); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
% [pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
figure
plot(Fv, abs(FTdata(Iv))*2)
hold on
% plot(Fv(ix), pk, '^r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabedl('Amplitude')
title('Frequency-Domain Plot')
It may be necessary to use the xlim function to restrict the frequency axis to the region-of-interest in order to display all the relevant detail of the Fourier transform of the signal.
It might also be appropriate to include this analysis and plots with the rest of the assignment.
.
Abdul Rahman Alam
on 23 Dec 2021
@Star Strider so i use this whole code on my program or is it suppose to be an explantion how fft works?
little confused
I used the whole code and it got freeze
Star Strider
on 23 Dec 2021
It is simply a quality-assurance measure to be certain that the signal is correct in the frequency domain. It is not necessary to use it.
I haved no idea why it crashed. It is working fft code. I copied it from code I submitted as an Answer to a different post. (The only things I did not include were the time vector and the data vector, since those are supplied by your code.)
Am= 7; %Message signal amplitude
Ac= 10; %Carrier signal amplitude
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fc=123*(10^(6)); %Carrier frequency
Fs=2*(10^(6)); %sampling frequency
Fsm=2*(10^(3)); %sampling frequency for message signal
Ta= 1/Fs; %sampling period
Tam= 1/Fsm; %sampling period for message signal
T= 0:Ta/(1*(10^(6))):6*Ta; %Period
Tm= 0:Ta/(1*(10^(3))):6*Tam; %Period for message signal
Ym=Am*sin(2*pi*Fm.*Tm); %Message signal equation
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
M=Am/Ac; %Modulation index
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
Y1= Ac*(1+M*sin(2*pi*Fm.*Tm)).*sin(2*pi*Fc.*Tm); %Amplitude modulation testing
subplot(3,1,1),plot(Tm,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y1,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
t = T; % Time Vector
data = Y1; % Time-Domain Data
figure
plot(t, data)
grid
xlabel('t')
ylabel('Amplitude')
title('Time-Domain Plot')
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^(nextpow2(L)+1); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
CF = Fv(ix);
[pks, locs, wd, pr] = findpeaks(abs(FTdata(Iv))*2, 'MinPeakProminence',3);
figure
plot(Fv, abs(FTdata(Iv))*2)
hold on
plot(Fv(locs), pks, '^r', 'MarkerFaceColor','r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Frequency-Domain Plot')
xlim([-1 1]*1E7+CF)
ylim([0 12])
text(Fv(locs), pks, compose('Freq: %7.3fx10^9 Hz', Fv(locs)/1E9), 'Horiz','center', 'Vert','bottom')
The frequencies appear to be a bit high, however the double sideband transmitted carrier signal is definitely correct!
.
Abdul Rahman Alam
on 23 Dec 2021
Edited: Abdul Rahman Alam
on 23 Dec 2021
@Star Strider actually my laptop crashes randomly when using matlab so sorry about that
so should I lower the fm frequncy or fc frequency or keep it as it is?
edit: I have a diffrent result for the final graph since I changed a code slightly what i posted last time
Star Strider
on 23 Dec 2021
The carrier frequency needs to be appropriate for the aircraft communications band, so here 123 MHz if I remember correctly. Likely nothing else needs to change, other than the xlim arguments in the Fourier transform plot, although the code may do that itself. (Consider printing and attaching the Fourier transform plot to demonstrate that the signal is correct. It might get you some extra credit)
Interesting about the random crashes with MATLAB. I never had those problems on my desktop or any laptop I installed it on. My desktop crashes unpredictably, however I believe that has nothing to do with MATLAB and likely reflects something else. I have the Windows Event Viewer up and that occasionally proviides insight into what caused the crash, however not always, and it’s never MATLAB.
Abdul Rahman Alam
on 23 Dec 2021
Edited: Abdul Rahman Alam
on 23 Dec 2021
@Star Strider My laptop is old I think it is 2016 model, and nowadays I can't run multisim or matlab properly if I do heavy programming on it. it freezes then crashes that is why. most of the time I use my uni computer to do work or home desktop.
so my values for the frequency domain plot is okay? because it is a little different from what you have so a bit worried.
Star Strider
on 23 Dec 2021
I agree that 2016 technology is likely not up to 2021 software. Much has advanced in the last 5 years, and like gases, software expands to fill the available space! More capable computers mean more elaborate software.
I would use the formatting that I used in the (updated) compose call:
text(Fv(locs), pks, compose('Freq: %7.3f MHz', Fv(locs)/1E6), 'Horiz','center', 'Vert','bottom')
Also I believe that there is a problem with the ‘T’ calculation, and that ini trun is causing p[roblems for the frequency generation as reflected in the Fourier transform. (Checking the accuracy of the code is the reason for doing the Fourier transform.) To check to be certain the sampling interval is correct, check ‘T(2)’, and the sampling frequency ‘1/T(2)’.
Am= 7; %Message signal amplitude
Ac= 10; %Carrier signal amplitude
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fc=123*(10^(6)); %Carrier frequency
Fs=2*(10^(6)); %sampling frequency
Fsm=2*(10^(3)); %sampling frequency for message signal
Ta= 1/Fs; %sampling period
Tam= 1/Fsm; %sampling period for message signal
T= 0:Ta/(1*(10^(6))):6*Ta; %Period
Tm= 0:Ta/(1*(10^(3))):6*Tam; %Period for message signal
Ym=Am*sin(2*pi*Fm.*Tm); %Message signal equation
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
M=Am/Ac; %Modulation index
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
Y1= Ac*(1+M*sin(2*pi*Fm.*Tm)).*sin(2*pi*Fc.*Tm); %Amplitude modulation testing
subplot(3,1,1),plot(Tm,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y1,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
t = T; % Time Vector
data = Y1; % Time-Domain Data
figure
plot(t, data)
grid
xlabel('t')
ylabel('Amplitude')
title('Time-Domain Plot')
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^(nextpow2(L)+1); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
CF = Fv(ix);
[pks, locs, wd, pr] = findpeaks(abs(FTdata(Iv))*2, 'MinPeakProminence',3);
figure
plot(Fv, abs(FTdata(Iv))*2)
hold on
plot(Fv(locs), pks, '^r', 'MarkerFaceColor','r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Frequency-Domain Plot')
xlim([-1 1]*1E7+CF)
ylim([0 12])
text(Fv(locs), pks, compose('Freq: %7.3f MHz', Fv(locs)/1E6), 'Horiz','center', 'Vert','bottom')
.
Abdul Rahman Alam
on 23 Dec 2021
Edited: Abdul Rahman Alam
on 23 Dec 2021
@Star Strider Let me give you my updated code That I worked on it today:
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
echo on
Ac= 10; %Carrier signal amplitude
Am= 7; %Message signal amplitude
Fc=123*(10^(6)); %Carrier frequency
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fsc=2*(10^(6)); %sampling frequency
Fsm=2*(10^(3)); %sampling frequency for message signal
Tac= 1/Fsc; %sampling period
Tam= 1/Fsm; %sampling period for message signal
Tc= 0:Tac/(1*(10^(6))):6*Tac; %time
Tm= 0:Tac/(1*(10^(3))):6*Tam; %time for message signal
Yc= Ac*sin(2*pi*Fc.*Tc); %Carrier signal equation
Ym=Am*sin(2*pi*Fm.*Tm); %Message signal equation
M=Am/Ac; %Modulation index %Am/Ac
%Y= Ac*(1+M*sin(2*pi*Fm.*Tc)).*sin(2*pi*Fc.*Tc);
Y= Ac*(1+M*sin(2*pi*Fm.*Tm)).*sin(2*pi*Fc.*Tc); %Amplitude modulation
As seen in the code I modified my "Y" equation which was this before
Y1= Ac*(1+M*sin(2*pi*Fm.*Tm)).*sin(2*pi*Fc.*Tm); %Amplitude modulation testing
Also my updated Graph for what you updated:
Star Strider
on 23 Dec 2021
That appears to be correct, however the frequencies ideally need to be more accurate, so for example the carrier needs to be exactly 123.000 MHz if at all possible. The sidebands are correct, as the check here demonstrates.
Checking:
Freqs = [116.944 123.024 123.024 128.984]
Freqs = 1×4
116.9440 123.0240 123.0240 128.9840
CheckFreqs = diff(Freqs)
CheckFreqs = 1×3
6.0800 0 5.9600
So the frequencies and amplitudes are essentially correct. (The slight errors may be due to calculation inaccuracies, however it would be best to check to be certain they cannot be made more accurate.)
.
Abdul Rahman Alam
on 24 Dec 2021
ok, but at this stage am I safe to assume that I am done or bit tinkering needed for this code?
since i need start writitng report today, since I have submission on sunday.
Star Strider
on 24 Dec 2021
‘ok, but at this stage am I safe to assume that I am done or bit tinkering needed for this code?’
Yes!
Please post back with the results. I would give high marks for the effort and results.
Accepted Answer
Abdul Rahman Alam
on 24 Dec 2021
Edited: Abdul Rahman Alam
on 24 Dec 2021
I would like thank @Star Strider for helping me out understanding this project and fixing my mistakes. without further ado: this my code now and what changes I have made:
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
Ac= 10; %Carrier signal amplitude
Am= 7; %Message signal amplitude
Fc=123*(10^(6)); %Carrier frequency
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fs=2*(10^(3)); %sampling frequency
Ta= 1/Fs; %sampling period
T= 0:Ta/(1*(10^(6))):6*Ta; %time
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
Ym=Am*sin(2*pi*Fm.*T); %Message signal equation
M=Am/Ac; %Modulation index %Am/Ac
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
figure(1)
subplot(3,1,1),plot(T,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
%Part 2
t = T; % Time Vector
data = Y; % Time-Domain Data
figure (2)
plot(t, data)
grid
xlabel('Time Vector(sec)')
ylabel('Amplitude')
title('Time-Domain Plot')
Then to make sure you have the correct answer you have to use fourier transofr command "fft" as shown below to se if it double sided band
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^(nextpow2(L)+1); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
CF = Fv(ix);
[pks, locs, wd, pr] = findpeaks(abs(FTdata(Iv))*2, 'MinPeakProminence',3);
figure (3)
plot(Fv, abs(FTdata(Iv))*2)
hold on
plot(Fv(locs), pks, '^r', 'MarkerFaceColor','r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Frequency-Domain Plot')
xlim([-1 1]*1E4+CF)
ylim([0 12])
text(Fv(locs), pks, compose('Freq: %7.3f MHz', Fv(locs)/1E6), 'Horiz','center', 'Vert','bottom')
also to make sure my frequency is close to the Fc Carrier signal frequency as close as possible
11 Comments
Star Strider
on 24 Dec 2021
My pleasure!
However, there is a serious problem. The sidebands are now ±6 MHz from the carrier, they should be ±6 kHz from it. I still this a problem with they way ‘Tc’ and ‘Tm’ are calculated. First, there should be one time vector for all of the signals. Second, the time vector must to be calculated correctly. I would use the linspace function for this.
Abdul Rahman Alam
on 24 Dec 2021
@Star Strider so should I use the the previous code where frequencies appear to be a bit high?
also I had to use two time vectors because Tc in Mhz and Tm in kHz and if I do one then I don't get this graph
Star Strider
on 24 Dec 2021
The frequencies need to be correct, so the time vector needs to be correct.
Use the same (correct) time vector for everything, and scale the frequency arguments to the sin functions that create the two signals, carrier and modulating frequency. Two time vectors to describe the same system should not be necessary, and likely indicate that something is wrong somewhere.
Abdul Rahman Alam
on 24 Dec 2021
@Star Strider This is what I got, please tell me I am done since I really need to finish today and work on the other project
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
Ac= 10; %Carrier signal amplitude
Am= 7; %Message signal amplitude
Fc=123*(10^(6)); %Carrier frequency
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fs=2*(10^(3)); %sampling frequency
Ta= 1/Fs; %sampling period
T= 0:Ta/(1*(10^(6))):6*Ta; %time
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
Ym=Am*sin(2*pi*Fm.*T); %Message signal equation
M=Am/Ac; %Modulation index %Am/Ac
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
figure(1)
subplot(3,1,1),plot(T,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
%Part 2
t = T; % Time Vector
data = Y; % Time-Domain Data
figure (2)
plot(t, data)
grid
xlabel('Time Vector(sec)')
ylabel('Amplitude')
title('Time-Domain Plot')
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^(nextpow2(L)+1); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
CF = Fv(ix);
[pks, locs, wd, pr] = findpeaks(abs(FTdata(Iv))*2, 'MinPeakProminence',3);
figure (3)
plot(Fv, abs(FTdata(Iv))*2)
hold on
plot(Fv(locs), pks, '^r', 'MarkerFaceColor','r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Frequency-Domain Plot')
xlim([-1 1]*1E7+CF)
ylim([0 12])
text(Fv(locs), pks, compose('Freq: %7.3f MHz', Fv(locs)/1E6), 'Horiz','center', 'Vert','bottom')
Star Strider
on 24 Dec 2021
That looks good!
Change the xlim call to —
xlim([-1 1]*1E4+CF)
so that the Fourier transform plot displays correctly (I did that here).
I did not go through it in detail, however it appears to be correct.
%To plot Modulating,carrier and Amplitudede modulated signals
Ac= 10; %Carrier signal amplitude
Am= 7; %Message signal amplitude
Fc=123*(10^(6)); %Carrier frequency
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fs=2*(10^(3)); %sampling frequency
Ta= 1/Fs; %sampling period
T= 0:Ta/(1*(10^(6))):6*Ta; %time
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
Ym=Am*sin(2*pi*Fm.*T); %Message signal equation
M=Am/Ac; %Modulation index %Am/Ac
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
figure(1)
subplot(3,1,1),plot(T,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
%Part 2
t = T; % Time Vector
data = Y; % Time-Domain Data
figure (2)
plot(t, data)
grid
xlabel('Time Vector(sec)')
ylabel('Amplitude')
title('Time-Domain Plot')
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^(nextpow2(L)+1); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
CF = Fv(ix);
[pks, locs, wd, pr] = findpeaks(abs(FTdata(Iv))*2, 'MinPeakProminence',3);
figure (3)
plot(Fv, abs(FTdata(Iv))*2)
hold on
plot(Fv(locs), pks, '^r', 'MarkerFaceColor','r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Frequency-Domain Plot')
xlim([-1 1]*1E4+CF)
ylim([0 12])
text(Fv(locs), pks, compose('Freq: %7.3f MHz', Fv(locs)/1E6), 'Horiz','center', 'Vert','bottom')
Again, please follow up!
.
Abdul Rahman Alam
on 24 Dec 2021
@Star Strider yes I am getting the same graphs. and what should I follow up with?
Star Strider
on 24 Dec 2021
I would give you high marks on this.
I am curious as to whether that is the actual result!
Abdul Rahman Alam
on 24 Dec 2021
@Star Strider you can check the code: I removed the extra T's (Tam,Tac,Tm,Tc) and replaced it with on Ta and T. and I made the sample frequency as Fs= 2kHz which made it possible. although a bit worried that is really condensed compare to what I got before. if this is right or wrong.
clc
clear all
close all
%To plot Modulating,carrier and Amplitudede modulated signals
Ac= 10; %Carrier signal amplitude
Am= 7; %Message signal amplitude
Fc=123*(10^(6)); %Carrier frequency
Fm=6*(10^(3)); %Message frequency %Fm<Fc
Fs=2*(10^(3)); %sampling frequency
Ta= 1/Fs; %sampling period
T= 0:Ta/(1*(10^(6))):6*Ta; %time
Yc= Ac*sin(2*pi*Fc.*T); %Carrier signal equation
Ym=Am*sin(2*pi*Fm.*T); %Message signal equation
M=Am/Ac; %Modulation index %Am/Ac
Y= Ac*(1+M*sin(2*pi*Fm.*T)).*sin(2*pi*Fc.*T); %Amplitude modulation
figure(1)
subplot(3,1,1),plot(T,Ym); %Plot 1
title('Modulating signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,2),plot(T,Yc); %Plot 2
title('Carrier signal')
xlabel('Time(sec)');
ylabel('Amplitude ');
subplot(3,1,3),plot(T,Y,'r'); %Plot 3
title('Modulated signal')
xlabel('Time(sec)');
ylabel('Amplitude');
%Part 2
t = T; % Time Vector
data = Y; % Time-Domain Data
figure (2)
plot(t, data)
grid
xlabel('Time Vector(sec)')
ylabel('Amplitude')
title('Time-Domain Plot')
L = numel(t); % Vectors Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^(nextpow2(L)+1); % Length Of 'fft'
datam = data - mean(data); % Subtract Mean From Data (Shows Peaks Better)
FTdata = fft(datam,NFFT)/L; % Calculate Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pk,ix] = max(abs(FTdata(Iv))); % Peak Amplitude & Index (Optional)
CF = Fv(ix);
[pks, locs, wd, pr] = findpeaks(abs(FTdata(Iv))*2, 'MinPeakProminence',3);
figure (3)
plot(Fv, abs(FTdata(Iv))*2)
hold on
plot(Fv(locs), pks, '^r', 'MarkerFaceColor','r') % (Optional)
hold off
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Frequency-Domain Plot')
xlim([-1 1]*1E4+CF)
ylim([0 12])
text(Fv(locs), pks, compose('Freq: %7.3f MHz', Fv(locs)/1E6), 'Horiz','center', 'Vert','bottom')
Star Strider
on 24 Dec 2021
Efficient, shorter, code is better, so long as it is clear and essentially self-explanatory. This is.
It works, and appears to give the correct results.
More Answers (0)
See Also
Categories
Find more on Modulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- ä¸å›½
- 日本Japanese (日本語)
- í•œêµKorean (í•œêµì–´)