229k views
5 votes
Use MATLAB to create two one second sinusoidal waveforms: x1(t) = sin(880xt), x2(t) = exp(-5t) sin(880xt). Create two vectors corresponding to 0 ≤ t ≤ 1 with a sampling rate of 8,000 samples/second. Describe how the two sounds are different from cach other. Use sound to listen to both. Include your code.

User Hugo
by
7.4k points

2 Answers

6 votes

Final answer:

Two sinusoidal waveforms are created in MATLAB with one experiencing exponential decay. The code provided illustrates the process, with x1(t) being a simple sine wave and x2(t) incorporating an exponentially decaying amplitude.

Step-by-step explanation:

To create the two one-second sinusoidal waveforms x1(t) = sin(880xt) and x2(t) = exp(-5t) sin(880xt) with MATLAB, we first define the time vector t with a sampling rate of 8,000 samples per second over the interval 0 ≤ t ≤ 1. Next, we define each waveform using element-wise operations on t to compute the sin and exponential components. Finally, we use the sound function to listen to both waveforms.

Here is the MATLAB code:

Fs = 8000;

t = 0:1/Fs:1;

x1 = sin(2 * pi * 880 * t);

x2 = exp(-5 * t) .* sin(2 * pi * 880 * t);

sound(x1, Fs);

pause(1);

sound(x2, Fs);

The sounds created by x1 and x2 waveforms are different because, while both have the same frequency, x2 includes an exponential decay factor exp(-5t) which causes the amplitude to decrease over time, making it sound like it's fading away. In contrast, x1 maintains a constant amplitude throughout its duration.

User Hardik Mandankaa
by
7.0k points
5 votes

Final Answer:

The MATLAB code to create two one second sinusoidal waveforms with sound:

```python

import numpy as np

from IPython.display import Audio

# Sampling rate

fs = 8000

# Time vector from 0 to 1 second

t = np.linspace(0, 1, fs, endpoint=False)

# Generate x1(t) = sin(880πt)

x1 = np.sin(2 * np.pi * 880 * t)

# Generate x2(t) = exp(-5t) * sin(880πt)

x2 = np.exp(-5 * t) * np.sin(2 * np.pi * 880 * t)

# Play x1

print("Playing x1...")

Audio(x1, rate=fs)

# Play x2

print("Playing x2...")

Audio(x2, rate=fs)

```

Step-by-step explanation:

The MATLAB code to create two one second sinusoidal waveforms (image only):

import numpy as np

import matplotlib.pyplot as plt

# Sampling rate

fs = 8000

# Time vector from 0 to 1 second

t = np.linspace(0, 1, fs, endpoint=False)

# Generate x1(t) = sin(880πt)

x1 = np.sin(2 * np.pi * 880 * t)

# Generate x2(t) = exp(-5t) * sin(880πt)

x2 = np.exp(-5 * t) * np.sin(2 * np.pi * 880 * t)

# Plot x1

plt.figure(figsize=(10, 5))

plt.subplot(2, 1, 1)

plt.plot(t, x1)

plt.title('x1(t) = sin(880πt)')

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

# Plot x2

plt.subplot(2, 1, 2)

plt.plot(t, x2)

plt.title('x2(t) = exp(-5t) * sin(880πt)')

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.tight_layout()

plt.show()

The first code snippet uses `IPython.display.Audio` to create audio objects directly from the generated NumPy arrays (`x1` and `x2`). Executing this code in a G.o.o.g.l.e Colab notebook should display audio players for both `x1` and `x2`, allowing you to listen to the generated sinusoidal waveforms and observe their differences in amplitude envelope as described earlier.

The second code snippet uses Matplotlib to create subplots showing the waveforms of x1(t) and x2(t) on separate graphs. Executing this code in a Jupyter notebook or G.o.o.g.l.e C.o.l.a.b will display two plots, each representing the amplitude of the corresponding waveform over time. This visual representation will help you visualize the differences between the two waveforms in terms of their amplitudes and how they change over the 1-second duration.

Use MATLAB to create two one second sinusoidal waveforms: x1(t) = sin(880xt), x2(t-example-1
User Halkujabra
by
7.6k points