Compare commits
30 Commits
47358d25a8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1340ff2a0e | ||
|
|
e2398a8a39 | ||
|
|
6a996f1c09 | ||
|
|
68ffcf4956 | ||
|
|
a38c21b1a9 | ||
|
|
54bf5ca168 | ||
|
|
df2c11ae67 | ||
|
|
c501581f39 | ||
|
|
dc9bda2b37 | ||
|
|
2f3f75d3f2 | ||
| aebff3d595 | |||
|
|
83fb593dd6 | ||
|
|
764bb967f6 | ||
| d558d5834e | |||
|
|
21e87884c6 | ||
|
|
c968a3ae00 | ||
|
|
6726a156b3 | ||
| a10a010701 | |||
|
|
f4af875bb3 | ||
|
|
4b57659747 | ||
|
|
c7f48c6fe9 | ||
| 594aa545da | |||
| 286a3d2f32 | |||
| df94c4721b | |||
|
|
2fa41ea756 | ||
|
|
4eb7cd640b | ||
|
|
5f52c8b518 | ||
|
|
0e9f89d331 | ||
|
|
44447ec5b8 | ||
|
|
df21d69df4 |
@@ -7,15 +7,15 @@ This is a git repository for the FlareBlog. The Blog is based on [Hugo](https://
|
||||
Clone the repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/JamesFlare1212/FlareBlog.git
|
||||
git clone --recurse-submodules https://github.com/JamesFlare1212/FlareBlog.git
|
||||
```
|
||||
|
||||
Then, install Hugo.
|
||||
|
||||
For Linux:
|
||||
```bash
|
||||
wget https://github.com/gohugoio/hugo/releases/download/v0.136.5/hugo_extended_0.136.5_linux-amd64.deb
|
||||
dpkg -i hugo_extended_0.136.5_linux-amd64.deb
|
||||
wget https://github.com/gohugoio/hugo/releases/download/v0.146.0/hugo_extended_0.146.0_linux-amd64.deb
|
||||
sudo dpkg -i hugo_extended_0.146.0_linux-amd64.deb
|
||||
```
|
||||
|
||||
For MacOS:
|
||||
|
||||
@@ -46,9 +46,8 @@ details summary strong {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.katex-display {
|
||||
overflow-x: auto;
|
||||
overflow-y: clip;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# Hugo Configuration
|
||||
# See: https://gohugo.io/getting-started/configuration/
|
||||
# -------------------------------------------------------------------------------------
|
||||
|
||||
#ignoreLogs = ['error-get-gh-repo', 'error-get-remote-json']
|
||||
# website title
|
||||
title = "FlareBlog"
|
||||
# Hostname (and path) to the root
|
||||
@@ -25,7 +25,8 @@ languageName = "English"
|
||||
# whether to include Chinese/Japanese/Korean
|
||||
hasCJKLanguage = true
|
||||
# default amount of posts in each pages
|
||||
paginate = 12
|
||||
[pagination]
|
||||
pagerSize = 12
|
||||
# copyright description used only for seo schema
|
||||
copyright = ""
|
||||
# whether to use robots.txt
|
||||
@@ -113,6 +114,11 @@ enableEmoji = true
|
||||
table = true
|
||||
taskList = true
|
||||
typographer = true
|
||||
[markup.goldmark.extensions.passthrough]
|
||||
enable = true
|
||||
[markup.goldmark.extensions.passthrough.delimiters]
|
||||
block = [['\[', '\]'], ['$$', '$$']]
|
||||
inline = [['\(', '\)'], ['$', '$']]
|
||||
# https://gohugo.io/getting-started/configuration-markup/#extras
|
||||
[markup.goldmark.extensions.extras]
|
||||
[markup.goldmark.extensions.extras.delete]
|
||||
@@ -167,7 +173,7 @@ enableEmoji = true
|
||||
# -------------------------------------------------------------------------------------
|
||||
|
||||
[privacy]
|
||||
[privacy.twitter]
|
||||
[privacy.x]
|
||||
enableDNT = true
|
||||
[privacy.youtube]
|
||||
privacyEnhanced = true
|
||||
@@ -854,8 +860,8 @@ enableEmoji = true
|
||||
appKey = ""
|
||||
placeholder = ""
|
||||
avatar = "mp"
|
||||
meta = ""
|
||||
requiredFields = ""
|
||||
meta = ['nick','mail','link']
|
||||
requiredFields = []
|
||||
pageSize = 10
|
||||
lang = ""
|
||||
visitor = true
|
||||
@@ -1063,7 +1069,7 @@ enableEmoji = true
|
||||
|
||||
# Analytics config
|
||||
[params.analytics]
|
||||
enable = false
|
||||
enable = true
|
||||
# Google Analytics
|
||||
[params.analytics.google]
|
||||
id = ""
|
||||
@@ -1074,6 +1080,31 @@ enableEmoji = true
|
||||
id = ""
|
||||
# server url for your tracker if you're self hosting
|
||||
server = ""
|
||||
# FixIt 0.3.16 | NEW Baidu Analytics
|
||||
[params.analytics.baidu]
|
||||
id = ""
|
||||
# FixIt 0.3.16 | NEW Umami Analytics
|
||||
[params.analytics.umami]
|
||||
data_website_id = "c687e659-a8de-4d17-a794-0fb82dd085f5"
|
||||
src = "https://track.jamesflare.com/script.js"
|
||||
data_host_url = "https://track.jamesflare.com"
|
||||
data_domains = ""
|
||||
# FixIt 0.3.16 | NEW Plausible Analytics
|
||||
[params.analytics.plausible]
|
||||
data_domain = ""
|
||||
src = ""
|
||||
# FixIt 0.3.16 | NEW Cloudflare Analytics
|
||||
[params.analytics.cloudflare]
|
||||
token = ""
|
||||
# FixIt 0.3.16 | NEW Splitbee Analytics
|
||||
[params.analytics.splitbee]
|
||||
enable = false
|
||||
# no cookie mode
|
||||
no_cookie = true
|
||||
# respect the do not track setting of the browser
|
||||
do_not_track = true
|
||||
# token(optional), more info on https://splitbee.io/docs/embed-the-script
|
||||
data_token = ""
|
||||
|
||||
# Cookie consent config
|
||||
[params.cookieconsent]
|
||||
@@ -1155,6 +1186,8 @@ enableEmoji = true
|
||||
# Depends on open custom blocks https://fixit.lruihao.cn/references/blocks/
|
||||
[params.customPartials]
|
||||
head = []
|
||||
menuDesktop = []
|
||||
menuMobile = []
|
||||
profile = []
|
||||
aside = []
|
||||
comment = []
|
||||
|
||||
BIN
content/en/posts/csci-1100/crib-sheets/Final Crib Sheet A.pdf
Normal file
BIN
content/en/posts/csci-1100/crib-sheets/Test 2 Crib Sheet A.pdf
Normal file
BIN
content/en/posts/csci-1100/crib-sheets/Test 2 Crib Sheet B.pdf
Normal file
BIN
content/en/posts/csci-1100/crib-sheets/Test 3 Crib Sheet A.pdf
Normal file
BIN
content/en/posts/csci-1100/crib-sheets/Test 3 Crib Sheet B.pdf
Normal file
84
content/en/posts/csci-1100/crib-sheets/index.md
Normal file
@@ -0,0 +1,84 @@
|
||||
---
|
||||
title: CSCI 1100 - Test Crib Sheets
|
||||
subtitle:
|
||||
date: 2024-12-08T22:17:36-05:00
|
||||
lastmod: 2024-12-08T22:17:36-05:00
|
||||
slug: csci-1100-crib-sheets
|
||||
draft: false
|
||||
author:
|
||||
name: James
|
||||
link: https://www.jamesflare.com
|
||||
email:
|
||||
avatar: /site-logo.avif
|
||||
description: This post shares the crib sheets I have been used in Test 2, Test 3 and Final of CSCI 1100.
|
||||
keywords:
|
||||
license:
|
||||
comment: true
|
||||
weight: 0
|
||||
tags:
|
||||
- CSCI 1100
|
||||
- Exam
|
||||
- RPI
|
||||
- Python
|
||||
- Programming
|
||||
categories:
|
||||
- Programming
|
||||
collections:
|
||||
- CSCI 1100
|
||||
hiddenFromHomePage: false
|
||||
hiddenFromSearch: false
|
||||
hiddenFromRss: false
|
||||
hiddenFromRelated: false
|
||||
summary: This post shares the crib sheets I have been used in Test 2, Test 3 and Final of CSCI 1100.
|
||||
resources:
|
||||
- name: featured-image
|
||||
src: featured-image.jpg
|
||||
- name: featured-image-preview
|
||||
src: featured-image-preview.jpg
|
||||
toc: true
|
||||
math: false
|
||||
lightgallery: false
|
||||
password:
|
||||
message:
|
||||
repost:
|
||||
enable: false
|
||||
url:
|
||||
|
||||
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
|
||||
---
|
||||
|
||||
<!--more-->
|
||||
|
||||
> [!TIP]
|
||||
> You can edit this PDF with Adobe Photoshop. Yes, you are correct! I made this PDF by Photoshop. The font have been used in these crib sheets is [Intel One Mono](https://github.com/intel/intel-one-mono).
|
||||
|
||||
## Test 1 Crib Sheet
|
||||
|
||||
> [!NOTE]
|
||||
> I didn't use a crib sheet in test 1. So, not crib sheets here.
|
||||
|
||||
## Test 2 Crib Sheet
|
||||
|
||||
<div style="width: 100%; max-width: 600px; margin: 0 auto; display: block;">
|
||||
<embed src="Test 2 Crib Sheet A.pdf" type="application/pdf" width="100%" height="500px">
|
||||
</div>
|
||||
|
||||
<div style="width: 100%; max-width: 600px; margin: 0 auto; display: block;">
|
||||
<embed src="Test 2 Crib Sheet B.pdf" type="application/pdf" width="100%" height="500px">
|
||||
</div>
|
||||
|
||||
## Test 3 Crib Sheet
|
||||
|
||||
<div style="width: 100%; max-width: 600px; margin: 0 auto; display: block;">
|
||||
<embed src="Test 3 Crib Sheet A.pdf" type="application/pdf" width="100%" height="500px">
|
||||
</div>
|
||||
|
||||
<div style="width: 100%; max-width: 600px; margin: 0 auto; display: block;">
|
||||
<embed src="Test 3 Crib Sheet B.pdf" type="application/pdf" width="100%" height="500px">
|
||||
</div>
|
||||
|
||||
## Final Crib Sheet
|
||||
|
||||
<div style="width: 100%; max-width: 600px; margin: 0 auto; display: block;">
|
||||
<embed src="Final Crib Sheet A.pdf" type="application/pdf" width="100%" height="500px">
|
||||
</div>
|
||||
@@ -10,7 +10,7 @@ author:
|
||||
email:
|
||||
avatar: /site-logo.avif
|
||||
description: This blog post provides a detailed overview of a Python programming homework assignment, which includes creating a Mad Libs game, calculating speed and pace, and generating a framed box with user-specified dimensions.
|
||||
keywords: ["Python", "programming", "homework", "Mad Libs", "speed calculation", "framed box"]
|
||||
keywords: ["Python", "Programming", "Homework", "Mad Libs", "Speed calculation", "Framed box"]
|
||||
license:
|
||||
comment: true
|
||||
weight: 0
|
||||
@@ -120,8 +120,6 @@ We will test your code for the values used in our examples as well as a range of
|
||||
|
||||
{{< link href="HW1.zip" content="HW1.zip" title="Download HW1.zip" download="HW1.zip" card=true >}}
|
||||
|
||||
***
|
||||
|
||||
## Solution
|
||||
|
||||
### hw1_part1.py
|
||||
|
||||
@@ -182,8 +182,6 @@ Test your code well and when you are sure that it works, please submit it as a f
|
||||
|
||||
{{< link href="HW2.zip" content="HW2.zip" title="Download HW2.zip" download="HW2.zip" card=true >}}
|
||||
|
||||
***
|
||||
|
||||
## Solution
|
||||
|
||||
### hw2_part1.py
|
||||
|
||||
504
content/en/posts/csci-1200/hw-1/index.md
Normal file
@@ -0,0 +1,504 @@
|
||||
---
|
||||
title: CSCI 1200 - Homework 1 - Spotify Playlists
|
||||
subtitle:
|
||||
date: 2025-02-15T13:38:46-05:00
|
||||
lastmod: 2025-02-15T13:38:46-05:00
|
||||
slug: csci-1200-hw-1
|
||||
draft: false
|
||||
author:
|
||||
name: James
|
||||
link: https://www.jamesflare.com
|
||||
email:
|
||||
avatar: /site-logo.avif
|
||||
description: This blog post provides a detailed guide on developing a music playlist management program similar to Spotify using C++. It covers command-line parameter handling, file I/O operations, and the use of STL string and vector classes.
|
||||
keywords: ["C++", "Programming", "Homework", "STL Vector","Playlist Management"]
|
||||
license:
|
||||
comment: true
|
||||
weight: 0
|
||||
tags:
|
||||
- CSCI 1200
|
||||
- Homework
|
||||
- RPI
|
||||
- C++
|
||||
- Programming
|
||||
categories:
|
||||
- Programming
|
||||
collections:
|
||||
- CSCI 1200
|
||||
hiddenFromHomePage: false
|
||||
hiddenFromSearch: false
|
||||
hiddenFromRss: false
|
||||
hiddenFromRelated: false
|
||||
summary: This blog post provides a detailed guide on developing a music playlist management program similar to Spotify using C++. It covers command-line parameter handling, file I/O operations, and the use of STL string and vector classes.
|
||||
resources:
|
||||
- name: featured-image
|
||||
src: featured-image.jpg
|
||||
- name: featured-image-preview
|
||||
src: featured-image-preview.jpg
|
||||
toc: true
|
||||
math: false
|
||||
lightgallery: false
|
||||
password:
|
||||
message:
|
||||
repost:
|
||||
enable: false
|
||||
url:
|
||||
|
||||
# See details front matter: https://fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
|
||||
---
|
||||
|
||||
<!--more-->
|
||||
|
||||
## Assignment Requirements
|
||||
|
||||
{{< details >}}
|
||||
Before starting this homework, make sure you have read and understood the Academic Integrity Policy.
|
||||
|
||||
In this assignment you will develop a program to manage music playlists like Spotify does, let's call this program New York Playlists. Please read the entire handout before starting to code the assignment.
|
||||
|
||||
## Learning Objectives
|
||||
|
||||
- Practice handling command line arguments.
|
||||
- Practice handling file input and output.
|
||||
- Practice the C++ Standard Template Library string and vector classes.
|
||||
|
||||
## Command Line Arguments
|
||||
|
||||
Your program will be run like this:
|
||||
|
||||
```console
|
||||
./nyplaylists.exe playlist.txt actions.txt output.txt
|
||||
```
|
||||
|
||||
Here:
|
||||
|
||||
- nyplaylists.exe is the executable file name.
|
||||
- playlist.txt is the name of an input file which contains a playlist - in this README, we will refer to this file as the **playlist file**.
|
||||
- actions.txt is an input file which defines a sequence of actions - in this README, we will refer to this file as the **actions file**.
|
||||
- output.txt where to print your output to.
|
||||
|
||||
## Playlist File Format and Output File Format
|
||||
|
||||
The playlist file and the output file have the same format. Take the playlist_tiny1.txt as an example, this file has the following 4 lines:
|
||||
|
||||
```console
|
||||
"Perfect Duet" Ed Sheeran, Beyonce
|
||||
"Always Remember Us This Way" Lady Gaga current
|
||||
"Million Reasons" Lady Gaga
|
||||
"I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper
|
||||
```
|
||||
|
||||
Except the second line, each line has two fields, the music title, and the artist(s). There is one single space separating these two fields.
|
||||
|
||||
The second line is special, it ends with the word **current**, meaning that the song "Always Remember Us This Way" is the currently playing song. This word **current** appears in the **playlist file** once and should also appear in the output file once.
|
||||
|
||||
## Actions File Format
|
||||
|
||||
The actions file defines actions. Take actions1.txt as an example, this file has the following lines:
|
||||
|
||||
```console
|
||||
add "Umbrella" Rihanna
|
||||
add "We Are Young" Fun
|
||||
add "You Are Still the One" Shania Twain
|
||||
remove "Million Reasons" Lady Gaga
|
||||
add "Viva La Vida" Coldplay
|
||||
move "I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper 1
|
||||
next
|
||||
next
|
||||
next
|
||||
previous
|
||||
move "You Are Still the One" Shania Twain 4
|
||||
```
|
||||
|
||||
The **actions file** may include 5 different types of actions:
|
||||
|
||||
- add, which adds a song to the end of the playlist.
|
||||
- remove, which removes a song from the playlist.
|
||||
- move, which moves a song to a new position - the new position is always included at the end of the line. The line *move "I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper 1*, moves the song "I Will Never Love Again - Film Version" to position 1, and the line *move "You Are Still the One" Shania Twain 4*, moves the song "You Are Still the One" to position 4. Note that, unliked array indexing in C/C++, positioning in Spotify starts at 1, as opposed to 0. This can be seen in the above Spotify screenshot: the first position is position 1.
|
||||
- next, which skips the currently playing song and starts playing the song that is listed directly after it. Note that if the currently playing song is already at the bottom of the playlist, the action *next* will make the first song (i.e., the song at the very top of the playlist) as the currently playing song.
|
||||
- previous, which skips the currently playing song and goes to the song listed directly before the currently playing song. Note that if the currently playing song is already at the top of the playlist, the action *previous* will make the last song (i.e., the song at the bottom of the playlist) as the currently playing song.
|
||||
|
||||
According to this sample **actions file**, 4 songs will be added to the playlist, 1 song will be removed, 2 songs will be moved. And the currently playing song will be a different song, instead of the song "Always Remember Us This Way".
|
||||
|
||||
When playlist_tiny1.txt and actions1.txt are supplied to your program as the two input files, your program should produce the following output file:
|
||||
|
||||
```console
|
||||
"I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper
|
||||
"Perfect Duet" Ed Sheeran, Beyonce
|
||||
"Always Remember Us This Way" Lady Gaga
|
||||
"You Are Still the One" Shania Twain
|
||||
"Umbrella" Rihanna
|
||||
"We Are Young" Fun current
|
||||
"Viva La Vida" Coldplay
|
||||
```
|
||||
|
||||
## Non-existent Songs
|
||||
|
||||
If a move action or a remove action as defined in the **actions file** attempts to move or remove a song which does not exist in the playlist, your program should ignore such an action.
|
||||
|
||||
## Duplicated Songs
|
||||
|
||||
In cases where the same song appears more than once on the playlist, choose the first song (to move or remove) - i.e., search the playlist, starting from the top to the bottom, identify the first occurrence of this song, and use it (to move or remove).
|
||||
|
||||
## Instructor's Code
|
||||
|
||||
You can test (but not view) the instructor's code here: [instructor code](http://ds.cs.rpi.edu/hws/playlists/). Note that this site is hosted on RPI's network and you can visit this site only if you are on RPI's network: either on campus or using a VPN service. Also note that, it is not your job in this assignment to play musics, the instructor's C++ code here is just used as the backend to manage the playlist.
|
||||
|
||||
## Program Requirements & Submission Details
|
||||
|
||||
In this assignment, you are required to use both std::string and std::vector. You are NOT allowed to use any data structures we have not learned so far.
|
||||
|
||||
Use good coding style when you design and implement your program. Organize your program into functions: don’t put all the code in main! Be sure to read the [Homework Policies](https://www.cs.rpi.edu/academics/courses/spring25/csci1200/homework_policies.php) as you put the finishing touches on your solution. Be sure to make up new test cases to fully debug your program and don’t forget to comment your code! Complete the provided template [README.txt](./README.txt). You must do this assignment on your own, as described in the [Collaboration Policy & Academic Integrity](https://www.cs.rpi.edu/academics/courses/spring25/csci1200/academic_integrity.php) page. If you did discuss the problem or error messages, etc. with anyone, please list their names in your README.txt file. Prepare and submit your assignment as instructed on the course webpage. Please ask a TA if you need help preparing your assignment for submission.
|
||||
|
||||
**Due Date**: 01/16/2025, 10pm.
|
||||
|
||||
## Rubric
|
||||
|
||||
13 pts
|
||||
- README.txt Completed (3 pts)
|
||||
- One of name, collaborators, or hours not filled in. (-1)
|
||||
- Two or more of name, collaborators, or hours not filled in. (-2)
|
||||
- No reflection. (-1)
|
||||
- STL Vector & String (3 pts)
|
||||
- Uses data structures which have not been covered in this class. (-3)
|
||||
- Did not use STL vector (-2)
|
||||
- Did not use STL string (-2)
|
||||
- Program Structure (7 pts)
|
||||
- No credit (significantly incomplete implementation) (-7)
|
||||
- Putting almost everything in the main function. It's better to create separate functions for different tasks. (-2)
|
||||
- Improper uses or omissions of const and reference. (-1)
|
||||
- Almost total lack of helpful comments. (-4)
|
||||
- Too few comments. (-2)
|
||||
- Contains useless comments like commented-out code, terminal commands, or silly notes. (-1)
|
||||
- Overly cramped, excessive whitespace, or poor indentation. (-1)
|
||||
- Lacks error checking (num of args, invalid file names, invalid command, etc.) (-1)
|
||||
- Poor choice of variable names: non-descriptive names (e.g. 'vec', 'str', 'var'), single-letter variable names (except single loop counter), etc. (-2)
|
||||
- Uses global variables. (-1)
|
||||
- Overly long lines, in excess of 100 or so characters. It's recommended to keep all lines short and put comments on their own lines. (-1)
|
||||
{{< /details >}}
|
||||
|
||||
## Supporting Files
|
||||
|
||||
{{< link href="spotify_playlists.7z" content="spotify_playlists.7z" title="Download spotify_playlists.7z" download="spotify_playlists.7z" card=true >}}
|
||||
|
||||
## Program Design
|
||||
|
||||
Before start, we need to find out what need to do. Let's draw a flowchart to exam what are the steps.
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
A(("Start")) --> D["Read 'playlist file', 'actions file'"]
|
||||
|
||||
subgraph "Initialize"
|
||||
D --> E["Find the index of current song (if any)"]
|
||||
end
|
||||
|
||||
E --> F{"For each action in 'actions file'"}
|
||||
|
||||
subgraph "Process Actions"
|
||||
F -- next --> G["Find the index of current song (if any)"]
|
||||
G --> H["Remove 'current' from current song"]
|
||||
H --> I{"Is it the last song?"}
|
||||
I -- Yes --> J["Set index to 0"]
|
||||
I -- No --> K["Set index to index+1"]
|
||||
J --> L["Mark new current song"]
|
||||
K --> L["Mark new current song"]
|
||||
|
||||
F -- previous --> M["Find the index of current song (if any)"]
|
||||
M --> N["Remove 'current' from current song"]
|
||||
N --> O{"Is it the first song?"}
|
||||
O -- Yes --> P["Set index to last song"]
|
||||
O -- No --> Q["Set index to index-1"]
|
||||
P --> R["Mark new current song"]
|
||||
Q --> R["Mark new current song"]
|
||||
|
||||
F -- add --> S["'Build' the new song string"]
|
||||
S --> T["Append to playlist"]
|
||||
|
||||
F -- remove --> U["'Build' the song string to remove"]
|
||||
U --> V["Find the first occurrence (if any)"]
|
||||
V --> W["Remove from playlist (ignore if not found)"]
|
||||
|
||||
F -- move --> X["'Build' the song string to move"]
|
||||
X --> Y["Check 'move' destination"]
|
||||
Y --> Z["Find the first occurrence (if any)"]
|
||||
Z --> ZA["Remove from playlist (ignore if not found)"]
|
||||
ZA --> ZB["Insert at new position"]
|
||||
end
|
||||
```
|
||||
|
||||
Then, we can plan what function to use in this program.
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph "Main"
|
||||
main["main()"]
|
||||
end
|
||||
|
||||
subgraph "File IO"
|
||||
load_list("load_list()")
|
||||
get_text("get_text()")
|
||||
write_list("write_list()")
|
||||
end
|
||||
|
||||
subgraph "Helpers"
|
||||
is_all_digits("is_all_digits()")
|
||||
tokenizer("tokenizer()")
|
||||
check_in_list("check_in_list()")
|
||||
remove_in_list("remove_in_list()")
|
||||
get_current("get_current()")
|
||||
build_song("build_song()")
|
||||
end
|
||||
|
||||
%% Connections
|
||||
main --> load_list
|
||||
load_list --> get_text
|
||||
main --> write_list
|
||||
|
||||
main --> is_all_digits
|
||||
main --> tokenizer
|
||||
main --> check_in_list
|
||||
main --> remove_in_list
|
||||
main --> get_current
|
||||
main --> build_song
|
||||
|
||||
remove_in_list --> check_in_list
|
||||
```
|
||||
|
||||
## Pitfalls
|
||||
|
||||
1. It's hard to load each argument correctly. For example, song can include spaces, the singer can also have space or something else in their names. But luckily, we don't need care too much about the middle part. I mean the first argument is always the command. The rest of it is the song information we need to add / delete. I split the arguments / songs into parts by space. `<action> <song> <location>` and take the each part as needed.
|
||||
2. When I am moving / adding the song. It's possible that the song has a `current` string at the end of line (in the playlist file already). If we only check the song's name, it will not pass some test cases. For example, this is how I handle this case for `move` command.
|
||||
|
||||
```diff
|
||||
if (tokens[0] == "move") {
|
||||
if (is_all_digits(tokens.back())){
|
||||
//set target position
|
||||
int dest = std::stoi(tokens.back());
|
||||
//build song from tokens
|
||||
std::string song;
|
||||
song = build_song(tokens, 1, tokens.size() - 1);
|
||||
+ //fix song name if it has current tag
|
||||
+ if (!check_in_list(song, playlist) &&
|
||||
+ !check_in_list(song + " current", playlist)) {continue;}
|
||||
+ else if (check_in_list(song + " current", playlist)) {
|
||||
+ song += " current";
|
||||
+ }
|
||||
remove_in_list(song, playlist);
|
||||
playlist.insert(playlist.begin() + dest - 1, song);
|
||||
} else {
|
||||
std::cout << "ERROR: Missing move destination" << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
I added another check with the song + `current` in the playlist before I actually add it into the playlist.
|
||||
|
||||
## Solution
|
||||
|
||||
### nyplaylists.cpp
|
||||
|
||||
```cpp
|
||||
//An implement of CSCI-1200 HW1 Spotify Playlists
|
||||
//Date: 2025/1/16
|
||||
//Author: JamesFlare
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
std::string get_text(const std::string &fname) {
|
||||
//load a text file into a string
|
||||
std::ifstream inFile(fname);
|
||||
//check if file exists
|
||||
if (!inFile) {
|
||||
std::cout << "Error: File not found" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::string text;
|
||||
std::string line;
|
||||
while (std::getline(inFile, line)) {
|
||||
text += line;
|
||||
text += "\n";
|
||||
}
|
||||
inFile.close();
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
std::vector<std::string> load_list(const std::string &fname) {
|
||||
//load a text file into a vector of strings
|
||||
std::string text = get_text(fname);
|
||||
|
||||
std::vector<std::string> lines;
|
||||
std::size_t start = 0;
|
||||
std::size_t end = 0;
|
||||
while ((end = text.find('\n', start)) != std::string::npos) {
|
||||
lines.push_back(text.substr(start, end - start));
|
||||
start = end + 1;
|
||||
}
|
||||
if (start < text.size()) {
|
||||
lines.push_back(text.substr(start));
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
bool is_all_digits(const std::string& s) {
|
||||
//check if string is int
|
||||
for (char c : s) {
|
||||
if (!std::isdigit(static_cast<unsigned char>(c))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !s.empty();
|
||||
}
|
||||
|
||||
std::vector<std::string> tokenizer(const std::string &s) {
|
||||
//split string into tokens
|
||||
std::vector<std::string> tokens;
|
||||
std::string token;
|
||||
for (char c : s) {
|
||||
if (c == ' ') {
|
||||
tokens.push_back(token);
|
||||
token = "";
|
||||
} else {
|
||||
token += c;
|
||||
}
|
||||
}
|
||||
tokens.push_back(token);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
bool check_in_list (const std::string &s, const std::vector<std::string> &list) {
|
||||
//check if string is in list
|
||||
for (std::string item : list) {
|
||||
if (s == item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void remove_in_list (const std::string &s, std::vector<std::string> &list) {
|
||||
//remove string from list
|
||||
if (!check_in_list(s, list)) {return;}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (list[i] == s) {
|
||||
list.erase(list.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get_current (std::vector<std::string> &playlist) {
|
||||
//return the index of the string has word current at the end
|
||||
for (int i = 0; i < playlist.size(); i++) {
|
||||
if (playlist[i].find("current") != std::string::npos) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string build_song (const std::vector<std::string> &tokens, const int &start, const int &end) {
|
||||
//build string from tokens w/ start and end positions
|
||||
std::string song;
|
||||
for (int i = start; i < end; i++) {
|
||||
song += tokens[i];
|
||||
if (i != end - 1) {
|
||||
song += " ";
|
||||
}
|
||||
}
|
||||
return song;
|
||||
}
|
||||
|
||||
void write_list(const std::string &fname, const std::vector<std::string> &list) {
|
||||
//write list to file
|
||||
std::ofstream outFile(fname);
|
||||
for (std::string line : list) {
|
||||
outFile << line << std::endl;
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
//take 3 arguments
|
||||
if (argc < 3) {
|
||||
std::cout << "Error: Not enough arguments" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
//load arguments
|
||||
std::string playlist_fname = argv[1];
|
||||
std::string action_list_fname = argv[2];
|
||||
std::string output_fname = argv[3];
|
||||
//load working files
|
||||
std::vector<std::string> playlist = load_list(playlist_fname);
|
||||
std::vector<std::string> action_list = load_list(action_list_fname);
|
||||
//get current playing song id
|
||||
int current_song_id = get_current(playlist);
|
||||
//execute actions
|
||||
for (std::string command : action_list) {
|
||||
//split command into tokens
|
||||
std::vector<std::string> tokens = tokenizer(command);
|
||||
if (tokens[0] == "next") {
|
||||
current_song_id = get_current(playlist);
|
||||
//remove "current" tag
|
||||
playlist[current_song_id].erase(playlist[current_song_id].length() - 8);
|
||||
if (current_song_id == playlist.size() - 1) {
|
||||
current_song_id = 0;
|
||||
} else {
|
||||
current_song_id++;
|
||||
}
|
||||
//update current song
|
||||
playlist[current_song_id] += " current";
|
||||
}
|
||||
if (tokens[0] == "previous") {
|
||||
current_song_id = get_current(playlist);
|
||||
//remove "current" tag
|
||||
playlist[current_song_id].erase(playlist[current_song_id].length() - 8);
|
||||
if (current_song_id == 0) {
|
||||
current_song_id = playlist.size() - 1;
|
||||
} else {
|
||||
current_song_id--;
|
||||
}
|
||||
//update current song
|
||||
playlist[current_song_id] += " current";
|
||||
}
|
||||
if (tokens[0] == "add") {
|
||||
std::string song;
|
||||
song = build_song(tokens, 1, tokens.size());
|
||||
playlist.push_back(song);
|
||||
}
|
||||
if (tokens[0] == "remove") {
|
||||
std::string song;
|
||||
song = build_song(tokens, 1, tokens.size());
|
||||
remove_in_list(song, playlist);
|
||||
}
|
||||
if (tokens[0] == "move") {
|
||||
if (is_all_digits(tokens.back())){
|
||||
//set target position
|
||||
int dest = std::stoi(tokens.back());
|
||||
//build song from tokens
|
||||
std::string song;
|
||||
song = build_song(tokens, 1, tokens.size() - 1);
|
||||
//fix song name if it has current tag
|
||||
if (!check_in_list(song, playlist) &&
|
||||
!check_in_list(song + " current", playlist)) {continue;}
|
||||
else if (check_in_list(song + " current", playlist)) {
|
||||
song += " current";
|
||||
}
|
||||
remove_in_list(song, playlist);
|
||||
playlist.insert(playlist.begin() + dest - 1, song);
|
||||
} else {
|
||||
std::cout << "ERROR: Missing move destination" << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
//write back file
|
||||
write_list(output_fname, playlist);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
BIN
content/en/posts/csci-1200/hw-1/spotify_playlists.7z
Normal file
|
After Width: | Height: | Size: 64 KiB |
1297
content/en/posts/csci-1200/hw-2/index.md
Normal file
BIN
content/en/posts/csci-1200/hw-2/ride_sharing.7z
Normal file
1206
content/en/posts/csci-1200/hw-3/index.md
Normal file
BIN
content/en/posts/csci-1200/hw-3/matrix1_array.avif
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
content/en/posts/csci-1200/hw-3/matrix_class.7z
Normal file
@@ -111,7 +111,10 @@ After modifying, write the `docker-compose.yaml` file. Then start the container:
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
Remember to correctly configure a reverse proxy; this proxy must support HTTPS because all of Logto's APIs must be run in a secure environment, otherwise errors will occur[^2]. Additionally, just having HTTPS isn't enough; you also need to set the `X-Forwarded-Proto` header value to `https` to inform Logto that users are accessing it via HTTPS. I use Nginx as my reverse proxy service and provide a reference configuration below (modify according to your situation).
|
||||
> [!WARNING]
|
||||
> Don't forget to set `X-Forwarded-Proto` header in Nginx!
|
||||
|
||||
this proxy must support HTTPS because all of Logto's APIs must be run in a secure environment, otherwise errors will occur[^2]. Additionally, just having HTTPS isn't enough; you also need to set the `X-Forwarded-Proto` header value to `https` to inform Logto that users are accessing it via HTTPS. I use Nginx as my reverse proxy service and provide a reference configuration below (modify according to your situation).
|
||||
|
||||
[^2]: Discussion on errors https://github.com/logto-io/logto/issues/4279
|
||||
|
||||
|
||||
@@ -71,8 +71,8 @@ repost:
|
||||
We know that, the Ohm's Law, KCL, and KVL can be shown as these formulas:
|
||||
|
||||
$$
|
||||
V = IR \\\
|
||||
\textstyle \sum I_{in} = \sum I_{out} \\\
|
||||
V = IR \\
|
||||
\textstyle \sum I_{in} = \sum I_{out} \\
|
||||
\textstyle \sum V_{n} = 0
|
||||
$$
|
||||
|
||||
@@ -82,11 +82,11 @@ Based on $V = IR$, the total $I$ should be
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V &= IR \\\
|
||||
I &= \frac{V}{R} \\\
|
||||
I_{total} &= \frac{5}{10K + \cfrac{1}{\frac{1}{1K} + \frac{1}{1K}} + 10K} \\\
|
||||
I_{total} &= \frac{5}{10000 + 500 + 10000} \\\
|
||||
I_{total} &= 0.000243902439 \\\
|
||||
V &= IR \\
|
||||
I &= \frac{V}{R} \\
|
||||
I_{total} &= \frac{5}{10K + \cfrac{1}{\frac{1}{1K} + \frac{1}{1K}} + 10K} \\
|
||||
I_{total} &= \frac{5}{10000 + 500 + 10000} \\
|
||||
I_{total} &= 0.000243902439 \\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -94,8 +94,8 @@ And $I(R2) = I(R3)$ should be
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R2) = I(R3) &= I_{total} \times \frac{R2}{R2 + R3} \\\
|
||||
I(R2) = I(R3) &= 0.000243902439 \times \frac{1000}{1000 + 1000} \\\
|
||||
I(R2) = I(R3) &= I_{total} \times \frac{R2}{R2 + R3} \\
|
||||
I(R2) = I(R3) &= 0.000243902439 \times \frac{1000}{1000 + 1000} \\
|
||||
I(R2) = I(R3) &= 0.0001219512195
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -106,16 +106,16 @@ To find $V(R1) = V(R4)$ and $V(R2) = V(R3)$, we can use
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) = V(R4) &= V_{total} \times \frac{R1}{R1 + R2 \Vert R3 + R4} \\\
|
||||
V(R1) = V(R4) &= 5 \times \frac{10000}{10000 + 500 + 10000} \\\
|
||||
V(R1) = V(R4) &= V_{total} \times \frac{R1}{R1 + R2 \Vert R3 + R4} \\
|
||||
V(R1) = V(R4) &= 5 \times \frac{10000}{10000 + 500 + 10000} \\
|
||||
V(R1) = V(R4) &= 2.4390244
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R2) = V(R3) &= V_{total} \\\
|
||||
V(R2) = V(R3) &= (5 - 2.4390244 - 2.4390244) \\\
|
||||
V(R2) = V(R3) &= V_{total} \\
|
||||
V(R2) = V(R3) &= (5 - 2.4390244 - 2.4390244) \\
|
||||
V(R2) = V(R3) &= 0.1219512
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -187,24 +187,24 @@ and the voltage is the difference in potential. Based on that, we can calculate
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) &= V(n001) - V(n002) \\\
|
||||
V(R1) &= 5 - 2.56098 \\\
|
||||
V(R1) &= V(n001) - V(n002) \\
|
||||
V(R1) &= 5 - 2.56098 \\
|
||||
V(R1) &= \boxed{2.43902}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R2) = V(R3) &= V(n002) - V(n003) \\\
|
||||
V(R2) = V(R3) &= 2.56098 - 2.43902 \\\
|
||||
V(R2) = V(R3) &= V(n002) - V(n003) \\
|
||||
V(R2) = V(R3) &= 2.56098 - 2.43902 \\
|
||||
V(R2) = V(R3) &= \boxed{0.12196}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R4) &= V(n003) - V(\text{GND}) \\\
|
||||
V(R4) &= 2.43902 - 0 \\\
|
||||
V(R4) &= V(n003) - V(\text{GND}) \\
|
||||
V(R4) &= 2.43902 - 0 \\
|
||||
V(R4) &= \boxed{2.43902}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -240,8 +240,8 @@ Using the expectation $I(R1) = I(R2) + I(R3)$ from Analysis. We can check
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
& \quad \thickspace I(R1) + I(R2) + I(R3) \\\
|
||||
&= -0.000243902 + 0.000121951 + 0.000121951 \\\
|
||||
& \quad \thickspace I(R1) + I(R2) + I(R3) \\
|
||||
&= -0.000243902 + 0.000121951 + 0.000121951 \\
|
||||
&= \boxed{0}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -256,8 +256,8 @@ We can use the result from previous part.
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) &= 2.43902 \\\
|
||||
V(R2) = V(R3) &= 0.12196 \\\
|
||||
V(R1) &= 2.43902 \\
|
||||
V(R2) = V(R3) &= 0.12196 \\
|
||||
V(R4) &= 2.43902
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -266,10 +266,10 @@ Use the expectation $V(n001) - V(n002) - V(n003) = 0$ from Analysis. We can chec
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
& \quad \thickspace V(n001) - V(n002) - V(n003) \\\
|
||||
&= 2.43902 - 0.12196 - 0.12196 \\\
|
||||
&= 0 \\\
|
||||
\boxed{\text{True}}
|
||||
& \quad \thickspace V(n001) - V(n002) - V(n003) \\
|
||||
&= 2.43902 - 0.12196 - 0.12196 \\
|
||||
&= 0 \\
|
||||
& \boxed{\text{True}}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -292,24 +292,24 @@ to calculate $I$ based on Ohm's Law.
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V &= IR \\\
|
||||
I &= \frac{V}{R} \\\
|
||||
V &= IR \\
|
||||
I &= \frac{V}{R} \\
|
||||
I(R1) &= \frac{2.4963}{10000} = \boxed{0.00024963}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V &= IR \\\
|
||||
I &= \frac{V}{R} \\\
|
||||
V &= IR \\
|
||||
I &= \frac{V}{R} \\
|
||||
I(R2) = I(R3) &= \frac{0.1665}{1000} = \boxed{0.0001665}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V &= IR \\\
|
||||
I &= \frac{V}{R} \\\
|
||||
V &= IR \\
|
||||
I &= \frac{V}{R} \\
|
||||
I(R4) &= \frac{2.4616}{10000} = \boxed{0.00024616}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -407,16 +407,16 @@ V(n002): 2.5 voltage
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) &= V(n001) - V(n002) \\\
|
||||
V(R1) &= 5 - 2.5 \\\
|
||||
V(R1) &= V(n001) - V(n002) \\
|
||||
V(R1) &= 5 - 2.5 \\
|
||||
V(R1) &= \boxed{2.5}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R2) &= V(n002) - \text{GND} \\\
|
||||
V(R2) &= 2.5 - 0 \\\
|
||||
V(R2) &= V(n002) - \text{GND} \\
|
||||
V(R2) &= 2.5 - 0 \\
|
||||
V(R2) &= \boxed{2.5}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -469,7 +469,7 @@ Also, we know that $R_1 = R_2 = 10K$ and the voltage across the resistor can be
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
\frac{V_1}{V_2} &= \frac{R_1}{R_2} \\\
|
||||
\frac{V_1}{V_2} &= \frac{R_1}{R_2} \\
|
||||
\frac{V_1}{V_2} &= \frac{10K}{10K} = \frac{1}{1}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -480,8 +480,8 @@ Using these values, we can find out $I(R1)$ and $I(R2)$ by
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R1) = I(R2) &= \frac{V}{R} \\\
|
||||
I(R1) = I(R2) &= \frac{2.5}{10K} \\\
|
||||
I(R1) = I(R2) &= \frac{V}{R} \\
|
||||
I(R1) = I(R2) &= \frac{2.5}{10K} \\
|
||||
I(R1) = I(R2) &= \boxed{0.00025}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -539,16 +539,16 @@ Based on the Ohm's Law - the relationship we got in Analysis $I = \frac{V}{R}$.
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R1) &= \frac{V}{R} \\\
|
||||
I(R1) &= \frac{2.5539}{10K} \\\
|
||||
I(R1) &= \frac{V}{R} \\
|
||||
I(R1) &= \frac{2.5539}{10K} \\
|
||||
I(R1) &= 0.00025539
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R2) &= \frac{V}{R} \\\
|
||||
I(R2) &= \frac{2.5204}{10K} \\\
|
||||
I(R2) &= \frac{V}{R} \\
|
||||
I(R2) &= \frac{2.5204}{10K} \\
|
||||
I(R2) &= 0.00025204
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -589,8 +589,8 @@ Also, the voltage is potential difference between the component.
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) = V(R2) &= n001 - \text{GND} \\\
|
||||
V(R1) = V(R2) &= 5 - 0 \\\
|
||||
V(R1) = V(R2) &= n001 - \text{GND} \\
|
||||
V(R1) = V(R2) &= 5 - 0 \\
|
||||
V(R1) = V(R2) &= \boxed{5}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -637,8 +637,8 @@ Let's put values into equation
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I_{total} &= \frac{5}{\cfrac{1}{\frac{1}{10K} + \frac{1}{10K}}} \\\
|
||||
I_{total} &= \frac{5}{5K} \\\
|
||||
I_{total} &= \frac{5}{\cfrac{1}{\frac{1}{10K} + \frac{1}{10K}}} \\
|
||||
I_{total} &= \frac{5}{5K} \\
|
||||
I_{total} &= \boxed{0.001}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -689,8 +689,8 @@ and the voltage is the difference in potential. Based on that, we can caculate t
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) = V(R2) &= V(n001) - \text{GND} \\\
|
||||
V(R1) = V(R2) &= 5 - 0 \\\
|
||||
V(R1) = V(R2) &= V(n001) - \text{GND} \\
|
||||
V(R1) = V(R2) &= 5 - 0 \\
|
||||
V(R1) = V(R2) &= \boxed{5}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -733,9 +733,9 @@ So, we get
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I_{total} &= I(R2) + I(R1) \\\
|
||||
I_{total} &= 0.0005 + 0.0005 \\\
|
||||
I_{total} &= 0.001 \\\
|
||||
I_{total} &= I(R2) + I(R1) \\
|
||||
I_{total} &= 0.0005 + 0.0005 \\
|
||||
I_{total} &= 0.001 \\
|
||||
& 0.001 = 0.001 \\; \boxed{\text{True}}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -764,9 +764,9 @@ Then, we can find out $I(R1)$ and $I(R2)$ by
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V &= IR \\\
|
||||
I &= \frac{V}{R} \\\
|
||||
I(R1) = I(R2) &= \frac{5.0305}{10000} \\\
|
||||
V &= IR \\
|
||||
I &= \frac{V}{R} \\
|
||||
I(R1) = I(R2) &= \frac{5.0305}{10000} \\
|
||||
I(R1) = I(R2) &= \boxed{0.0005305}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -808,8 +808,8 @@ Also, the voltage is potential difference between the component.
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) = V(R2) &= n001 - \text{GND} \\\
|
||||
V(R1) = V(R2) &= 5 - 0 \\\
|
||||
V(R1) = V(R2) &= n001 - \text{GND} \\
|
||||
V(R1) = V(R2) &= 5 - 0 \\
|
||||
V(R1) = V(R2) &= \boxed{5}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -830,16 +830,16 @@ and get
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R1) &= \frac{V(R1)}{R1} \\\
|
||||
I(R1) &= \frac{5}{10K} \\\
|
||||
I(R1) &= \frac{V(R1)}{R1} \\
|
||||
I(R1) &= \frac{5}{10K} \\
|
||||
I(R1) &= \boxed{0.0005}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R2) &= \frac{V(R2)}{R2} \\\
|
||||
I(R2) &= \frac{5}{10K} \\\
|
||||
I(R2) &= \frac{V(R2)}{R2} \\
|
||||
I(R2) &= \frac{5}{10K} \\
|
||||
I(R2) &= \boxed{0.0005}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -848,10 +848,10 @@ the relationship between $I(R1)$ and $I(R2)$ can be express as
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
\frac{I(R1)}{I(R2)} &= \cfrac{\cfrac{V(R1)}{R1}}{\cfrac{V(R2)}{R2}} \\\
|
||||
\because V(R1) &= V(R2) \\\
|
||||
\therefore \frac{I(R1)}{I(R2)} &= \cfrac{\cfrac{\cancel{V(R1)}}{R1} \times \cfrac{1}{\cancel{V(R1)}}}{\cfrac{\cancel{V(R2)}}{R2} \times \cfrac{1}{\cancel{V(R2)}}} \\\
|
||||
\frac{I(R1)}{I(R2)} &= \frac{\frac{1}{R1}}{\frac{1}{R2}} \\\
|
||||
\frac{I(R1)}{I(R2)} &= \cfrac{\cfrac{V(R1)}{R1}}{\cfrac{V(R2)}{R2}} \\
|
||||
\because V(R1) &= V(R2) \\
|
||||
\therefore \frac{I(R1)}{I(R2)} &= \cfrac{\cfrac{\cancel{V(R1)}}{R1} \times \cfrac{1}{\cancel{V(R1)}}}{\cfrac{\cancel{V(R2)}}{R2} \times \cfrac{1}{\cancel{V(R2)}}} \\
|
||||
\frac{I(R1)}{I(R2)} &= \frac{\frac{1}{R1}}{\frac{1}{R2}} \\
|
||||
&\boxed{\frac{I(R1)}{I(R2)} = \frac{R2}{R1}}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -866,9 +866,9 @@ as we get the $I_{total}$ by
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I_{total} &= \frac{V_{total}}{R_{total}} \\\
|
||||
I_{total} &= \frac{5}{\cfrac{1}{\cfrac{1}{10K} + \cfrac{1}{10K}}} \\\
|
||||
I_{total} &= \frac{5}{5K} \\\
|
||||
I_{total} &= \frac{V_{total}}{R_{total}} \\
|
||||
I_{total} &= \frac{5}{\cfrac{1}{\cfrac{1}{10K} + \cfrac{1}{10K}}} \\
|
||||
I_{total} &= \frac{5}{5K} \\
|
||||
I_{total} &= 0.001
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -883,8 +883,8 @@ We can get $I(R1)$ and $I(R2)$ by
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
I(R1) = I(R2) &= I_{total} \times \frac {R1}{R1 + R2} \\\
|
||||
I(R1) = I(R2) &= 0.001 \times \frac {10K}{10K + 10K} \\\
|
||||
I(R1) = I(R2) &= I_{total} \times \frac {R1}{R1 + R2} \\
|
||||
I(R1) = I(R2) &= 0.001 \times \frac {10K}{10K + 10K} \\
|
||||
I(R1) = I(R2) &= \boxed{0.0005}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -893,12 +893,12 @@ At this point, our logic is consistent, which
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
& \because R1 = R2 = 10K \\\
|
||||
& \because I(R1) = I(R2) = 0.0005 \\\
|
||||
& \because V(R1) = V(R2) = 5 \\\
|
||||
& \because I_{total} = I(R1) + I(R2) = 0.001 \\\
|
||||
& \because \frac{I(R1)}{I(R2)} = \frac{R2}{R1} \\\
|
||||
& \therefore I(R1) = I(R2) = I_{total} \times \frac {R1}{R1 + R2} \\\
|
||||
& \because R1 = R2 = 10K \\
|
||||
& \because I(R1) = I(R2) = 0.0005 \\
|
||||
& \because V(R1) = V(R2) = 5 \\
|
||||
& \because I_{total} = I(R1) + I(R2) = 0.001 \\
|
||||
& \because \frac{I(R1)}{I(R2)} = \frac{R2}{R1} \\
|
||||
& \therefore I(R1) = I(R2) = I_{total} \times \frac {R1}{R1 + R2} \\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -958,8 +958,8 @@ and the voltage is the difference in potential. Based on that, we can calculate
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V(R1) = V(R2) &= V(n001) - \text{GND} \\\
|
||||
V(R1) = V(R2) &= 5 - 0 \\\
|
||||
V(R1) = V(R2) &= V(n001) - \text{GND} \\
|
||||
V(R1) = V(R2) &= 5 - 0 \\
|
||||
V(R1) = V(R2) &= \boxed{5}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -999,9 +999,9 @@ Then, we can find out $I(R1)$ and $I(R2)$ by
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V &= IR \\\
|
||||
I &= \frac{V}{R} \\\
|
||||
I(R1) = I(R2) &= \frac{5.0305}{10000} \\\
|
||||
V &= IR \\
|
||||
I &= \frac{V}{R} \\
|
||||
I(R1) = I(R2) &= \frac{5.0305}{10000} \\
|
||||
I(R1) = I(R2) &= \boxed{0.0005305}
|
||||
\end{align*}
|
||||
$$
|
||||
@@ -1038,7 +1038,7 @@ We are going to use NTC 100K as our thermistor, and we will compare the reading
|
||||
NTC thermistor uses Beta formula to calculate the resistance under a specific temperature. The formula is like
|
||||
|
||||
$$
|
||||
\frac{1}{T_1} = \frac{1}{T_0} + \frac{1}{\beta} \ln\left(\frac{R_1}{R_0}\right) \\\
|
||||
\frac{1}{T_1} = \frac{1}{T_0} + \frac{1}{\beta} \ln\left(\frac{R_1}{R_0}\right) \\
|
||||
$$
|
||||
|
||||
We can move $R_1$ to the left side to get
|
||||
@@ -1054,7 +1054,7 @@ Since we want to find out the resistance of this thermistor under a specific tem
|
||||
The thermistor we are using is NTC 100K. Which means it has $100k \Omega$ at the reference temperature $25 \degree C$
|
||||
|
||||
$$
|
||||
T_0 = 298.15K \\\
|
||||
T_0 = 298.15K \\
|
||||
R_0 = 100k \Omega
|
||||
$$
|
||||
|
||||
@@ -1107,7 +1107,7 @@ We used the math function in Scope with
|
||||
to get the temperature in $\degree C$. This is from
|
||||
|
||||
$$
|
||||
\frac{1}{T_1} = \frac{1}{T_0} + \frac{1}{\beta} \ln\left(\frac{R_1}{R_0}\right) \\\
|
||||
\frac{1}{T_1} = \frac{1}{T_0} + \frac{1}{\beta} \ln\left(\frac{R_1}{R_0}\right) \\
|
||||
$$
|
||||
|
||||
which $T_1$ is the temperature reading we want.
|
||||
|
||||
BIN
content/en/posts/ecse-1010/lab02/Lab02.pdf
Normal file
BIN
content/en/posts/ecse-1010/lab02/P1-1-a.avif
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-1-b-2.avif
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-1-b.avif
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-1-c-2.avif
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-1-c.avif
Normal file
|
After Width: | Height: | Size: 122 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-2-a.avif
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-2-b.avif
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-3-a.avif
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-a-2.avif
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-a.avif
Normal file
|
After Width: | Height: | Size: 368 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-b.avif
Normal file
|
After Width: | Height: | Size: 287 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-c-2.avif
Normal file
|
After Width: | Height: | Size: 400 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-c.avif
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-d-2.avif
Normal file
|
After Width: | Height: | Size: 478 KiB |
BIN
content/en/posts/ecse-1010/lab02/P1-4-d.avif
Normal file
|
After Width: | Height: | Size: 532 KiB |
270
content/en/posts/ecse-1010/lab02/P1-4-d.svg
Normal file
|
After Width: | Height: | Size: 114 KiB |
272
content/en/posts/ecse-1010/lab02/P1-4-e.svg
Normal file
|
After Width: | Height: | Size: 134 KiB |
BIN
content/en/posts/ecse-1010/lab02/P2-2-a.avif
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
220
content/en/posts/ecse-1010/lab02/P2-4-c-2.svg
Normal file
|
After Width: | Height: | Size: 330 KiB |
BIN
content/en/posts/ecse-1010/lab02/P3-1-a.avif
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
content/en/posts/ecse-1010/lab02/P3-3-a.avif
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
content/en/posts/ecse-1010/lab02/P3-4-a.avif
Normal file
|
After Width: | Height: | Size: 542 KiB |
BIN
content/en/posts/ecse-1010/lab02/P3-4-b-2.avif
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
content/en/posts/ecse-1010/lab02/P3-4-b-3.avif
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
content/en/posts/ecse-1010/lab02/P3-4-b.avif
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
content/en/posts/ecse-1010/lab02/P4-1-a.avif
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
content/en/posts/ecse-1010/lab02/P4-2-a.avif
Normal file
|
After Width: | Height: | Size: 188 KiB |
BIN
content/en/posts/ecse-1010/lab02/P4-3-a.avif
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
content/en/posts/ecse-1010/lab02/P4-4-a.avif
Normal file
|
After Width: | Height: | Size: 240 KiB |
BIN
content/en/posts/ecse-1010/lab02/P4-4-b-1.avif
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
content/en/posts/ecse-1010/lab02/P4-4-b-2.avif
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
content/en/posts/ecse-1010/lab02/P5-2-a.avif
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
content/en/posts/ecse-1010/lab02/P5-3-a.avif
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
content/en/posts/ecse-1010/lab02/P5-3-b.avif
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
content/en/posts/ecse-1010/lab02/P5-4-a-1.avif
Normal file
|
After Width: | Height: | Size: 227 KiB |
BIN
content/en/posts/ecse-1010/lab02/P5-4-a.avif
Normal file
|
After Width: | Height: | Size: 230 KiB |
BIN
content/en/posts/ecse-1010/lab02/P6-1-a.avif
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
content/en/posts/ecse-1010/lab02/P6-3-a.avif
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
content/en/posts/ecse-1010/lab02/P6-3-b.avif
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
content/en/posts/ecse-1010/lab02/P6-4-a-b.avif
Normal file
|
After Width: | Height: | Size: 279 KiB |
BIN
content/en/posts/ecse-1010/lab02/P6-4-a.avif
Normal file
|
After Width: | Height: | Size: 260 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-1-a.avif
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-2-a.avif
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-3-a.avif
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-4-a-b.avif
Normal file
|
After Width: | Height: | Size: 1009 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-4-a.avif
Normal file
|
After Width: | Height: | Size: 978 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-4-b.avif
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
content/en/posts/ecse-1010/lab02/P8-4-c.avif
Normal file
|
After Width: | Height: | Size: 39 KiB |
820
content/en/posts/ecse-1010/lab02/index.md
Normal file
@@ -0,0 +1,820 @@
|
||||
---
|
||||
title: ECSE 1010 Proof of Concepts - Omega Lab02
|
||||
subtitle:
|
||||
date: 2024-11-28T12:57:51-05:00
|
||||
lastmod: 2024-11-28T12:57:51-05:00
|
||||
slug: ecse-1010-poc-lab02
|
||||
draft: false
|
||||
author:
|
||||
name: James
|
||||
link: https/www.jamesflare.com
|
||||
email:
|
||||
avatar: /site-logo.avif
|
||||
description: The experiments aim to validate Ohm's Law, non-linear IV curves for LEDs, differential resistance in diode IV curves, nodal voltage solving with Kirchhoff’s Laws, the function of an op amp comparator, mathematical op amp functionality, and two-channel audio mixer transfer functions.
|
||||
keywords: ["Electrical Engineering","Ohm's Law","IV curve","Nodal Analysis","Op-Amp"]
|
||||
license:
|
||||
comment: true
|
||||
weight: 0
|
||||
tags:
|
||||
- ECSE 1010
|
||||
- Lab
|
||||
- Electrical Engineering
|
||||
- RPI
|
||||
categories:
|
||||
- Electrical Engineering
|
||||
collections:
|
||||
- ECSE 1010
|
||||
hiddenFromHomePage: false
|
||||
hiddenFromSearch: false
|
||||
hiddenFromRss: false
|
||||
hiddenFromRelated: false
|
||||
summary: The experiments aim to validate Ohm's Law, non-linear IV curves for LEDs, differential resistance in diode IV curves, nodal voltage solving with Kirchhoff’s Laws, the function of an op amp comparator, mathematical op amp functionality, and two-channel audio mixer transfer functions.
|
||||
resources:
|
||||
- name: featured-image
|
||||
src: featured-image.avif
|
||||
- name: featured-image-preview
|
||||
src: featured-image-preview.avif
|
||||
toc: true
|
||||
math: true
|
||||
lightgallery: true
|
||||
password:
|
||||
message:
|
||||
repost:
|
||||
enable: false
|
||||
url:
|
||||
|
||||
# See details front matter: https/fixit.lruihao.cn/documentation/content-management/introduction/#front-matter
|
||||
---
|
||||
|
||||
<!--more-->
|
||||
|
||||
## 0. Lab Document
|
||||
|
||||
<div style="width: 100%; max-width: 600px; margin: 0 auto; display: block;">
|
||||
<embed src="Lab02.pdf" type="application/pdf" width="100%" height="500px">
|
||||
</div>
|
||||
|
||||
## 1. Prove That the Slope of an $IV$ Curve Corresponds with Ohm’s Law for Two Different Resistor Values
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P1-1-a.avif" caption="P1-1-a" width=600px >}}
|
||||
|
||||
Let's pick two resistor. The first one is
|
||||
|
||||
{{< figure src="P1-1-b.avif" caption="P1-1-b" width=600px >}}
|
||||
|
||||
4-Band Color Code: Orange, Orange, Brown, Gold
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
33 \times (1\times10^1) = 330 \Omega \pm 5\%
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
have a check
|
||||
|
||||
{{< image src="P1-1-b-2.avif" caption="P1-1-b-2" width=600px >}}
|
||||
|
||||
The second one is
|
||||
|
||||
{{< image src="P1-1-c.avif" caption="P1-1-c" width=600px >}}
|
||||
|
||||
4-Band Color Code: Brown, Brown, Red, Gold
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
11 \times (1\times10^2) = 1100 \Omega \pm 5\%
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
have a check
|
||||
|
||||
{{< image src="P1-1-c-2.avif" caption="P1-1-c-2" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
We know that $IV$ curve means $I$ on the y-axis and $V$ on the x-axis of the plot. Then, it must be a linear function, because both $IV$ don't have powers.
|
||||
|
||||
Using the idea of linear function, we know the slope is $\frac{\Delta X}{\Delta Y}$. Back to our case, it becomes $\frac{\Delta V}{\Delta I}$. Also, we knows the Ohm's Law, which $\frac{V}{I} = R$. So, the slope is very likely to be the resistance $R$.
|
||||
|
||||
If we take $R_1 = 10 \Omega$, $R_2 = 100 \Omega$ (As the simulation set). We should got.
|
||||
|
||||
{{< image src="P1-2-a.avif" caption="P1-2-a" width=600px >}}
|
||||
|
||||
If we plot them together, we got
|
||||
|
||||
{{< image src="P1-2-b.avif" caption="P1-2-b" width=600px >}}
|
||||
|
||||
Here is the data table
|
||||
|
||||
|$I$ | $V=IR_1$ | $V=IR_2$ |
|
||||
|:----|----------:|----------:|
|
||||
| 0 | 0 | 0 |
|
||||
| 0.2 | 2 | 20 |
|
||||
| 0.4 | 4 | 40 |
|
||||
| 0.6 | 6 | 60 |
|
||||
| 0.8 | 8 | 80 |
|
||||
| 1 | 10 | 100 |
|
||||
|
||||
### Simulation
|
||||
|
||||
{{< image src="P1-3-a.avif" caption="P1-3-a" width=600px >}}
|
||||
|
||||
### Measurement
|
||||
|
||||
First we built a circuit like this
|
||||
|
||||
{{< image src="P1-4-a.avif" caption="P1-4-a" width=600px >}}
|
||||
|
||||
this is based on the diagram from the lab document
|
||||
|
||||
{{< image src="P1-4-a-2.avif" caption="P1-4-a-2" width=250px >}}
|
||||
|
||||
We only changed the $R1, R2$ values. Also, it's hard to plug multimeter on the breadboard. So, we intersect the $V+$ circuit at the front
|
||||
|
||||
{{< image src="P1-4-b.avif" caption="P1-4-b" width=600px >}}
|
||||
|
||||
This method is not ideal, but works.
|
||||
|
||||
***
|
||||
|
||||
Let's begin
|
||||
|
||||
For $V+ = 0.5V$, we got
|
||||
|
||||
{{< image src="P1-4-c.avif" caption="P1-4-c" width=600px >}}
|
||||
|
||||
{{< image src="P1-4-c-2.avif" caption="P1-4-c-2" width=600px >}}
|
||||
|
||||
To save some space and work, we just will not show each result. But here is the data
|
||||
|
||||
|$V+$|$V(R1)$|$V(R1)$|$I$|
|
||||
|:---|:------|:------|:--|
|
||||
|$0V$|$0V$|$0V$|$0mA$|
|
||||
|$0.5V$|$0.142V$|$0.396V$|$0.3mA$|
|
||||
|$1V$|$0.238V$|$0.724V$|$0.6mA$|
|
||||
|$1.5V$|$0.358V$|$1.126V$|$1.0mA$|
|
||||
|$2V$|$0.463V$|$1.492V$|$1.3mA$|
|
||||
|$2.5V$|$0.572V$|$1.831V$|$1.6mA$|
|
||||
|$3V$|$0.632V$|$1.994V$|$1.9mA$|
|
||||
|
||||
With this MATLAB code,
|
||||
|
||||
```matlab
|
||||
% Step 1: Enter the data
|
||||
V_plus = [0, 0.5, 1, 1.5, 2, 2.5, 3]; % V+ values
|
||||
V_R1 = [0, 0.142, 0.238, 0.358, 0.463, 0.572, 0.632]; % V(R1) values
|
||||
V_R2 = [0, 0.396, 0.724, 1.126, 1.492, 1.831, 1.994]; % V(R2) values
|
||||
I = [0, 0.3, 0.6, 1.0, 1.3, 1.6, 1.9] * 1e-3; % I values in A (converted from mA)
|
||||
|
||||
% Step 2: Plot the data
|
||||
figure;
|
||||
|
||||
% Plot for Resistor R1
|
||||
subplot(2, 1, 1);
|
||||
plot(V_R1, I, '-o');
|
||||
xlabel('Voltage V(R1) (V)');
|
||||
ylabel('Current I (A)');
|
||||
title('Resistor R1: Current vs Voltage');
|
||||
grid on;
|
||||
|
||||
% Plot for Resistor R2
|
||||
subplot(2, 1, 2);
|
||||
plot(V_R2, I, '-o');
|
||||
xlabel('Voltage V(R2) (V)');
|
||||
ylabel('Current I (A)');
|
||||
title('Resistor R2: Current vs Voltage');
|
||||
grid on;
|
||||
```
|
||||
|
||||
we got the plot of $R1$ and $R2$
|
||||
|
||||
{{< image src="P1-4-d.svg" caption="P1-4-d" width=600px >}}
|
||||
|
||||
Now, let's create a fit line for both. It's needed to find out the slope ($R=V/I$). To do that, we changed the code a bit into
|
||||
|
||||
```matlab
|
||||
% Step 1: Enter the data
|
||||
V_plus = [0, 0.5, 1, 1.5, 2, 2.5, 3]; % V+ values
|
||||
V_R1 = [0, 0.142, 0.238, 0.358, 0.463, 0.572, 0.632]; % V(R1) values
|
||||
V_R2 = [0, 0.396, 0.724, 1.126, 1.492, 1.831, 1.994]; % V(R2) values
|
||||
I = [0, 0.3, 0.6, 1.0, 1.3, 1.6, 1.9] * 1e-3; % I values in A (converted from mA)
|
||||
|
||||
% Step 2: Fit linear regression curves
|
||||
% Fit for Resistor R1
|
||||
p_R1 = polyfit(I, V_R1, 1);
|
||||
slope_R1 = p_R1(1);
|
||||
R_R1 = slope_R1; % Resistance of R1
|
||||
|
||||
% Fit for Resistor R2
|
||||
p_R2 = polyfit(I, V_R2, 1);
|
||||
slope_R2 = p_R2(1);
|
||||
R_R2 = slope_R2; % Resistance of R2
|
||||
|
||||
% Step 3: Display the resistances
|
||||
fprintf('Resistance of R1: %.3f ohms\n', R_R1);
|
||||
fprintf('Resistance of R2: %.3f ohms\n', R_R2);
|
||||
|
||||
% Step 4: Plot the data and fitted curves
|
||||
figure;
|
||||
|
||||
% Plot for Resistor R1
|
||||
subplot(2, 1, 1);
|
||||
plot(V_R1, I, 'o');
|
||||
hold on;
|
||||
plot(polyval(p_R1, I), I, '-');
|
||||
xlabel('Voltage V(R1) (V)');
|
||||
ylabel('Current I (A)');
|
||||
title('Resistor R1: Current vs Voltage with Linear Fit');
|
||||
legend('Data', 'Linear Fit');
|
||||
grid on;
|
||||
|
||||
% Plot for Resistor R2
|
||||
subplot(2, 1, 2);
|
||||
plot(V_R2, I, 'o');
|
||||
hold on;
|
||||
plot(polyval(p_R2, I), I, '-');
|
||||
xlabel('Voltage V(R2) (V)');
|
||||
ylabel('Current I (A)');
|
||||
title('Resistor R2: Current vs Voltage with Linear Fit');
|
||||
legend('Data', 'Linear Fit');
|
||||
grid on;
|
||||
```
|
||||
|
||||
we got a result of
|
||||
|
||||
```text
|
||||
Resistance of R1: 331.144 ohms
|
||||
Resistance of R2: 1069.374 ohms
|
||||
```
|
||||
|
||||
and the plots
|
||||
|
||||
{{< image src="P1-4-e.svg" caption="P1-4-e" width=600px >}}
|
||||
|
||||
Check this result from multimeter's reading of resistance
|
||||
|
||||
{{< image src="P1-4-d.avif" caption="P1-4-d" width=600px >}}
|
||||
|
||||
{{< image src="P1-4-d-2.avif" caption="P1-4-d-2" width=600px >}}
|
||||
|
||||
Great! The actual reading is very close to the resistances we determined from your IV measurement data and the linear regression. The average $\%$ error is less than $1\%$
|
||||
|
||||
### Discussion
|
||||
|
||||
We did a lot of discussion in each session instead of in one. This is just to make the document more logical and follows the flow. So, we will only summarize and add something not appear above.
|
||||
|
||||
First, we used LTSpecie to determine $IV$ curve of two resistor $R_1 = 10\Omega$ and $R_2 = 100\Omega$. (This is just for prove our Analysis, so it doesn't match the $R_1 = 330\Omega$ and $R_2 = 1100\Omega$ we used later). And it matches our Analysis. Both the plot created by Excel and the values.
|
||||
|
||||
Then, we built a series circuit, and we know they have the same current across all components. And, the $R$ is only related to $IV$. As long as we got some reading pairs, we can plot the curve. The result matches our expectation with less than $1\%$ error. Consider our multimeter can only measure down to $0.1 mV$. This accuracy is amazing!
|
||||
|
||||
Thus, we proved That the Slope of an $IV$ Curve Corresponds with Ohm’s Law for Two Different Resistor Values.
|
||||
|
||||
## 2. Prove the non linear $IV$ curve for a light emitting diode
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P3-1-a.avif" caption="P3-1-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
To plot a $IV$ curve of a diode. We need to find out a few important data.
|
||||
|
||||
- Forward Voltage ($V_F$)
|
||||
- Reverse Breakdown Voltage ($V_{BR}$)
|
||||
- Reverse Leakage Current ($I_S$)
|
||||
|
||||
As the datasheet of [QED123](https/www.onsemi.com/pdf/datasheet/qed123-d.pdf) said
|
||||
|
||||
- $V_F = 1.7V$
|
||||
- $I_F = 100 mA$
|
||||
- $V_{BR} = 5V$
|
||||
- $I_S = 10 \mu A$
|
||||
|
||||
We just plot them into a standard diode $IV$ characteristic diagram and get
|
||||
|
||||
{{< image src="P2-2-a.avif" caption="P2-2-a" width=600px >}}
|
||||
|
||||
### Simulation
|
||||
|
||||
{{< image src="P3-3-a.avif" caption="P2-3-a" width=600px >}}
|
||||
|
||||
The turn on voltage of 1N914 is about $0.7V$
|
||||
|
||||
### Measurement
|
||||
|
||||
{{< image src="P3-4-a.avif" caption="P3-4-a" width=600px >}}
|
||||
|
||||
We create a trig wave like
|
||||
|
||||
{{< image src="P3-4-b.avif" caption="P3-4-b" width=600px >}}
|
||||
|
||||
with amplitude to 5V (10 volts peak to peak), frequency to 200 Hz, and phase to 90 degrees.
|
||||
|
||||
Then, we use channel 1 to find out the current using the math function in scope
|
||||
|
||||
```js
|
||||
C1/330*1000
|
||||
```
|
||||
|
||||
{{< image src="P3-4-b-2.avif" caption="P3-4-b-2" width=600px >}}
|
||||
|
||||
and the $IV$ Curve
|
||||
|
||||
{{< image src="P3-4-b-3.avif" caption="P3-4-b-3" width=600px >}}
|
||||
|
||||
with this MATLAB Code,
|
||||
|
||||
```matlab
|
||||
% Step 1: Import the CSV file
|
||||
data = readmatrix('P2-4-c.csv');
|
||||
|
||||
% Step 2: Extract the columns
|
||||
voltage = data(:, 2); % Second column is voltage (V)
|
||||
current = data(:, 1); % Third column is current (I)
|
||||
|
||||
|
||||
% Step 3: Plot the I-V curve
|
||||
figure;
|
||||
plot(currentvoltage, current, 'k-', 'LineWidth', 1.5);
|
||||
xlabel('Voltage (V)');
|
||||
ylabel('Current (I)');
|
||||
title('I-V Curve');
|
||||
grid on;
|
||||
```
|
||||
|
||||
we got
|
||||
|
||||
{{< image src="P2-4-c-2.svg" caption="P2-4-c-2" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
Our experimental matches the datasheet. Consider the datasheet said
|
||||
|
||||
- $V_F = 1.7V$
|
||||
- $I_F = 100 mA$
|
||||
|
||||
and we got $1.7V$ on $10 mA$ this matches the datasheet curve.
|
||||
|
||||
## 3. Show / demonstrate that the differential resistance changes in different regions in the diode $IV$ curve
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P3-1-a.avif" caption="P3-1-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
To plot a $IV$ curve of a diode. We need to find out a few important data.
|
||||
|
||||
- Forward Voltage ($V_F$)
|
||||
- Reverse Breakdown Voltage ($V_{BR}$)
|
||||
- Reverse Leakage Current ($I_S$)
|
||||
|
||||
As the datasheet of [QED123](https/www.onsemi.com/pdf/datasheet/qed123-d.pdf) said
|
||||
|
||||
- $V_F = 1.7V$
|
||||
- $I_F = 100 mA$
|
||||
- $V_{BR} = 5V$
|
||||
- $I_S = 10 \mu A$
|
||||
|
||||
We just plot them into a standard diode $IV$ characteristic diagram and get
|
||||
|
||||
{{< image src="P2-2-a.avif" caption="P2-2-a" width=600px >}}
|
||||
|
||||
### Simulation
|
||||
|
||||
{{< image src="P3-3-a.avif" caption="P3-3-a" width=600px >}}
|
||||
|
||||
The turn on voltage of 1N914 is about $0.7V$
|
||||
|
||||
### Measurement
|
||||
|
||||
{{< image src="P3-4-a.avif" caption="P3-4-a" width=600px >}}
|
||||
|
||||
We create a trig wave like
|
||||
|
||||
{{< image src="P3-4-b.avif" caption="P3-4-b" width=600px >}}
|
||||
|
||||
with amplitude to 5V (10 volts peak to peak), frequency to 200 Hz, and phase to 90 degrees.
|
||||
|
||||
Then, we use channel 1 to find out the current using the math function in scope
|
||||
|
||||
```js
|
||||
C1/330*1000
|
||||
```
|
||||
|
||||
{{< image src="P3-4-b-2.avif" caption="P3-4-b-2" width=600px >}}
|
||||
|
||||
and the $IV$ Curve
|
||||
|
||||
{{< image src="P3-4-b-3.avif" caption="P3-4-b-3" width=600px >}}
|
||||
|
||||
with this MATLAB Code,
|
||||
|
||||
```matlab
|
||||
% Step 1: Import the CSV file
|
||||
data = readmatrix('P2-4-c.csv');
|
||||
|
||||
% Step 2: Extract the columns
|
||||
voltage = data(:, 2); % Second column is voltage (V)
|
||||
current = data(:, 1); % Third column is current (I)
|
||||
|
||||
|
||||
% Step 3: Plot the I-V curve
|
||||
figure;
|
||||
plot(voltage, current, 'k-', 'LineWidth', 1.5);
|
||||
xlabel('Voltage (V)');
|
||||
ylabel('Current (I)');
|
||||
title('I-V Curve');
|
||||
grid on;
|
||||
```
|
||||
|
||||
we got
|
||||
|
||||
{{< image src="P2-4-c-2.svg" caption="P2-4-c-2" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
To find out at least 2 locations on the curve to show that the differential resistance changes along the I-V characteristic. We modified the code a bit to let it find out 2 random point on the plot and its slope.
|
||||
|
||||
```matlab
|
||||
% Step 1: Import the CSV file
|
||||
data = readmatrix('P2-4-c.csv');
|
||||
|
||||
% Step 2: Extract the columns
|
||||
voltage = data(:, 2); % Second column is voltage (V)
|
||||
current = data(:, 1); % Third column is current (I)
|
||||
|
||||
% Step 3: Select two random points
|
||||
num_points = length(current);
|
||||
random_indices = randperm(num_points, 2); % Generate 2 unique random indices
|
||||
|
||||
% Step 4: Extract the voltage and current values for the selected points
|
||||
V1 = voltage(random_indices(1));
|
||||
V2 = voltage(random_indices(2));
|
||||
I1 = current(random_indices(1));
|
||||
I2 = current(random_indices(2));
|
||||
|
||||
% Step 5: Calculate the slopes
|
||||
slope1 = (V2 - V1) / (I2 - I1);
|
||||
slope2 = (V1 - V2) / (I1 - I2); % This is the same as slope1 but calculated in reverse
|
||||
|
||||
% Step 6: Print the slopes
|
||||
fprintf('The slope between the randomly selected points (I1 = %.4f, V1 = %.4f) and (I2 = %.4f, V2 = %.4f) is: %.4f\n', I1, V1, I2, V2, slope1);
|
||||
fprintf('The slope between the randomly selected points (I2 = %.4f, V2 = %.4f) and (I1 = %.4f, V1 = %.4f) is: %.4f\n', I2, V2, I1, V1, slope2);
|
||||
```
|
||||
|
||||
We got
|
||||
|
||||
> The slope between the randomly selected points (I1 = 0.0097, V1 = 0.2959) and (I2 = 0.0036, V2 = -2.6254) is: 479.8789
|
||||
>
|
||||
>The slope between the randomly selected points (I2 = 7.9784, V2 = 1.2568) and (I1 = 2.8170, V1 = 1.1975) is: 0.0115
|
||||
|
||||
We can see they are very different.
|
||||
|
||||
## 4. Prove That Nodal Analysis Solves Unknown Nodal Voltages in a Circuit
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P4-1-a.avif" caption="P4-1-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
{{< image src="P4-2-a.avif" caption="P4-2-a" width=600px >}}
|
||||
|
||||
To make our life easier, I rewrite some equation in $\LaTeX$.
|
||||
|
||||
Current through a resistor:
|
||||
|
||||
$$
|
||||
I_R = \frac{V_A - V_B}{R}
|
||||
$$
|
||||
|
||||
Kirchhoff's Current Law (KCL) at node B:
|
||||
|
||||
$$
|
||||
I_{R_1} + I_{R_2} + I_{R_3} = 0
|
||||
$$
|
||||
|
||||
KCL at node C:
|
||||
|
||||
$$
|
||||
I_{R_3} + I_{R_4} = 0
|
||||
$$
|
||||
|
||||
Expressing currents in terms of voltages. From the first equation:
|
||||
|
||||
$$
|
||||
\frac{V_B - V_A}{R_1} + \frac{V_B}{R_2} + \frac{V_B - V_C}{R_3} = 0
|
||||
$$
|
||||
|
||||
From the second equation:
|
||||
|
||||
$$
|
||||
\frac{V_C - V_B}{R_3} + \frac{V_C - V_D}{R_4} = 0
|
||||
$$
|
||||
|
||||
Substituting known values. Given $V_A = 5$ and $V_D = 0$, the equations become:
|
||||
|
||||
$$
|
||||
2.5V_B - V_C = 5 \\
|
||||
2V_C - V_B = 0
|
||||
$$
|
||||
|
||||
Matrix form: $\begin{bmatrix} 2.5 & -1 \\ -1 & 2 \end{bmatrix}$ $\begin{bmatrix} V_B \\ V_C \end{bmatrix} =$ $\begin{bmatrix} 5 \\ 0 \end{bmatrix}$
|
||||
|
||||
Solve them "by hand"
|
||||
|
||||
```matlab
|
||||
% Define the matrix A and the vector b
|
||||
A = [2.5, -1; -1, 2];
|
||||
b = [5; 0];
|
||||
|
||||
% Solve the system of linear equations A * x = b
|
||||
x = A \ b;
|
||||
|
||||
% Display the solution
|
||||
disp('The solution is:');
|
||||
disp(x);
|
||||
```
|
||||
|
||||
we got
|
||||
|
||||
```text
|
||||
The solution is:
|
||||
2.5000
|
||||
1.2500
|
||||
```
|
||||
|
||||
Thus, $\begin{bmatrix} V_B \\ V_C \end{bmatrix} =$ $\begin{bmatrix}2.5 \\ 1.25 \end{bmatrix}$
|
||||
|
||||
### Simulation
|
||||
|
||||
{{< image src="P4-3-a.avif" caption="P4-3-a" width=600px >}}
|
||||
|
||||
### Measurement
|
||||
|
||||
{{< image src="P4-4-a.avif" caption="P4-4-a" width=600px >}}
|
||||
|
||||
For $V_C$, we got
|
||||
|
||||
{{< image src="P4-4-b-1.avif" caption="P4-4-b-1" width=600px >}}
|
||||
|
||||
For $V_B$, we got
|
||||
|
||||
{{< image src="P4-4-b-2.avif" caption="P4-4-b-2" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
|Node|Analysis|Simulation|Experimental|diff|%diff|
|
||||
|:-:|:-:|:-:|:-:|:-:|:-|
|
||||
|$V_B$|$2.50V$|$2.50V$|$2.45V$|$5mV$|$2\%$|
|
||||
|$V_C$|$1.25V$|$1.25V$|$1.22V$|$3mV$|$2.4\%$|
|
||||
|
||||
Our Analysis matches the Simulation. The Experimental data has less than $2.5\%$ error than expect, which is very less. Thus, we proved That Nodal Analysis Solves Unknown Nodal Voltages in a Circuit.
|
||||
|
||||
## 5. Prove / demonstrate your approach to designing a circuit using nodal analysis
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P5-3-a.avif" caption="P5-3-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
{{< image src="P5-2-a.avif" caption="P5-2-a" width=600px >}}
|
||||
|
||||
To make our life easier, I rewrite some equation in $\LaTeX$.
|
||||
|
||||
Given values:
|
||||
|
||||
- $V_A = 3 \, \text{V}$
|
||||
- $V_C = 0 \, \text{V}$
|
||||
- $V_B$ is unknown.
|
||||
|
||||
Using Kirchhoff's Current Law (KCL) at node B:
|
||||
|
||||
$$
|
||||
\frac{V_B - V_A}{R_1} + \frac{V_B - V_C}{R_2} + \frac{V_B - V_C}{R_3} = 0
|
||||
$$
|
||||
|
||||
Substituting the given values and resistances:
|
||||
|
||||
$$
|
||||
\frac{V_B - 3}{1} + \frac{V_B - 0}{4} + \frac{V_B - 0}{4} = 0
|
||||
$$
|
||||
|
||||
Simplifying the equation:
|
||||
|
||||
$$
|
||||
(V_B - 3) + \frac{V_B}{4} + \frac{V_B}{4} = 0
|
||||
$$
|
||||
|
||||
Combine terms:
|
||||
|
||||
$$
|
||||
V_B - 3 + \frac{V_B}{2} = 0
|
||||
$$
|
||||
|
||||
Multiply through by 2 to clear the fraction:
|
||||
|
||||
$$
|
||||
2V_B - 6 + V_B = 0
|
||||
$$
|
||||
|
||||
Combine terms:
|
||||
|
||||
$$
|
||||
3V_B = 6
|
||||
$$
|
||||
|
||||
Solve for $V_B$:
|
||||
|
||||
$$
|
||||
V_B = 2
|
||||
$$
|
||||
|
||||
### Simulation
|
||||
|
||||
{{< image src="P5-3-a.avif" caption="P5-3-a" width=600px >}}
|
||||
|
||||
### Measurement
|
||||
|
||||
{{< image src="P5-4-a-1.avif" caption="P5-4-a-1" width=600px >}}
|
||||
|
||||
For $V_B$, we got
|
||||
|
||||
{{< image src="P5-4-a.avif" caption="P5-4-a" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
|Node|Analysis|Simulation|Experimental|diff|%diff|
|
||||
|:-:|:-:|:-:|:-:|:-:|:-|
|
||||
|$V_B$|$2V$|$2V$|$1.979V$|$21mV$|$1.1\%$|
|
||||
|
||||
Our Analysis matches the Simulation. The Experimental data has less than $1.2\%$ error than expect, which is very less. Thus, we proved That Nodal Analysis Solves Unknown Nodal Voltages in a Circuit.
|
||||
|
||||
## 6. Prove the function of an op amp comparator
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P6-1-a.avif" caption="P6-1-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
A non-inverted comparator has a transfer function of
|
||||
|
||||
$$
|
||||
\begin{equation*}
|
||||
V_{out}=\begin{cases}
|
||||
\text{if} \; V_{in} < V_{ref}, V_{out} = V_s - \\
|
||||
\text{if} \; V_{in} > V_{ref}, V_{out} = V_s + \\
|
||||
\end{cases}
|
||||
\end{equation*}
|
||||
$$
|
||||
|
||||
In our case, we got
|
||||
|
||||
$$
|
||||
\begin{equation*}
|
||||
V_{out}=\begin{cases}
|
||||
\text{if} \; V_{in} < 0V, V_{out} = -5V \\
|
||||
\text{if} \; V_{in} > 0V, V_{out} = 5V \\
|
||||
\end{cases}
|
||||
\end{equation*}
|
||||
$$
|
||||
|
||||
Our supply voltage are $5V$ and $-5V$, and the input is a SINE wave with amplitude of $1V$, and the reference voltage is $GND$ which is $0V$
|
||||
|
||||
### Simulation
|
||||
|
||||
{{< image src="P6-3-b.avif" caption="P6-3-b" width=600px >}}
|
||||
|
||||
{{< image src="P6-3-a.avif" caption="P6-3-a" width=600px >}}
|
||||
|
||||
### Measurement
|
||||
|
||||
{{< image src="P6-4-a-b.avif" caption="P6-4-a-b" width=600px >}}
|
||||
|
||||
{{< image src="P6-4-a.avif" caption="P6-4-a" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
Comparing our simulation to our experiment, we see that both of them are square waves with the same periods and similar amplitudes. They are fluctuating between 5 and -5, which are our supply voltages. This makes sense, because the supply voltages are the outputs of op amp comparators.
|
||||
|
||||
This proves our concept of an op amp comparator.
|
||||
|
||||
## 7. Prove the function of a mathematical op amp
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P8-1-a.avif" caption="P8-1-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
{{< image src="P8-2-a.avif" caption="P8-2-a" width=600px >}}
|
||||
|
||||
Summing amplifier circuit has a transfer function like
|
||||
|
||||
$$
|
||||
V_{out} = - \frac{Rf}{R1} \cdot V1 - \frac{Rf}{R2} \cdot V2
|
||||
$$
|
||||
|
||||
In our case, we want to use $50K \Omega$ potentiometer as the resistors, so it can be adjusted according to our demand. Then, we got
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V_{out} &= - \frac{\cancel{50K}}{\cancel{50K}} \cdot V1 - \frac{\cancel{\cancel{50K}}}{\cancel{50K}} \cdot V2 \\
|
||||
V_{out} &= - V1 - V2 \\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
### Simulation
|
||||
|
||||
We just used two SINE waves with different frequencies ($500 \; \text{Hz}$ and $1K \; \text{Hz}$) in our simulation.
|
||||
|
||||
{{< image src="P8-3-a.avif" caption="P8-3-a" width=600px >}}
|
||||
|
||||
{{< image src="P5-3-b.avif" caption="P5-3-b" width=600px >}}
|
||||
|
||||
### Measurement
|
||||
|
||||
Then, we setup the circuit. We just connected scope channel 1 to the $V_{out}$ to check it works or not
|
||||
|
||||
{{< image src="P8-4-a-b.avif" caption="P8-4-a-b" width=600px >}}
|
||||
|
||||
We have $V_s + = 5V$ and $V_s - = -5V$
|
||||
|
||||
{{< image src="P8-4-a.avif" caption="P8-4-a" width=600px >}}
|
||||
|
||||
We used wave generator to create to SINE waves of $500 \; \text{Hz}$ and $1K \; \text{Hz}$
|
||||
|
||||
{{< image src="P8-4-b.avif" caption="P8-4-b" width=600px >}}
|
||||
|
||||
And we checked the output wave using scope channel 1+
|
||||
|
||||
{{< image src="P8-4-c.avif" caption="P8-4-c" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
As we see, the shape of the output wave is exactly the same as our simulation. Both the amplitude of the output wave in the simulation and measurement is around $1.75V$, and the period is the same.
|
||||
|
||||
Since the shape and all features of our experimental wave matches our simulation, we know this op-amp works in different voltage ranges.
|
||||
|
||||
This proved our concept of summer amp which is a mathematical op-amp.
|
||||
|
||||
## 8. Prove the concept of transfer functions of Two-Channel Audio Mixer
|
||||
|
||||
### Building Block
|
||||
|
||||
{{< image src="P8-1-a.avif" caption="P8-1-a" width=600px >}}
|
||||
|
||||
### Analysis
|
||||
|
||||
{{< image src="P8-2-a.avif" caption="P8-2-a" width=600px >}}
|
||||
|
||||
Summing amplifier circuit has a transfer function like
|
||||
|
||||
$$
|
||||
V_{out} = - \frac{Rf}{R1} \cdot V1 - \frac{Rf}{R2} \cdot V2
|
||||
$$
|
||||
|
||||
In our case, we want to use $50K \Omega$ potentiometer as the resistors, so it can be adjusted according to our demand. Then, we got
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
V_{out} &= - \frac{\cancel{50K}}{\cancel{50K}} \cdot V1 - \frac{\cancel{\cancel{50K}}}{\cancel{50K}} \cdot V2 \\
|
||||
V_{out} &= - V1 - V2 \\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
### Simulation
|
||||
|
||||
We just used to SINE wave with different frequency ($500 \; \text{Hz}$ and $1K \; \text{Hz}$) to test what we expect.
|
||||
|
||||
{{< image src="P8-3-a.avif" caption="P8-3-a" width=600px >}}
|
||||
|
||||
{{< image src="P5-3-b.avif" caption="P5-3-b" width=600px >}}
|
||||
|
||||
### Measurement
|
||||
|
||||
Then, we setup the circuit. We just connect scope channel 1 to the $V_{out}$ to check it works or not
|
||||
|
||||
{{< image src="P8-4-a-b.avif" caption="P8-4-a-b" width=600px >}}
|
||||
|
||||
We supply $V_s + = 5V$ and $V_s - = -5V$
|
||||
|
||||
{{< image src="P8-4-a.avif" caption="P8-4-a" width=600px >}}
|
||||
|
||||
And use wave generator to create to SINE wave of $500 \; \text{Hz}$ and $1K \; \text{Hz}$
|
||||
|
||||
{{< image src="P8-4-b.avif" caption="P8-4-b" width=600px >}}
|
||||
|
||||
And we checked the output wave using scope channel 1+
|
||||
|
||||
{{< image src="P8-4-c.avif" caption="P8-4-c" width=600px >}}
|
||||
|
||||
### Discussion
|
||||
|
||||
As we see, the shape of the output wave is exactly the same as what we simulated. Both the amplitude of the output wave in the simulation and measurement is around $1.75V$, and the period is the same.
|
||||
|
||||
This proved our concept of summer amp.
|
||||
BIN
content/en/posts/ecse-1010/lab03/Lab03.pdf
Normal file
BIN
content/en/posts/ecse-1010/lab03/P1-1-a.avif
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
content/en/posts/ecse-1010/lab03/P1-1-b.avif
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
content/en/posts/ecse-1010/lab03/P1-1-c.avif
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
content/en/posts/ecse-1010/lab03/P1-2-a.avif
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
content/en/posts/ecse-1010/lab03/P2-1-a.avif
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
content/en/posts/ecse-1010/lab03/P2-1-b.avif
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
content/en/posts/ecse-1010/lab03/P2-2-a.avif
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
content/en/posts/ecse-1010/lab03/P3-2-a.avif
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
content/en/posts/ecse-1010/lab03/P3-2-b.avif
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
content/en/posts/ecse-1010/lab03/P3-2-c.avif
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
content/en/posts/ecse-1010/lab03/P3-2-d.avif
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-1-a.avif
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-1-b.avif
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-3-a-b.avif
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-3-a.avif
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-3-b-b.avif
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-3-b.avif
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-4-a-b.avif
Normal file
|
After Width: | Height: | Size: 180 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-4-a.avif
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-4-b-b.avif
Normal file
|
After Width: | Height: | Size: 192 KiB |
BIN
content/en/posts/ecse-1010/lab03/P4-4-b.avif
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
content/en/posts/ecse-1010/lab03/P5-1-a.avif
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
content/en/posts/ecse-1010/lab03/P5-1-b.avif
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
content/en/posts/ecse-1010/lab03/P5-2-a.avif
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
content/en/posts/ecse-1010/lab03/P5-2-b.avif
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
content/en/posts/ecse-1010/lab03/P5-2-c.avif
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
content/en/posts/ecse-1010/lab03/P5-2-d.avif
Normal file
|
After Width: | Height: | Size: 24 KiB |