CSE 432 Fall 2019 Lab 8

Task #1 Importing audio into MATLAB

The example below shows importing a sound and plotting it.

clear
close all
clc
sample=length(y);
totaltime=sample/Fs;
t=1:sample;
t=t/Fs;
y_fft = abs(fft(y));
y_fft = y_fft(1:sample/2);
f = Fs*(0:sample/2-1)/sample;
figure
plot(t,y)
figure
plot(f, y_fft)

Task #2 Playing audio into MATLAB

Any sound generated using MATLAB and imported in MATLAB can be listened using soundsc(y, Fs); function

Below is an extension of the previous example.

clear
close all
clc
sample=length(y);
totaltime=sample/Fs;

t=1:sample;
t=t/Fs;

y_fft = abs(fft(y));
y_fft = y_fft(1:sample/2);
f = Fs*(0:sample/2-1)/sample;
soundsc(y, Fs);

figure
plot(t,y)
figure
plot(f, y_fft)

Task #3 Creating and playing different into MATLAB

The table below shows the frequency for different notes.

As an example

clear
close all
clc
L = 2;
fs = 11025;
Ts = 1/fs;
t  = 0:Ts:L-Ts;
w = 2*pi*440;
A = 5;
x = A * sin(w*t);
soundsc(x, fs);
plot(t,x);
xlabel('Time, t');
ylabel('Amplitude, x');
title('Simple Sine wave with Frequency 440Hz');
axis([0 2 -1 1]);

Now create different notes from the table.

Task #4 Creating and playing a beat note into MATLAB

A beat note is a phenomenon that occurs when two sinusoids of different frequencies are multiplied together.
Musicians are usually familiar with the beat note phenomena since it often occurs when two instruments that are slightly out of tune try to play the same note at the same time. The effect of
listening to this is of a ‘pulsing’ sound of varying amplitude depending on the amount of variation between instrument tunings.

Beat notes are a type of Amplitude Modulation (AM) which is a common technique in the communications field where it is used in radio communications.

Create another sinusoid of much lower frequency to the first (tens of Hz (for example 10) rather than hundreds of Hz(for example 440)) and multiply this new sinusoid with the first. Use soundsc() to listen to the new modulated signal (this signal may sound a bit like a dial-tone on a telephone).

xmod = x1.*x2; % .* performs vector multiplication of x1 and x2

Plot this signal on a new figure, change the x axis limits until you see approx. four periods of the signal and observe the ‘envelope’ of the waveform. (Envelope is another name for the amplitude fluctuations of the modulated waveform).

Task #5 Creating and playing a chirp note into MATLAB

A chirp is also called a linear frequency modulated (LFM) signal and occurs when the frequency of a sinusoid is increased or decreased linearly over time.

Chirp signals are useful in signal processing when examining the effects systems have on a varying range of frequencies or how a system responds to a wide bandwidth signal. A chirp can be mathematically produced by the following formula:

Where f0 is the initial starting frequency of the chirp and µ is a term (sometimes called the modulation index) which determines the rate of frequency change over time ( µ can be positive or
negative depending on whether the chirp increases or decreases in frequency over time).

Chirps are also a variant on a type of modulation called Frequency Modulation (FM) which again is a technique commonly used in radio communications.

Using the 2 second time vector created in task 1 create a chirp waveform by using equation above.

Set the initial frequency to 440 Hz and make sure the final frequency is double this (880 Hz).
Use soundsc() to listen to the chirp signal.

L = 2;
fs = 11025;
Ts = 1/fs;
t  = 0:Ts:L-Ts;
f0 = 440;
w = 2*pi*f0;
mu = 220;
x = cos(2*pi*(f0+t.*mu).*t);
N = length(t);
F = fs/N;
f = f0+t*mu;
soundsc(x, fs);
plot(f,x);
xlabel('Frequency, f');
ylabel('Modulation, x');
title('Chirp Signal');

Change µ and the initial frequency to create chirps that start and end at the following frequencies:

Visualize frequency spectrum all the signal generated.

Use the MATLAB function spectrogram() to create spectrograms of the chirp signals generated in the last task.
Set window and nfft to 1024, leave noverlap blank ([]) to give a 50% overlap between windows.
Make sure the colorbar is active on the figure (type in colorbar or select Insertcolorbar on the figure window).

Task #7 Creating the first AM signal

Create a new MATLAB file and set up time and frequency vectors for a signal that will be 3 seconds long.
The first signal to be created is a sinusoid, amplitude modulated with a decaying exponential envelope. E.g.

To do this start by creating the sinusoid with frequency fm = 350 Hz
Now multiply this sinusoid with the exponential envelope I0et /τ , set τ = 1 and I0 = 3 to start with.

Plot this initial signal.
Use soundsc() to also listen to the amplitude modulated signal.

We next want to use this signal to frequency modulate another sinusoidal signal:

We have x(t) from the previous task so now use MATLAB to generate this new frequency modulated signal by setting fc= 250 Hz and including the added x(t) component.
Plot this new waveform and use soundsc() to listen to it as well. This is now sounding a lot like a bell, but it’s not perfect yet.

Task #9 Application of final envelope

Finally we need to apply the final envelope to the bell sound, this envelope is identical to the envelope generated originally in task 7:

Multiply y(t) with this envelope and use soundsc() to listen to the final bell sound.

Plot this final waveform

Use some of the parameters in Table below to change the sound of the bell.

Parameters for bell sound