├── eric.wav ├── readme-assets ├── am-modulation │ ├── 00.png │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ ├── 25.png │ ├── 26.png │ ├── 27.png │ ├── 28.png │ ├── 29.png │ └── 30.png └── fm-modulation │ ├── 00.png │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ └── 06.png ├── plot_in_time.m ├── plot_in_frequency.m ├── generate_filter.m ├── env_demod.m ├── coh_demod.m ├── LICENSE ├── Readme.md ├── fm_modulation.m └── am_modulation.m /eric.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/eric.wav -------------------------------------------------------------------------------- /readme-assets/am-modulation/00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/00.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/01.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/02.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/03.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/04.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/05.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/06.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/07.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/08.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/09.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/10.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/11.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/12.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/13.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/14.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/15.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/16.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/17.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/18.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/19.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/20.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/21.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/22.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/23.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/24.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/25.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/26.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/27.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/28.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/29.png -------------------------------------------------------------------------------- /readme-assets/am-modulation/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/am-modulation/30.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/00.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/01.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/02.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/03.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/04.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/05.png -------------------------------------------------------------------------------- /readme-assets/fm-modulation/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Omar-Radwan/AM-FM_Modulation/HEAD/readme-assets/fm-modulation/06.png -------------------------------------------------------------------------------- /plot_in_time.m: -------------------------------------------------------------------------------- 1 | function plot_in_time(yt,fs,title_label) 2 | t = linspace(0, length(yt)/fs, length(yt)); 3 | figure() 4 | plot(t,yt); 5 | title(title_label); 6 | xlabel('Time'); 7 | ylabel('Value'); 8 | end -------------------------------------------------------------------------------- /plot_in_frequency.m: -------------------------------------------------------------------------------- 1 | function plot_in_frequency(yf,fs,title_label) 2 | f = linspace(-fs/2,fs/2,length(yf)); 3 | figure() 4 | plot(f,yf./fs); 5 | title(title_label); 6 | xlabel('Frequency'); 7 | ylabel('Value'); 8 | end -------------------------------------------------------------------------------- /generate_filter.m: -------------------------------------------------------------------------------- 1 | function filter = generate_filter(signal_length,fs,f_filter) 2 | filter = ones(signal_length,1); 3 | f = linspace(-fs/2,fs/2,signal_length); 4 | for i = 1: signal_length 5 | if abs(f(i))>f_filter 6 | filter(i)=0; 7 | end 8 | end 9 | end -------------------------------------------------------------------------------- /env_demod.m: -------------------------------------------------------------------------------- 1 | function [yt_demod,yf_demod] = env_demod(st,fs_cur,fs_res,is_snr,snr) 2 | 3 | if is_snr == 1 4 | st = awgn(st, snr); 5 | end 6 | 7 | yt_demod = resample(abs(hilbert(st)),fs_res,fs_cur); %envelope detector and resample 8 | yf_demod = fftshift(fft(yt_demod)); 9 | end -------------------------------------------------------------------------------- /coh_demod.m: -------------------------------------------------------------------------------- 1 | function [yt_demod, yf_demod] = coh_demod(st,fs_bef,fs_aft,is_snr,snr,fc,phase,f_filter) 2 | if is_snr == 1 3 | st = awgn(st, snr); 4 | end 5 | 6 | t = linspace(0,length(st)/fs_bef, length(st)); %(x2-x1)/(n-1) = 1/5*fc, linspace(x1,x2,n) 7 | carrier_t = cos(2*pi*fc*t+phase).'; 8 | tmp = st.*carrier_t; %m(t)*c(t) 9 | filter = generate_filter(length(tmp),fs_bef,f_filter); %filter in frequency domain 10 | 11 | tmp = fftshift(fft(tmp)).*filter; 12 | tmp = ifft(ifftshift(tmp)); 13 | yt_demod = resample(tmp,fs_aft,fs_bef); %mutiply by carrier,filter and resample 14 | yf_demod = fftshift(fft(yt_demod)); 15 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Omar-Radwan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # AM-FM Modulation 2 | Amplitude modulation/demodulation and frequency modulation/demodulation of voice signal using MATLAB 3 | ## AM Modulation/Demodulation 4 | ![](./readme-assets/am-modulation/00.png) 5 | ![](./readme-assets/am-modulation/01.png) 6 | ![](./readme-assets/am-modulation/02.png) 7 | ![](./readme-assets/am-modulation/03.png) 8 | ![](./readme-assets/am-modulation/04.png) 9 | ![](./readme-assets/am-modulation/05.png) 10 | ![](./readme-assets/am-modulation/06.png) 11 | ![](./readme-assets/am-modulation/07.png) 12 | ![](./readme-assets/am-modulation/08.png) 13 | ![](./readme-assets/am-modulation/09.png) 14 | ![](./readme-assets/am-modulation/10.png) 15 | ![](./readme-assets/am-modulation/11.png) 16 | ![](./readme-assets/am-modulation/12.png) 17 | ![](./readme-assets/am-modulation/13.png) 18 | ![](./readme-assets/am-modulation/14.png) 19 | ![](./readme-assets/am-modulation/15.png) 20 | ![](./readme-assets/am-modulation/16.png) 21 | ![](./readme-assets/am-modulation/17.png) 22 | ![](./readme-assets/am-modulation/18.png) 23 | ![](./readme-assets/am-modulation/19.png) 24 | ![](./readme-assets/am-modulation/20.png) 25 | ![](./readme-assets/am-modulation/21.png) 26 | ![](./readme-assets/am-modulation/22.png) 27 | ![](./readme-assets/am-modulation/23.png) 28 | ![](./readme-assets/am-modulation/24.png) 29 | ![](./readme-assets/am-modulation/25.png) 30 | ![](./readme-assets/am-modulation/26.png) 31 | ![](./readme-assets/am-modulation/27.png) 32 | ![](./readme-assets/am-modulation/28.png) 33 | ![](./readme-assets/am-modulation/29.png) 34 | ![](./readme-assets/am-modulation/30.png) 35 | 36 | ## FM Modulation/Demodulation 37 | ![](./readme-assets/fm-modulation/00.png) 38 | ![](./readme-assets/fm-modulation/01.png) 39 | ![](./readme-assets/fm-modulation/02.png) 40 | ![](./readme-assets/fm-modulation/03.png) 41 | ![](./readme-assets/fm-modulation/04.png) 42 | ![](./readme-assets/fm-modulation/05.png) 43 | ![](./readme-assets/fm-modulation/06.png) 44 | -------------------------------------------------------------------------------- /fm_modulation.m: -------------------------------------------------------------------------------- 1 | %-------------------------------------------------clear-------------------------------------------------------------------- 2 | clc; 3 | close all; 4 | clear all; 5 | %-------------------------------------------------read file-------------------------------------------------------------------- 6 | FILE = 'eric.wav'; 7 | fc = 100000; 8 | [yt, fs]= audioread(FILE); 9 | fs_res = 5*fc; 10 | f_filter = 4000; 11 | %-------------------------------------------------plotting-------------------------------------------------------------------- 12 | plot_in_time(yt,fs,'Message in time domain'); 13 | plot_in_frequency(real(fftshift(fft(yt))),fs, 'Message in frequency domain'); 14 | %-------------------------------------------------message in frequency domain-------------------------------------------------------------------- 15 | yf = fftshift(fft(yt)); 16 | xf = linspace(-fs/2,fs/2,length(yf)); 17 | %-------------------------------------------------filter-------------------------------------------------------------------- 18 | filter = generate_filter(length(yf),fs,f_filter); 19 | yf_filtered = filter.*yf; 20 | %-------------------------------------------------back to time domain-------------------------------------------------------------------- 21 | yt_filtered= real(ifft(ifftshift(yf_filtered))); 22 | plot_in_time(yt_filtered, fs, 'Signal in time domain after filter' ) 23 | %-------------------------------------------------sound-------------------------------------------------------------------- 24 | % sound(yt_filtered,fs); 25 | %-------------------------------------------------plotting-------------------------------------------------------------------- 26 | xt = linspace(0,length(yt_filtered)/fs, length(yt_filtered)); 27 | %-------------------------------------------------resmple-------------------------------------------------------------------- 28 | yt_resampled = resample(yt_filtered,fs_res,fs); 29 | %-------------------------------------------------carrier signal-------------------------------------------------------------------- 30 | t = linspace(0,length(yt_resampled)/fs_res, length(yt_resampled)); %(x2-x1)/(n-1) = 1/5*fc, linspace(x1,x2,n) 31 | carrier = cos(2*pi*fc*t).'; 32 | carriersin = sin(2*pi*fc*t).'; 33 | yt_carrier=carrier; 34 | yf_carrier=fftshift(fft(yt_carrier)); 35 | xt_carrier=t; 36 | xf_carrier=linspace(-fc/2,fc/2,length(yt_carrier)); 37 | %------------------------------------------------FM Modulation------------------------------------------------------------------------ 38 | %------------------------------------------------NBFM------------------------------------------------------------------------ 39 | A = max(abs(yt)); 40 | kf = pi; %de ely btefre2 fel amplitude bta3 elcarrier 41 | beta = (kf*A)/(2*pi*fs_res); 42 | m_int = kf.*cumsum(yt_resampled).'; % Integrating Msg 43 | St = A.*cos(2*pi*fc*t + m_int); 44 | plot_in_time(St, fs_res, 'NBFM modulated signal in time domain'); 45 | plot_in_frequency(abs(fftshift(fft(St))),fs_res,'NBFM modulated signal in Frequency domain'); 46 | 47 | %St = A.*cos(2*pi*fc*t)-m_int;%.*sin(2*pi*fc*t); 48 | fourier = fftshift(fft(St)); 49 | %------------------------------------------------Demodulation------------------------------------------------------------------------ 50 | %------------------------------convert FM to AM---------------------------- 51 | %AM = A.*(2*pi*fc+kf*yt_resampled).*sin(2*pi*fc*t+m_int); 52 | AM = diff(St); 53 | AM = [0 AM]; 54 | %plot_in_frequency(abs(fftshift(fft(AM))), fs, 'lel'); 55 | [yt_demod, yf_demod] = env_demod(AM,fs_res,fs,0,0); 56 | 57 | plot_in_time(yt_demod,fs,'NBFM demodulated signal in time domain using envelope detector'); 58 | plot_in_frequency(yf_demod,fs,'NBFM demodulated signal in frequency domain using envelope detector'); 59 | 60 | %sound(yt_demod,fs); -------------------------------------------------------------------------------- /am_modulation.m: -------------------------------------------------------------------------------- 1 | %{ 2 | plot_in_time 3 | plot_in_frequency 4 | generate_filter 5 | env_demod 6 | coh_demod 7 | %} 8 | 9 | 10 | %-------------------------------------------------clear-------------------------------------------------------------------- 11 | clc; 12 | close all; 13 | clear all; 14 | %-------------------------------------------------read file-------------------------------------------------------------------- 15 | FILE = 'eric.wav'; 16 | fc = 100000; 17 | fs_res = 5*fc; 18 | modulation_index = 0.5; 19 | [yt, fs]= audioread(FILE); 20 | max_amp = max(abs(yt)); 21 | f_filter = 4000; 22 | %-------------------------------------------------plotting-------------------------------------------------------------------- 23 | plot_in_time(yt,fs,'Signal in time domain'); 24 | %-------------------------------------------------message in frequency domain-------------------------------------------------------------------- 25 | yf = fftshift(fft(yt)); 26 | %-------------------------------------------------plotting-------------------------------------------------------------------- 27 | plot_in_frequency(real(yf),fs,'Signal in frequency domain'); 28 | %-------------------------------------------------filter-------------------------------------------------------------------- 29 | filter = generate_filter(length(yf),fs,f_filter); 30 | yf_filtered = filter.*yf; 31 | %-------------------------------------------------plotting-------------------------------------------------------------------- 32 | plot_in_frequency(real(filter),fs,'Filter'); 33 | plot_in_frequency(real(yf_filtered),fs,'Filtered message in frequency domain'); 34 | 35 | %-------------------------------------------------back to time domain-------------------------------------------------------------------- 36 | yt_filtered= real(ifft(ifftshift(yf_filtered))); 37 | %-------------------------------------------------sound-------------------------------------------------------------------- 38 | %sound(yt_filtered,fs); 39 | %-------------------------------------------------plotting-------------------------------------------------------------------- 40 | t = linspace(0,length(yt_filtered)/fs, length(yt_filtered)); 41 | plot_in_time(yt_filtered,fs, 'Filtered signal in time domain'); 42 | %-------------------------------------------------resmple-------------------------------------------------------------------- 43 | yt_resampled = resample(yt_filtered,fs_res,fs); 44 | 45 | %-------------------------------------------------carrier signal-------------------------------------------------------------------- 46 | t_carr = linspace(0,length(yt_resampled)/fs_res, length(yt_resampled)); %(x2-x1)/(n-1) = 1/5*fc, linspace(x1,x2,n) 47 | carrier_t = cos(2*pi*fc*t_carr).'; 48 | carrier_f = fftshift(fft(carrier_t)); 49 | 50 | 51 | 52 | 53 | %-------------------------------------------------DSBSC modulation-------------------------------------------------------------------- 54 | yt_sc = carrier_t.*yt_resampled; 55 | yf_sc = fftshift(fft(yt_sc)); 56 | %sound(yt_sc, fs); 57 | 58 | 59 | %-------------------------------------------------plotting-------------------------------------------------------------------- 60 | plot_in_time(yt_sc,fs_res,'DSBSC modulated signal in time domain'); 61 | plot_in_frequency(real(yf_sc),fs_res,'DSBSC modulated signal in frequency domain'); 62 | 63 | %-------------------------------------------------DSBTC modulation-------------------------------------------------------------------- 64 | max_message = max(abs(yt_resampled)); 65 | A = 2*max_message; 66 | yt_tc = (A+yt_resampled).*carrier_t; 67 | yf_tc = fftshift(fft(yt_tc)); 68 | %-------------------------------------------------plotting-------------------------------------------------------------------- 69 | plot_in_time(yt_tc,fs_res,'DSBTC modulated signal in time domain'); 70 | plot_in_frequency(real(yf_tc),fs_res,'DSBTC modulated signal in frequency domain'); 71 | %sound(yt_tc,fs); 72 | 73 | 74 | %-------------------------------------------------DSBSC envelope detector demodulation-------------------------------------------------------------------- 75 | [yt_sc_env, yf_sc_env] = env_demod(yt_sc,fs_res,fs,0,0); 76 | %-------------------------------------------------plotting-------------------------------------------------------------------- 77 | plot_in_time(yt_sc_env, fs, 'DSBSC demodulated signal in time domain using envelope detector'); 78 | plot_in_frequency(real(yf_sc_env), fs, 'DSBSC demodulated signal in frequency domain using envelope detector'); 79 | %-------------------------------------------------sound-------------------------------------------------------------------- 80 | %sound(yt_sc_env,fs); %should not be good 81 | 82 | 83 | 84 | 85 | %################################################################################################################################################################# 86 | %-------------------------------------------------DSBTC no snr envelope detector demodulation-------------------------------------------------------------------- 87 | [yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,0,0); 88 | %-------------------------------------------------plotting-------------------------------------------------------------------- 89 | plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal no snr, in time domain using envelope detector'); 90 | plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal no snr in frequency domain using envelope detector'); 91 | %-------------------------------------------------sound-------------------------------------------------------------------- 92 | %sound(yt_tc_env,fs); %should be good 93 | 94 | 95 | %-------------------------------------------------DSBTC 0 snr envelope detector demodulation-------------------------------------------------------------------- 96 | [yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,1,0); 97 | %-------------------------------------------------plotting-------------------------------------------------------------------- 98 | plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal snr=0, in time domain using envelope detector'); 99 | plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal snr=0, in frequency domain using envelope detector'); 100 | %-------------------------------------------------sound-------------------------------------------------------------------- 101 | %sound(yt_tc_env,fs); 102 | 103 | 104 | %-------------------------------------------------DSBTC 10 snr envelope detector demodulation-------------------------------------------------------------------- 105 | [yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,1,10); 106 | %-------------------------------------------------plotting-------------------------------------------------------------------- 107 | plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal snr=10, in time domain using envelope detector'); 108 | plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal snr=10, in frequency domain using envelope detector'); 109 | %-------------------------------------------------sound-------------------------------------------------------------------- 110 | %sound(yt_tc_env,fs); 111 | 112 | %-------------------------------------------------DSBTC 30 snr envelope detector demodulation-------------------------------------------------------------------- 113 | [yt_tc_env, yf_tc_env] = env_demod(yt_tc,fs_res,fs,1,30); 114 | %-------------------------------------------------plotting-------------------------------------------------------------------- 115 | plot_in_time(yt_tc_env, fs, 'DSBTC demodulated signal snr=30, in time domain using envelope detector'); 116 | plot_in_frequency(real(yf_tc_env), fs, 'DSBTC demodulated signal snr=30, in frequency domain using envelope detector'); 117 | %-------------------------------------------------sound-------------------------------------------------------------------- 118 | %sound(yt_tc_env,fs); 119 | %################################################################################################################################################################# 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | %################################################################################################################################################################# 159 | %-------------------------------------------------DSBSC no snr coherent demodulation-------------------------------------------------------------------- 160 | [yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,0,0,fc,0,f_filter); 161 | %-------------------------------------------------plotting-------------------------------------------------------------------- 162 | plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal no snr in time domain using coherent detector'); 163 | plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal no snr in frequency domain using coherent detector'); 164 | %-------------------------------------------------sound-------------------------------------------------------------------- 165 | % sound(real(yt_sc_coh),fs); %should be good 166 | 167 | %-------------------------------------------------DSBSC 0 snr coherent demodulation-------------------------------------------------------------------- 168 | [yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,1,0,fc,0,f_filter); 169 | %-------------------------------------------------plotting-------------------------------------------------------------------- 170 | plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal snr=0, in time domain using coherent detector'); 171 | plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal snr=0, in frequency domain using coherent detector'); 172 | %-------------------------------------------------sound-------------------------------------------------------------------- 173 | %sound(real(yt_sc_coh),fs); %should be good 174 | 175 | 176 | %-------------------------------------------------DSBSC 10 snr coherent demodulation-------------------------------------------------------------------- 177 | [yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,1,10,fc,0,f_filter); 178 | %-------------------------------------------------plotting-------------------------------------------------------------------- 179 | plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal snr=10, in time domain using coherent detector'); 180 | plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal snr=10, in frequency domain using coherent detector'); 181 | %-------------------------------------------------sound-------------------------------------------------------------------- 182 | %sound(real(yt_sc_coh),fs); 183 | 184 | 185 | %-------------------------------------------------DSBSC 30 snr coherent demodulation-------------------------------------------------------------------- 186 | [yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,1,30,fc,0,f_filter); 187 | %-------------------------------------------------plotting-------------------------------------------------------------------- 188 | plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal snr=30, in time domain using coherent detector'); 189 | plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal snr=30 in frequency domain using coherent detector'); 190 | %-------------------------------------------------sound-------------------------------------------------------------------- 191 | %sound(real(yt_sc_coh),fs); 192 | %################################################################################################################################################################# 193 | 194 | 195 | 196 | 197 | 198 | 199 | %-------------------------------------------------DSBSC no snr coherent demodulation with fc error-------------------------------------------------------------------- 200 | [yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,0,0,fc+100,0,f_filter); 201 | %-------------------------------------------------plotting-------------------------------------------------------------------- 202 | plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal in time domain using coherent detector with fc error'); 203 | plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal in frequency domain using coherent detector with fc error'); 204 | %-------------------------------------------------sound-------------------------------------------------------------------- 205 | % sound(real(yt_sc_coh),fs); 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | %-------------------------------------------------DSBSC no snr coherent demodulation with phase shift -------------------------------------------------------------------- 216 | phaseshift = degtorad(20); 217 | [yt_sc_coh, yf_sc_coh] = coh_demod(yt_sc,fs_res,fs,0,0,fc,phaseshift,f_filter); 218 | %-------------------------------------------------plotting-------------------------------------------------------------------- 219 | plot_in_time(real(yt_sc_coh), fs, 'DSBSC demodulated signal in time domain using coherent detector with phase shift'); 220 | plot_in_frequency(real(yf_sc_coh), fs, 'DSBSC demodulated signal in frequency domain using coherent detector with phase shift'); 221 | %-------------------------------------------------sound-------------------------------------------------------------------- 222 | %sound(real(yt_sc_coh),fs); 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | --------------------------------------------------------------------------------