Samar Qureshi

1009149583

Part A

Low → High

image.png

High → Low

image.png

Low → High → Low

image.png

High → Low → High

image.png


Fs = 8000;        
To = 0.5;        
t = 0:1/Fs:To-1/Fs;

%linear chirp from f_start to f_end over duration To
make_chirp = @(f_start, f_end) cos( 2*pi * (f_start .* t + ((f_end - f_start)/(2*To)) .* (t.^2) ) );
f_low  = 300;    
f_high = 1500;   

% 1) low -> high
sig_A = make_chirp(f_low, f_high);

% 2) high -> low
sig_B = make_chirp(f_high, f_low);

% 3) low -> high -> low
sig_C = [ make_chirp(f_low,  f_high), make_chirp(f_high, f_low ) ];

% 4) high -> low -> high
sig_D = [ make_chirp(f_high, f_low ), make_chirp(f_low,  f_high) ];

figure;

tA = (0:length(sig_A)-1)/Fs;
tB = (0:length(sig_B)-1)/Fs;
tC = (0:length(sig_C)-1)/Fs;
tD = (0:length(sig_D)-1)/Fs;

subplot(4,2,1);
plot(tA, sig_A);
xlabel('Time [s]'); ylabel('Amp');
title('A: low tohigh');

subplot(4,2,3);
plot(tB, sig_B);
xlabel('Time [s]'); ylabel('Amp');
title('B: high to  low');

subplot(4,2,5);
plot(tC, sig_C);
xlabel('Time [s]'); ylabel('Amp');
title('C: low high low');

subplot(4,2,7);
plot(tD, sig_D);
xlabel('Time [s]'); ylabel('Amp');
title('D: high low high');

% window=256, overlap=200, nfft=256
subplot(4,2,2);
spectrogram(sig_A, 256, 200, 256, Fs, 'yaxis');
title('Spec A');

subplot(4,2,4);
spectrogram(sig_B, 256, 200, 256, Fs, 'yaxis');
title('Spec B');

subplot(4,2,6);
spectrogram(sig_C, 256, 200, 256, Fs, 'yaxis');
title('Spec C');

subplot(4,2,8);
spectrogram(sig_D, 256, 200, 256, Fs, 'yaxis');
title('Spec D');

Part B

image.png

Fs      = 8000;     
tone_f  = 600;      
Tdot    = 0.08;     
t_dot   = 0:1/Fs:Tdot-1/Fs;
t_dash  = 0:1/Fs:(3*Tdot)-1/Fs;

dot_tone  = cos(2*pi*tone_f*t_dot);
dash_tone = cos(2*pi*tone_f*t_dash);

gap_symbol = zeros(size(t_dot));        % silence of 1 dot between symbols in same letter
gap_letter = zeros(1, round(4*Tdot*Fs));% silence of 4 dots between letters

% lookup table for morse
morseMap = containers.Map( ...
{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', ...
 '0','1','2','3','4','5','6','7','8','9', ...
 ' '}, ...
{'.-','-...','-.-.','-..','.', '..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..', ...
 '-----','.----','..---','...--','....-','.....','-....','--...','---..','----.', ...
 ' '} );

msg = 'HELLO SAMAR IS HERE'; 
msg = upper(msg);

full_signal = [];

for ch = 1:length(msg)
    c = msg(ch);

    if ~isKey(morseMap, c)
        continue; 
    end

    code = morseMap(c);  

    if c == ' ' 
				%% extra silence b/w worsd
        full_signal = [full_signal, zeros(1, round(7*Tdot*Fs))];
        continue;
    end

    % single letter
    letter_sig = [];
    for k = 1:length(code)
        if code(k)=='.'
            letter_sig = [letter_sig, dot_tone];
        elseif code(k)=='-'
            letter_sig = [letter_sig, dash_tone];
        end

        if k < length(code)
            letter_sig = [letter_sig, gap_symbol];
        end
    end
    letter_sig = [letter_sig, gap_letter];
    full_signal = [full_signal, letter_sig];
end

figure;
plot((0:length(full_signal)-1)/Fs, full_signal);

xlabel('Time [s]');
ylabel('Amplitude');
title('HELLO SAMAR IS HERE');
grid on;