Getting started guide

This commit is contained in:
Adog64 2025-01-16 18:34:22 -05:00
parent a8d165aa1a
commit 1522fce3cd
16 changed files with 138 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

View File

@ -0,0 +1,43 @@
# Getting Started with Python for DSP
In this tutorial set, I will start with a fresh installation of Windows 10. The steps should be similar, if not identical, if you are using Windows 11. If you are running macOS, please follow along as best as possible. Finally, if you are running Linux, please let me know, and I will help you.
If you run into any issues, please reach out to Aidan Sharpe via email:
[sharpe23@students.rowan.edu](mailto:sharpe23@students.rowan.edu?subject=DSP%20Help%20-%20FULL%20NAME) subject line: **DSP Help - FULL NAME**.
## The Python Language
Recall your Computer Science & Programming and Introduction to Embedded Systems classes. You are familiar with C and C++, where by compiling `.c` or `.cpp` file, you generate an executable `.exe` file. Both C and C++ are considered *compiled languages* for this reason. You can email the `.exe` file to a friend, and without any code (or even a compiler) they can run your file on their machine. When this file is executed, it runs in its own *process* on the operating system, which you can see by opening your task manager while the program is still running.
Python is *not* a compiled language. Instead, it is what we call an interpreted language. Rather than creating an executable file, the code is run line-by-line by a program called an interpreter. In the next section, we will install the Python Interpreter. Importantly, since no executable file is created, anyone who wants to run your code will have to run it with their own Python Interpreter. Additionally, unlike a compiled language, the program does not have its own OS process. In the case of Python 3, your program will run in the `python` process.
## Installing Python
Before we begin writing any code, we need to install the Python Interpreter. These installation instructions are, as noted prviously, targetted at Windows 10/11 users. If you happen to be running Linux, you probably already have a Python interpreter installed, especially if you are running a "just works" distribution such as Ubuntu or Fedora. If you happen to be running macOS, please follow the installation instructions on [python.org](https://www.python.org/downloads/macos/).
\newpage
### 1. Open the Microsoft Store
On you taskbar or "Start" menu, open the "Microsoft Store" application.
![](open-microsoft-store.png)
### 2. Search for "python 3.13"
In the Microsoft Store, search for "python 3.13" and click the result titled "Python 3.13". This is the interpreter and runtime we will be using.
![](search-for-python-3.13.png)
\newpage
### 4. Click "Get"
Click the "Get" button to install the application. Wait for the installation to complete.
![](click-get.png)
### 5. Verify installation
Open your "Start" menu and see if Python 3.13 and IDLE are shown.
![](recently-installed.png)
\newpage
## Hello World
Start by opening "Python 3.13". This is the *Python Interpreter* we mentioned earlier. When run directly as an application, we are met with the *Python Shell*. Here, we can type Python code, and it will be executed as we go. For example, we can write a one-line "Hello, World" style program simply by typing `print("Hello, World!")` and hitting the enter key. The text "Hello, World!" will be printed, and we are prompted again on the following line. We can change the text inside the quotes to whatever we want, and that text will be printed out as well. Congratulations, you have run your first Python code!
![](hello-dsp.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

View File

@ -0,0 +1,16 @@
% Lab 1
% Question 1 on aliasing
fs=100; % Sampling frequency [Hz]
ts=1/fs; % Sampling period [s]
n=0:1:9; % Sample indicies
x20(n+1)=cos(2*pi*20*n*ts); % x[n] with f = 20 [Hz]
x80(n+1)=cos(2*pi*80*n*ts); % x[n] with f = 80 [Hz]
subplot(211) % Start top sub plot
stem(n,x20,'linewidth',2) % Plot samples of x[n] with f = 20[Hz] for all n
subplot(212) % Start bottom sub plot
stem(n,x80,'linewidth',2) % Plot samples of x[n] with f = 80[Hz] for all n
xlabel('f = 20 and 80 Hz'); % Label the x axis

View File

@ -0,0 +1,22 @@
import numpy as np
import matplotlib.pyplot as plt
def main():
f_s = 100 # Sample frequency [Hz]
T_s = 1/f_s # Sample period [s]
n = np.arange(10) # Samples starting at zero, up to, but not including 10
t = n*T_s # Convert from sample domain to time domain
x_20 = np.cos(2*np.pi*20*t) # Cosine signal x[n] with f = 20[Hz]
x_80 = np.cos(2*np.pi*80*t) # Cosine signal x[n] with f = 80[Hz]
plt.subplot(211) # Begin top subplot
plt.stem(n, x_20) # Plot samples of x (x_20) over sample indicies (n)
plt.subplot(212) # Begin bottom subplot
plt.stem(n, x_80) # Plot samples of x (x_80) over sample indicies (n)
plt.show() # Show the plot
if __name__ == "__main__":
main()

View File

@ -0,0 +1,13 @@
syms W
for k=1:24;
E(k)=single(int((sin(0.5*W)/(0.5*W))^2 ,W,0,k*pi)/pi);
end
stem(E,'linewidth',2);
hold on
EE=0.9900*ones(1,24);
plot(EE,'r','linewidth',2)
set(gca,'XTick',0:5:25)
set(gca,'XTickLabel',{'0','5\pi','10\pi','15\pi','20\pi','25\pi'})
xlabel('Angular frequency')
ylabel('Signal Energy')
axis([0 25 0 1.1])

View File

@ -0,0 +1,2 @@
syms t
a=simplify(fourier(sin(0.5*t)/(0.5*t)))

View File

@ -0,0 +1,12 @@
% Lab 1
% Question 4
fs=4;
ts=1/fs;
n=0:1:99;
x(n+1)=cos(2*pi*n*ts/5)+sin(4*pi*n*ts/7)+cos(16*pi*n*ts/9);
stem(n,x,'linewidth',2);
xlabel('n')
ylabel('x(n)')

View File

@ -0,0 +1,3 @@
syms t
f=exp(-t*4)*heaviside(t);
ff=fourier(f);

View File

@ -0,0 +1,9 @@
syms a b t
assume(a > 0)
f = exp(-a*abs(t));
ff = fourier(f);
assume(b > 0)
g = f*cos(b*t);
gg = simplify(fourier(g));

View File

@ -0,0 +1,18 @@
# Digital Signal Processing - Python Tutorials
\newpage
## Module 1
- The Python Language
- Installing Python
## Module 2
- Declaring variables
- Decision statements
- Defining functions
- Importing modules
## Module 3
- Installing packages
- Introducing numpy
- Introducing matplotlib
\newpage