Welcome to the 28th session in module 2 of the core signal and systems. We will now take a few examples of the calculation of the Fourier transform and then build upon the properties as we had promised to do. So, let us take one of the most traditional functions. Let us begin with what is called the rectangular pulse. We make the pulse symmetric, height a going from minus t by 2 to plus t by 2 on the time axis. We call this function h of t or x of t, whatever you like. We find its Fourier transform. So, the Fourier transform capital h of omega is going to be given by integral from minus to plus infinity, h t e raised to power minus j omega t dt and that is the same as minus infinity to plus infinity. Well, or a rather for minus t by 2 to plus t by 2 0 else, you know this is the function multiplied by e raised to power minus j omega t dt and that is essentially integral from minus capital t by 2 to plus t by 2 a e raised to power minus j omega t dt, a very easy integral to evaluate. So, you have a e raised to power minus j omega t by 2 minus e raised to power j omega t by 2 divided by minus j omega and we could multiply and divide by t by 2. So, let us simplify this. So, you have 2j sign, you know you can look at the numerator, numerator essentially is 2j times sign omega t by 2 divided by j omega t and now the 2 can be brought down. So, we have a t and the j can go away, sign omega t by 2 divided by omega t by 2 and this is a very special function. We can rewrite it in the following way, a t sign 2 pi f t by 2 divided by 2 pi f t by 2 where omega is essentially 2 pi f. So, you know f here corresponds to the cycles per second frequency and this is of course, the angular frequency as you know capital omega. So, the expression that we have here is a t sign pi, we will take pi outside, pi gamma let us say pi gamma divided by pi gamma where gamma is f t. Now, this function sign pi gamma by pi gamma is called the sink function. The sink function is an oft repeated and oft used function in the context of signal resistance. It would be a good idea for you to get very familiar with this function, understand it very well. Let us sketch this function now. So, this is how the function would look as a function of gamma. You can see that this will tend to 1 as gamma tends to 0 and it would have nulls at every integer. So, at 1, at 2, at 3 and so on. The function is also even. So, as you see the function decays in its oscillation as gamma increases both on the positive side of gamma and on the negative side of gamma. At every integer it has a null or a 0. At gamma equal to 0 it takes the maximum magnitude of 1 and subsequently the magnitude only keeps going down. I mean the magnitude as in the magnitude of oscillation and also the maximum value is never reached again. The maximum value of 1 is never reached again. So, you could call it a kind of damped oscillation, but damped in the sense of 1 by gamma. It is damped as the reciprocal of gamma. A somewhat slow damping as we understand in signals and systems. We are more used to what we call exponential damping. You know, natural circuits when they have damped responses produce exponential damping. This one is kind of slow compared to exponential damping. Anyway, it is a damped sinusoid of some kind. So, let us summarize the properties of this function. Let me in fact mark them right here. Even function damped sinusoid and nulls at the impedance. These are the three things that we need to remember. And therefore, we could now draw the Fourier transform of the rectangular pulse. Let us draw the rectangular pulse and its Fourier transform together. We must draw the Fourier transform as a function of f. So, we have its Fourier transform h of omega or h of 2 pi f, if you want to call it that. Now, let us make a few observations about this. See, the first thing is that the function is limited in terms of its occupancy of the time axis. It goes only from minus t by 2 to plus t by 2. On the other hand, the Fourier transform in principle lasts all over the frequency axis. Now, this is something, this is a function which is oft discussed and oft quoted to illustrate that because you want to make the function vanish all over the time axis outside a certain finite interval, you have to bring together frequencies of all magnitudes and signs except for a few nulls. Note that frequencies of all magnitudes and signs f going from 0 to plus infinity and also f going from 0 to minus infinity except for the points where there are nulls. Those frequencies are not required. All these frequencies need to come together in appropriate amplitude to form this rectangular pulse. Now, the beauty is h of omega or h of f is potentially a complex number, but here the Fourier transform turns out to be real. That means the phase is either 0 or pi. If it is negative, the phase is pi. If it is positive, the phase is 0. So, look at the Fourier transform here. The Fourier transform has a phase of 0 here and a phase of pi here and of course a phase of 0 here, pi here and so on. What is more? If we look at the Fourier transform itself, let us see how it varies as t varies, varying t. So, let me draw one for a certain t and then let me halve the t. Let us see what happens with a certain t. And now on the same graph, I will show what happens when I halve the t. If t is halved, this frequency is doubled. So, this moves here. Moreover, this now becomes a t by 2. So, in fact, this will also be brought down. Let me correct and draw the correct plot in a dotted form. Let us not be too fussy about the drawing. It is just indicative. So, what happens when we halve t? The nulls are doubly spaced and the central amplitude is halved. Of course, you can similarly see what happens when we double. If we double t, the nulls will be half-spaced. So, now you will have nulls at 1 by 2t and so on. So, you will have twice the number of nulls in the same interval. And of course, the central height will also double. Now, you can see there is some intuitive logic in all this. Let us look at this curve once again here. You see, take the black curve and the red curve here. In the black curve, let me mark or identify or kind of emphasize what I call the main loop. Let me emphasize that main loop. And let me emphasize the same main loop when t is halved. You notice that when the t is halved, when we halve the value of t, the main loop width is doubled and the main loop height is halved. So, in some sense there is a conservation of area if you might want to call it that loosely. Let us not be too fussy. Let us not be too strict on our interpretation. But it essentially says that the main loop tries to conserve area in some sense. And this is also true of the side loops. Let me point out the side loops. So, the other loops that you see here for example, this one is a side loop here. Let me mark it. This is a black side loop and correspondingly you have red side loops too. So, you notice something interesting. As you change t, there is a tendency for these loops, the main loop and the side loops to conserve their areas. It will lose asymptotic sense. What is interesting and important is that when you stretch the pulse in time, that means doubling t for example, the Fourier transform is compressed. And when you compress the pulse in time having t, you stretch the Fourier transform. This is a very important property of the Fourier transform. So, that is also kind of intuitive. We will see more properties of the Fourier transform as we go to the next session.


So, welcome everyone, my presentation about how Cassandra 4 gave us to cut the cost and we will be talking about the money, everyone wants to save some money to have some pay rise or stuff like that, to not let bezels left to the space one more time and do, for example, create next weird movie. So, my name is Robert Struppio, I was on the first Cassandra Sum in 2014, the first Cassandra cluster was also made like that, the first Cassandra production failed and also success and I'm Java developer, architect, DBA DevOps and finally also the FineOps. So who is the FineOps? The FineOps is the person who played with the Google Cloud, with AWS, with Azure to pay as less as possible, for example looking for some leftovers, cutting costs on everything what is possible, analyze day by day cost explorer, advice in CUD, CUD saving plans, some reserved or and finally FineOps should save more than just earn. That's just the general rules, but sometimes it could be different and FineOps also looking for the different weird correlation, like for example here, sometimes it's okay that we are finding something, sometimes it's like here, okay, so let's go further. So this presentation will be focused only on AWS because I have 25 minutes and I have to do some on that. I know that everyone want to go to the lunch to eat something, so I will be speed up and also only talk about AWS. So I don't have enough time to talk about Azure or about the GCP, for the GCP fans. So Cassandra could be deployed on on-prem, cloud, hybrid, everyone knows that and we can also choose a database as a service like the Astra key space or any other or just self-hosted on the Bermetal virtual machine or containers. So we will be focused also on just on self-hosted Cassandra. So where is the cast on the Cassandra which is self-hosted? So mainly it's inside the compute, so CPUs and memory on the storage it could be ephemeral, non-ephemeral, on the network of course, and some other stuff. And of course the DBA tools. So CPU and ROM, why it's so important to go into Cassandra 4 to save some cast of the CPU and memory. So Cassandra 4 of course as everyone knows supports Java 11, but why it's so important Java 11? So what it's new in the Java 11? So too long to read, just Graviton is Java 11 for being full speed. There is an article about that, there is a source of the slides, that's on the Java 8, the Graviton don't have the full speed. So if we go, if we want to cut the cost, just use Graviton. So it's ARM CPU made by Amazon. And the third generation of Graviton contain the DDR5 RAM memory. We don't have the issue of NUMA, so no new memory access because it's just one socket. There is no Graviton 3 machine which contain more than one physical CPU. So if you want to go with Graviton, just go to the newest Ubuntu version. If we for example, okay, it's Apple or Bezos, I don't know who. So basically if we go to the Graviton, we should use also the Amazon Linux 2, that's the second edition, or Ubuntu 22 or Ubuntu 20.23, something the new OS because on the old legacy, also for example the cache are not visible. So if you want to have the full speed of Graviton, we should choose the Cassandra 4 because it's Java 11 plus the newest Linux. And finally in our company, we are switching from old Intel machine to the newest Graviton. And finally after that, we realize that the Graviton third generation are so fast because it's DDR5 that we can even cut the number of CPUs and memory by 2 and there is the final result of the cost on the AWS cloud. I have to cut the numbers, but we see that we are switching for for example, R5D 20 X large to for example, R7G X large or so on. Okay, so storage, where we can save some money on the storage size. So basically on AWS, we have two possibilities, go to with the FMRL drive, so it's local SSD and FMI, on FMRL is the EBS, so elastic block storage. If we go to the elastic block storage, of course, we have three different options. It could be the standard drive, so it's a magnetic drive. We could go with GP2 or GP3. Don't use GP2 if someone have GP2, for example, for the root volume or something else. Let's move that to GP3 because GP3 is less expensive, it's cheaper and it's much faster or IO2 and IO1 and IO2. So for example, if we compare the same machine, one is R7G 2X large plus GP3 FMRL drive, the cost to R7G which the drive 2X large, so it contains the local SSD, the price is lower on the machine without the FMRL drive. But of course, FMRL drive is much faster. So we have the FMRL, but if we are choosing the faster FMRL drive which is the local SSD, we have also some additional cost, the cost of FMRL risk. So if we stop the instance which contains the FMRL drive, the FMRL drive will be loose and we lose all the data which are inside. So we cannot do any fancy feature like the AMI rollout. We cannot do, for example, the detach and attach this drive to another EC2 machine. We cannot easily scale up and scale down EC2 machine, so we lose a lot of capabilities which we have when we are using EBS drive. And we cannot easily extend or replace our drive. For example, after making some weird stuff on our tables, for example, remove this one which are not used, we want to save some cost by making our drive smaller. But we cannot do that using FMRL drive, we have to go with EBS for example. So what is new in the Cassandra 4? If we go to the Cassandra 4, there is another new fancy feature which is the compression. If we have some tables which contain a lot of data and it's not, it's like sometimes rarely used, we have a lot of disk space used, but the CPUs are not so often in use. We can switch, is it a compression from default LZ4 to that standard? After that, we will cut the disk space like 25%. After cut the disk space 25%, we can switch the EBS drive also to the smaller one and also save some cost. And we do exactly the same. We deleted and we dropped some tables which are not used. We realized that after some long investigation and we also switched the compression algorithm from the default LZ4 to that compression on the rarely used table. And after that, we cut our EBS drive cost by two. So another thing, so there is some parameters read ahead on the Linux site. So when we are reading some data from our EBS drive, we're reading something more and place that in our page cache. So the general recommendation which was on the Cassandra Apache.org in the production recommendation page said that if we are using SSD, we should go to the 4 kilobyte read ahead. But this is the parameters which should be set for local SSD. If we go with GP2, with GP3 or IO2, these parameters when will be removed, when will be replaced from the default 256 into 4 kilobytes, make our cluster so stressed that it will be working two times worse. We test that very, very hard. So with the general recommendation, but when we are using the bare metal machine with the local SSD drive. If we are using EBS drive, this general recommendation is not for us. Just remember about that. It's not for us because the EBS drive are, of course, the network disk. And the latency are much bigger. And when we are read ahead something from our disk size, and we are keeping it in our OS page cache, and we have very fast DDR5 memory, it has the benefits. So, network, where we pay for the network. Of course, it's the interzone, which is free on the AWS. There is a traffic cross availability zone, and of course cross the region. Service like S3 also could be for free, but it also depends on our configuration. So for interzone, we are not paying anything. So for some cluster, which are not so critical and can even lose all the data, we can place that by topology only on one availability zone. But it's also very risky, and I know it's not the general recommendation to avoid any other availability zone. But it's something which we could consider. But if we are thinking about the traffic, which is the interregion. We have the possibilities to enable compression. So first one is the traffic between the nodes and the client. Of course, we should use for the very small pieces of data, the snappy algorithm, which is by default disabled, for example, in S3 Cassandra data, and the traffic between the nodes. So in Cassandra 4, there is the new feature, which is the non-blocking inter-node connection. It also used the netty, not like previously, which was blocking. So we should compress all the data. By default, of course, then, I don't know why, but now it's working. So maybe I talked too much, but by default, of course, the traffic between the nodes in Cassandra is the compression between the nodes in Cassandra is enabled for data centers. But if we have different availability zones, and just Cassandra in one region, we are using more often the availability zone per rack. So we pay for this traffic between the racks. So my recommendation is to enable this compression between all the nodes. So between the different availability zone. Of course, we also did that. After enable the clients to node compression, and after enable the compression between the nodes, we also have some cutting cost after that. So basically, if we are sending some data into S3, like, for example, the incremental backups, like, for example, the backups or something else from our EC2 machine, we should not pay anything for that. But of course, we could have something which is called, sorry for that, we should, we could have something which called is the node gateway. So if we are running out of our VPC to something else like the S3 service, we could serve our network traffic directly to EC2, directly to S3, or via node gateway. So if we are not setting something what's called of gateway endpoints, if someone want to, if someone don't want to pay a lot of bucks for using node gateway, there is free of charge gateway endpoints. And after that, we are not paying for connection to S3 for our EC2. We see the result of enable this endpoint. So client's anti-pattern. So Cassandra 4 have some new capabilities, which name is the virtual tables. And after that, we can easily track the service which is the betas, for example, which use the different protocol version, which use something weird, which make a lot of data transfer, which we want to, for example, avoid. And after that, if we are going to the virtual tables and analyze that, we can also remove some weird stuff. I don't have time to talk about that. And finally achieve some better latency. And for example, there is a miss of this slide. But people are often use the spring data Cassandra. And inside the spring data Cassandra, it's some critical bug. And it's the critical bug in the GitHub 1, 2, 1, 3. I think that a lot of people know about that. But it was in the spring Cassandra data for 3.x. And it's bugs create the prepare statement for every single queries. So if we, for example, are happy that we are using some fancy feature like spring Cassandra data, everything is prepared, is made, every query made prepare statement. But it's not reuse that. It's not binding the new value. But for each particular query, create the new prepare statement. So we know that it made that stress on our prepare statement cache. And also generate additional traffic. So my, and if we are go to the table, which was introduced in Cassandra 3.11, not in 4.x, we saw that, for example, for each, for each queries, we have the new prepare statement, which of course made a lot of latency issue. And of course also generate the additional traffic, which also made the cost. So my general recommendation is to upgrade spring data Cassandra to the newest version. To avoid that issue and for example, if we are, if we have something, which name is the vault in the integration and for each microservice, we are generating the new credit credentials inside our Cassandra cluster. There is in the 4.x, very extremely important parameters. So we can set up our out create constancy level and our divide constancy level as ever we want. So basically by default in the Cassandra 2, 3, I think that even in the one, there is the constancy level for rich authentication, just one. So if we have situation like that, that we have some microservices deployed, for example, Kubernetes on something, something else. And we have this vault, we generate the new credit credentials. We could have the situation that one node goes down, what is normally in Cassandra because there is some patch, there is some operation because maybe someone kill minus nine by some incident or something, something, something else weird. So any other nodes which was the coordinator during creating the new credentials have some contain some hints. If the nodes will go back, it will be set, it will be sent back to this node which are, which are, which are down. And of course, if we are asking that node about our microservice to know if some users have the permission, have some credentials, the information about that could be stored in our hints and in the queue of the hints. And if we are asking that particular node which was down, we have some, we have some out permission issues. And to avoid that, we have to increase the identification for its constancy level or to not use any weird service like Vault, which creates in every five minutes new, new accounts and propagates that to all the cluster. Okay, of course, if I want to convince people to go into Cassandra 4, there is also something that's it's end of life for 3.x. So if you are looking for the support version during the download, the Cassandra, we just read that's the end of life. It's around December 2023. So now, if we have the version which is out of support, we should have, we could have some non-finance risk, which also costs us a money. For example, in the in the past, there is some major bugs, major vulnerabilities like the JMX RCE. So with remote code execution, which was of course solved by releasing new version. There is, for example, lock for shell, another big major big major bug. For example, 2023 overflow bugs. If we are staying on the legacy version, which not provide the upgrades, we will have the issue that there is some vulnerabilities, which is not fixed. So summary to go to the launch. So on the Cassandra 4 choose the Java 11, even if it's possible to use Java 8. And of course, the newest OS. Of course, go to the Graviton. Always test all good advice if it's much your cases. Because some advice could be some, for example, the Z-standard. In our cases, on the 90% of tables using Z-standard, it's good enough. It's not increase the latency, but cut a lot of disk space. Review from time-time cost explorer, if you have access, of course. If CPUs have some free cycle, enable compression. And many other good advice. So final result of our cutting cost mission. There is a question for the audience. Have anyone want to guess how many percent we cut our TCO? So total cost ownership. In how many percent we cut our TCO? You can guess. OK, next shot. 60, next shot. Close. For the one who will shot, I have one Bitcoin. Not less. OK, who set 70? OK, it was 69. So a lot. So it's a Bitcoin for you on the end of presentation. So finally, we go with Cassandra 4. We switch because we should, because Cassandra 3 is end of life. I don't think if I have to tell something else why it's worth to go to the version which is under the support. But it's important. So thank you for attending my presentation. And there is a time for question. Now only that one. Of course, we did a lot of different scenarios like going to the table, looking on the table starts, going to, for example, we don't have data. But going to our monitoring and figure out which table are in use, which generate the latency, when we can switch to the compression, different compression, which table are not in use. There is also one table which contain, if I could remember, 10 terabytes of data which are not in use so often. So we go to the business to talk with them if we can remove this table. And finally, when we have some calculation of our EBS drive and how much it will save us the money, they said, OK, so remove that. Which storage? OK, so the question was on which storage we are. So we are using EBS GP3. Of course, IO2 is each much faster and have more and less the performance very similar to the local SSD. But it's so expensive. If I will use the IO2, I think that this presentation will be not the cutting cost name, but will be some changing the drive, changing the EBS type of drive. Because IO2 provision, only not the disk space, but also the number of IOPS and the throughput. And if we want to have more IOPS than 100, we have to pay for that. On GP3, by default, we have 3,000 IOPS for free in the free tier. OK, so our big IOPS requirement, if we are a monitor, so during the peak, it's in the prime time around 2 PM where people start to go and maybe write some charts and stuff like that. It was like 2,000 IOPS per machine. So we are still in the free tier. In any time when we will observe some big peak of the users, we can go to AWS console or run the Terraform and increase that. If I could remember, AWS allow us to switch one time per six hour to switch the IOPS in any time.


so it was so emotional, so heart touching and we all become really emotional by speaking we never thought of giving this kind of speech and we have blamed so many things it is a historical day for this road and its every space day also really wonderful everybody loving and enjoying this moment thank you


Can you believe it when I say our entire coastliners divided into different zones? You have to believe it because it is the truth. Yes, I'm talking about the coastal regulation zone notification, which is released by the Ministry of Environment. And here is everything you need to know about the CRSIT notification. See in the year 1991, the Union Ministry of Environment notified the Coastal Regulation Zone notification. So, what does the notification do? See it declares certain coastal stretches as Coastal Regulation Zone under Section 3 of Environment Protection Act 1986. So, this is about the Coastal Regulation Zone notification. See, largely the CRSIT area is based on the high tide line. High tide line means the line on the land up to which the highest water line reaches during the spring tide. See, this HDL, which is the short form of high tide line, is demarcated by the National Centre for Sustainable Coast Management. Now, look at this image here. Here, the red line is high tide line and the blue line is low tide line. So, the low tide line is nothing but the lowest level up to which the water reaches during the spring tide. Now, with this basics, let us see about the different zone nations in CRSIT. First of all, we are going to see CRSIT 1. It includes areas between low tide line and high tide line. And it also includes areas that are ecologically sensitive and important such as national parks, marine parks, sanctuaries, reserve forests, wildlife habitats, mangroves, coral reefs, etc. And it also includes area which are closer to breeding and spawning grounds of fish. And it also includes areas of historical importance. See, all these areas, they come under CRSIT 1. And these areas are the most protected area. In this zone, no new construction will be permitted except for the projects relating to the Department of Atomic Energy and construction of trans-harbour sea link and routes. So, this is the exception. Now, apart from this, you should know that if an area that comes under CRSIT 1 is not a eco-sensitive zone, then the exploration and extraction of natural gas, salt harvesting and desalination plans are also allowed. So, this is also an exception. But the condition is the area under CRSIT 1 should not be a eco-sensitive zone. And only then these activities are allowed. Now, moving on to the next zone which is CRSIT 2. Now, look at this image here. Here, CRSIT 2 is highlighted in the orange colour. This includes area, landward of high tide line which includes the areas that are already developed. See, the crucial point here is it includes areas that are landward of high tide line. So, it extends from the sea towards the land. See here, developed area is referred to as that area within the municipal limits or in other legally designated urban areas which is already substantially built up. See, what does this mean? This means that these developed areas, they have already been provided with drainage, approach roads and other infrastructural facilities such as water supply, sewerage, etc. See, here no new construction shall be made on the seaward side. See, we saw that the area under CRSIT 2 extends from high tide line towards the land. So, what activity is prohibited here? New construction is not allowed on the seaward side which is towards the sea. And then reconstruction of authorised building will be permitted only if it adheres to the FSI norms. Here, FSI is nothing but floor space index. Now, that is all about the CRSIT 2. Now, coming to CRSIT 3, see, this includes areas that are relatively undisturbed and those which do not belong to either category 1 or category 2. See, in this image, CRSIT 3 is highlighted in red colour here. Now, as you can see, it is subdivided into two areas. The first area is 200m landward of the high tide line and it is called as the No Development Zone. See, here no construction shall be permitted except for the construction of gardens, pastures, parks, play fields, forestry and salt manufacture from seawater. Now, coming to the second subdivision, it is the area between 200m and 500m landward. See, here development of vacant plots for construction is allowed only after prior approval of states. Now, this is about CRSIT 3. Now, coming to the final one which is CRSIT 4. See, this includes areas 12 nautical miles seaward from the low tide line. See, CRSIT 4 is nothing but the territorial waters of the country. See, in this area, traditional fishing is allowed, but discharge of untreated sea wages prohibited. Now, these are the different zones that are categorised under the CRSIT notification. Now, finally, coming to who has the authority to give clearance. According to 2019 CRSIT notification, the Ministry of Environment, Forest and Climate Change will oversee the matter of CRSIT clearance only for CRSIT 1 and CRSIT 4. Do you remember what areas come under CRSIT 1 and CRSIT 4? Yeah, CRSIT 1 includes ecologically vulnerable areas and CRSIT 4 includes area between low tide line and 12 nautical miles seaward. So, for these two categories, Ministry of Environment gives the clearance. And the areas which comes under the other two categories that is CRSIT 3 and CRSIT 2, the power of clearance has been designated at the state level. That is, the authority to give clearance has been delegated to the states. And now, I hope you are very clear about the different zones in the CRSIT notification and you will be able to tell who has the authority to give the CRSIT clearance. Now, if you want to know more environment-related topics like this, subscribe to Shankaraya's Academy's YouTube channel or watch the daily news analysis of Shankaraya's Academy. Thank you.


So basically, it's a batch of college college. It's really... You might need this. Okay, you're going to put this in your pocket, I think. Definitely amateurs. Hello. Hi. Hello, hello. Hello, hello. Hello, hello. Yes, I'm... We don't have that. Okay. Okay, yeah.  I will say, I think he's a very smart guy. Because the challenges are really fun to do. So it's released during the Christmas period over 25 days. So he will release one each day, and people will compete to see who can compete his challenge first for each day. And so it looks very old school like this. So each day, there will be one challenge. Then you will open up the puzzle input, then you... So the puzzle input is unique for each person who will log in. So you cannot just copy your friend's answer. So... And then you submit it. And you can... So there's... So, okay. This is just what I was saying. So you are free to use any programming language you want. So because I use JS, so I will share today's talk in JS. So there are things like leader's board.  There are some really crazy people out there that can finish in two minutes, five minutes. Yeah. Then you can look at your own personal stack. My stack wasn't that good, but because most of the time when they released the challenge, it was lunchtime. So I wasn't doing the challenge. Yeah. So you can also see actually how many people actually completed. You can see along the way, people are dropping off because they are fighting too tough, too harmful for their health. But if you need a little more help, that's always ready. You can... People actually share their solution. And you can actually see how it's done. So I'm going to share some of the learnings I've learned from this, doing this, because if you do your day-to-day JavaScript, you hardly actually touch some of the tools that you get to learn, that is out there. You know you learn about it, but you hardly actually try out these tools because the kind of problem you face in your day-to-day is actually very restricted. So doing coding challenge sometimes actually is very helpful to open up your eyes to new things out there. So for example, first thing, generators. Actually, who here knows about generator and actually do use it in your code? Actually, you know what actually... Even you learn it, you hardly actually find a chance to use it. But actually coding challenge really has a lot of problems that actually generator is ideal for. So by the way, for those who don't know what the generator is like, basically a function with a star and the function will return the iterator. So within your function, you can have this use statement that will return a value and the next time you call the next, it will go to the next use statement. So it allows your function to operate like a go-to statement. So I'll illustrate. I'll just use one case where it's actually very nice case to say. So for example, one of the problems, day three of 2017. So the problem is actually about spiral traversal. So it's not that hard once you actually draw it out on paper. So once you draw it out on paper, you realize that actually the pattern is very easy. So right one step, up one step, left two step, down two step, right. So every time you move two, you actually increase one more step to go. So since the pattern is so easy, so we can actually write a generator for this to solve this problem. So this is basically the implementation of what I was writing down just now. So it's like write one step, up one step, then increase the number of steps to two steps then. So you see all this use statement down here. So when I actually call my function to actually get the result, so I only need to just do a dot next dot value. So why is it this one is appropriate? So you will say like, why don't I just create an object to do it instead? Or say just, why don't I just take this entire code and put inside here and isn't it as trust that I create a generator that I use the generator inside? Because just don't forget to mention one point that every code usually has two parts. So the first part, so the first part maybe is like something very simple, just do a spiral traversal. So the second part, you need to do something at each step. So you see now if I had actually done the whole function inside here, then I need to put something else and another process down here to inside each of these use statement to actually do some further tasks. So actually this actually made the code very ugly because the traversal step and the processing step can be actually separated out cleanly in this case if I use a generator. So what I need to change is just do some process at this step because I already use the current position that I traversed to. So this is one use case where actually generator is very appropriate. So you say like why don't just create an object? So the difference between generator and just create an object with internal state is your internal state is not encapsulated as a variable or as a variable in your object. It's actually encapsulated as, you can use the part of the code, how to say, sorry I have to keep going back to this. So just the position of this code encapsulates the state of the generator. So if I have written this entire thing in the form of an object, then I need to keep track which step am I in? Am I in the left step or the up step or the down step? I have to keep track like what is the number of steps that I am at right now. But with a generator all this is actually encapsulated as the position of the code which functions very much like a go-to statement. So in certain case actually go-to statement is actually much more readable than creating an object and encapsulating states. So this is the first thing that I learned. So I go to just show another example. So there's another problem because it's all Christmas later. So they have this reindeer Olympics. Actually it's very simple. If you fly for a distance then you have to rest because you need to recharge then. So you have to just see the question and just see which one arrives first. So if the problem is just simply compare a bunch of reindeer that travel in this mode, of course you can have just a complicated mathematical equation that's solved for this. But the part two of the problem requires me to actually solve for this for every time interval. So now it will be actually more wasteful to use the complicated mathematical equation. It will be easier to just compute the state of the reindeer at every step. So I just make each reindeer into an express frame as a generator. Then I just call them with a dot next for each take of the event. So this is another example where the generator can be used. So there are actually a lot, a lot other examples we didn't ever have of code. So if you all actually get to try, you all can see. So what is the next thing that I find is very useful that I learned is so we do use gadgets all the time but actually coding challenge actually push your knowledge of gadgets to the maximum because you get to try things that you don't normally try. So for example, for one question in my coding challenge it's actually finding a bar sequence. Basically it can be like A, B, B, A, A, B, A, A, B, X, Y, Y, X or Y, X. So any a bar sequence. So do you all know that actually gadgets have this very interesting pattern that you can use? So this slash 2 slash 1 basically means take the result that is the second captured result. Slash 1 means take the first captured result. So actually I didn't even know about this so I actually googled at far about this and actually used this to solve the challenge. So there are a lot of these chances to use gadgets when doing coding challenge. So another sub that I find interesting is actually 2 core. So one of the, so one of the challenges actually deals with this what we call look and say sequence. So this thing actually came out on the internet recently. Somebody came out with this challenge that trying to actually, so it starts from 1 and the next number is 1-1, next number is 2-1, this one. So it doesn't look like there's any pattern but actually this is what we call look and say sequence. How it works is since there's only 1-1, we call it 1-1, then the next time there's 2-1, so there's 2-1, next time there's 1-2 and 1-1. So this is the look and say sequence. So the task is not to figure out this challenge, this sequence because they already say it's a look and say sequence but to actually implement it, run it for 40 rounds and get the result out of it. So it's a very, very simple task. So I just write a recursion function that scan the first stretch of numbers and then continue with a recursion with the remaining stretch. So what it is, when I run it for 40 rounds, we encounter what is called step overflow because JavaScript does not have a proper to call. So there, but what about... Yes? Can you zoom in? Zoom in. You can actually share the link of the slide. You can actually look from the .js issue. Yeah. But we can actually make this into a proper to call. So by changing the function, now I return the recursion function and this is a proper to call and now I can run for as many cycles as I want. But unfortunately, it's only supported in node 7 and set spoil 12. So somehow Google VA Engine stops. The latest VA Engine doesn't support. So even with a flat, you can't do it. But in case you're actually still need this, actually there are ways to actually overcome it. You can actually do write a recursion. Any recursion actually can be returned as an iteration by using a stack. So next I'm going to share about enumeration. So a lot of coding challenge actually requires you to enumerate stuff. So enumerate all possible... So rather than try and find the solution, you just enumerate all possible solution and you find the one that meets the criteria. So some example. So for example, so we want to find all combination that totals to a certain value. So in this case, we need to enumerate all possible assignment combination like 0, 0, 0, 0, 0, 1. So in some case, we need to say travel route from... find the shortest route. So we need to enumerate all different permutation. So this is easy to say just enumerate but actually implementing enumeration requires some tricks. So in another case here, instead of enumerating a trick that covers all the destination, we're enumerating a sitting arrangement. So this is actually not very much different from enumerating route. So you actually just need to fix one position then enumerate the other person, the other people around the table. So finally, there's also this problem here that is by the ideal recipe. So let's say I have 100 units, 100 teaspoons. Then each teaspoon of a particular ingredient adds a certain properties to my cake. So we need to enumerate all the possible combination of these ingredients. So let's say I have three ingredients. I can have 0 unit of the first ingredient, 0 unit of the second ingredient. So how do I enumerate all these possible combinations? So there are ways to do that. So for example, I will use... So for example, enumerating assignment, so the 0, 1, 0. So how do I actually... What strategy to do that on JavaScript? So basically you just need to count all the binary values. So you count from 0 to 2 to the power n minus 1. So then you use number.prototype.toString2. This will give you the binary representation of the number. Then from there, you can pair it with 0 and you split it out. So this is a very easy way to enumerate from all binary combinations. So this is my implementation. So this is the easy one. This is the harder one, the split combination that I mentioned about just now. So how do you enumerate while making sure that your total is always sum up to 100? So the trick here is instead of enumerating the numbers, you enumerate the split point. So let's say I have 10 items here. So let's say I need to make four... How many here? One, two, one, two, three, four. Let's say I have four types of ingredients here. So instead of enumerating the four ingredients of the number, I enumerate the split. So I actually enumerated only three numbers down here. So I enumerate by... Say I made a card at these two positions. Then the ingredients, the units of the ingredients is actually just the difference between adjacent cards. So by doing this, I can ensure you always sum up to the total number. So this is my implementation in JavaScript. So I'm not expecting you to read this. So you can read it on your own laptop. So because I'm a very tired person, so along the way, I realized that actually I'm repeating all these enumeration tasks. So I actually write all these helpers though for my coding tasks, for different kind of enumeration tasks. So if you are going for coding interviews, can actually come and look at my helpers for revision. Because enumeration is a very basic task, but it's the kind of stuff that, under the pleasure of interviews and stuff, we always forget how to do it. So next thing, how about lazy enumeration? Because just all the functions that I share are not lazy, in the sense that it actually enumerates everything before you return. So in some cases, we actually don't want it to enumerate everything because the combination is just too much. We want it to return early once the first result comes back. Once the first result that meets a certain criteria comes back. So how do we do that? So we use this very nice new JavaScript tool also called Iterobos. So who actually tried using Iterobos before constructing your own Iterobos? Other than using the default built-in. So we can use what Iterobos does, what Iterobos is, it's basically a function that implements this special method called symbol.iterator that returns Iteratorator. So this function, this Iterobos is, you can use it by things like, say, fall off loops, or you can use the array.from, or you can use a spread operator or this. So just for example, so I rewrite the earlier one I shared about the assignment enumerator into Iterobos form. So with this form, I can actually break halfway once I actually found the result. I'm doing the enumerate every possible result out. So there is a call way to use it as a wrong one. So Iterobos, you can actually use array.from. You can use a spread operator. But these are the wrong way, because once you do it, any array.from, you actually enumerate everything already. It's no longer lazy. So the proper way is to use it in a fall off loop so it can break off early. So also while playing with coding challenge, you'll also be doing a lot of graph searches. So some of the tips for graph searches, the very basic reference search, how to implement in JavaScript, always have a visitor, which is an object. So you can key and actually check for duplicates. Then you have an unvisited, which is an array. So that first search, use a queue. So use shift. That first search, use a pop, use a step. So that's why I use a pop. So the important thing to remember, so for those who are familiar with com size and do know about that first search. So the important thing to know about, to remember for that first search is, remember that because you don't do that first search, you usually don't do that first search randomly. Because if you are, that first search, you can always end early once the results found. But that first search, you will search until the end of the tree node then before you visit the next node. So usually we will sort our results and we actually visit those that are more likely to give the result we want. So because we do some sorting, so it's important to actually reverse the sort because you are using a step. Because you are using a step, the first one that you pop is the last one that you push in. So because of the last same first search, always remember to reverse your result. So also in FL code, we also deal a lot with this kind of assembly code like of challenge. So when dealing with this kind of coding challenge, so it's very typically very hard to debug. So what I learned, what I really learned is that finally I actually convinced myself to actually use the proper way to debug instead of using a console.log. So the proper way to debug a node, a node program is that it should use this inspect, break, flag. So how many people actually do use this one before? Yeah. So a few of you. So most of you are lazy, we just use console.log.  So right there are just some of the some of the learnings, as much as possible, work on paper.  So work on paper first. Example like the case where I show you all the spiral traversal disk. This kind of problem is very easy once you put it down on paper. So also don't premature optimize. Focus more on writing clean code than actually writing performance code. So let's wrap it up. So I actually check all my solutions to ever our code for the 3 years 2015, 16 and 17 on GitHub.  So that's all. So we have time for questions. So just back me up to the store and you did this every day for 120 days? Yeah, no, no. So it's over 25 days. So I found out about this only in 2017. So I realized that's the 2016 version and 2015 version. So over that same 25 day I decided to do all 3 years and I won't go. So what's the average time you take to solve? So it depends on how hard the problem is. Some problem I spend actually 5 hours or more to solve. So it's not that trivial like the spiral traversal and all this. The ones I show are the really trivial ones. The average problem is much more difficult. So what is the benefit you would say when you're doing more mundane tasks or if you're working on a project, do you implement some of the new techniques or smart ways of a personal problem to learn from the challenge? So for example, the generators and all this. I would say I would still find it hard to actually apply it in my daily task. But now I actually have the confidence that I actually know how to use a generator or it's even like iterables. But just learning by reading MDN and stuff, you don't really have the confidence to say that you actually really understand. But when you actually work on this stuff that is outside of your daily, what you're doing in your daily stuff, it really gives you the confidence that you actually understand these concepts. And then you might realize that actually you apply to that. So does anyone have any question on iterables or... When you do this challenge, it's like what's pushing you to do for a smart solution like a generator instead of waiting for an object instead? Because there's always a similar way to solve these problems. Because I want... So even though the challenge is really about finishing it, being the first person to finish it, to most people, I would rather play this game in the sense of writing the code that is most understandable, clean, that somebody else reading my solution will immediately notice what I'm trying to do. This is something that I actually practice a lot myself, even within my day work. So when I'm doing this challenge, I also try to actually write code in a very clean way even by using these new tools. I've heard of this thing called the 408 loop. I haven't really used it, I think. Oh, 408. Something of something. I think it's ESA. I think it's an ESA feature for a wait loop. Not yet. But I think it's actually also running on... It's running on an iterable. It's running on...  Yes. That's actually... Require this generator. Yeah, so I think there's actually a proposal for AC iterators. But I haven't tried it yet. Yeah. Have you found any uses for OXYs and Max and Sets? Maps and Sets. I haven't actually... Because I think objects are good enough for me for now. I mean, I didn't use maps... Sets before sometimes. Cool. Any more questions? Go for it. Did you write tests for your solutions? Why or why not? Did you write tests? No, I didn't write for that question. Did you write tests for your questions? No, but... But I usually construct my solutions that... So I was lazy here to just copy in the input rather than actually passing the... So I try and find one. So generally, I will write my function with extra variables, with some default variables that allows me to actually run tests on it. So because the actual problems, I will actually set a default value to the additional variable. So it allows me to actually run on different... So for example, the actual case, I need to run on, say, 50x50 box. But usually the question will provide some test example with, say, a 5x5 box. So I will actually supply an additional variable that allows me to actually change my function out to be able to run tests on those test cases. But it's still manual. I didn't actually specifically write a separate test for my functions. Thank you.


So you want to rotate unity like a master, not a problem. For the sake of keeping this tutorial simple I will not be typing in delta time, but when you add this code to your game don't forget to add delta time. If you just want to rotate your object constantly like a cyberpunk holographic sign or something just use transform dot rotate. Like everything else these numbers represent x, y and z. So if you wanted this object to rotate constantly on the y axis at a speed of 0.5 then just type that here. Say even when you run the game you will see it doing exactly that. But if you know what sort of angle you want your object to be in you can set it with transform dot local Euler angle. So if we type something like 3, 0 and 45 save and play the game that is going to be your object's rotation. Now these are vector 3's so again you can create your own vector 3 variable and replace it here if you want. If you are trying to control the camera or the player character you should probably use transform dot local rotation equals quaternion Euler. It's kind of like local Euler angles but the difference is y is usually parallel to the ground. That's ideal for the camera. If you want an object to look at another object create a variable for that target object and then type transform dot look at and whatever the name of that object is. Stand in the inspector, drag the object that you want to be the target into your variable and when you run the game your object will always be looking at that target object. There's one more method I want to show you but I think that's enough for this video. Hope that helps and as always I hope you have a fantastic day and I'll see you next time.


We've introduced some concepts. What do we mean by data communications, links, networks? We've talked about signals and then we've looked at performance metrics in the previous topic. Now we're going to go into the details of the basics of communications and look really at signals. And look at signals, communication signals in a mathematical perspective in this topic. And then in the next topics, a few more details about how do we take, let's say our data, think of bits. If we have digital data, how do we take a sequence of bits and convert them into some signal that can be sent across some link as an electrical signal or generally electromagnetic signal. Many of the examples I'll use will talk about transmitting digital data. Zeroes and ones is the data we want to communicate whether it's a file, like a text file or a video. It can be converted to a binary and then that's the data. Then we convert it to a signal to be sent across a link. But the same signals are used for analog data as well. Like when I'm talking, I'm communicating analog data to you. It's not digital. So we'll see examples of data as we go through. Data transmission. Let's first introduce some simple terminology. We're focusing on a link, a single link. There's a transmitter and a receiver. And we want to get data from the transmitter to the receiver across some link or generally across some medium, the thing between the transmitter and receiver. And what's transferred, so we want to get data from transmitter to receiver, the way that we do it is we send some signal, some communication signal, which is in the form of electromagnetic waves, an electromagnetic signal. And the examples I'll use think of a sine wave as a very simple representation of electromagnetic wave. But electromagnetic actually contains two components. The electrical component, electro, as well as the magnetic component. A magnetic field and electric field. But we'll just think of it as sine wave and we'll use that as the concept. So get data by sending a signal from transmitter to receiver via some medium. What types of medium? Well, we've got classified the medium as either guided or unguided. Guided is when that signal is, as the name suggests, guided somehow by some materials in some direction. And really that means wired. So the signal may be electricity flowing through a copper conductor. And the signal effectively is maintained within that wire or with the insulation around that wire. The signal does not disperse much. So we'll look in the next topic about these media in detail like copper wires called twisted pair, the LAN cables, coaxial cable which you may use for cable internet or cable TV, an optical fiber, and so examples of guided media, wires or cables. The signal, think of the signal is guided within the conductor or within the wire. Unguided is wireless. So we don't have a material, we transmit our signal through the air. No wires. Through the air, through the water in some cases or in a theoretical case through a vacuum. So guided is wired, unguided is wireless. So we're focusing on getting from transmitter to receiver across a link that may be guided or unguided. Usually in most of our cases or examples we'll refer to one device sends to one other device, a point-to-point configuration. Two devices share the medium. We have a cable from one computer to another. The medium is that wire where our signal propagates across. It's shared by the two devices which are connected. So the wire connects into the LAN cable, LAN port of my laptop and into the LAN port of this PC. There's two devices sharing that medium. That's the most typical case we think of. But we can have multi-point configurations where there are more than two devices sharing a medium. An example? Someone? What's an example of a medium where we have multi-point communications? Air. Okay, wireless. Typically, not always, but we typically think of wireless communications as multi-point. Some cases we'll think of it as point-to-point.  So it's not one-to-one, it's not point-to-point, it's one-to-many or multiple points sharing this medium. So different configurations of our links. Point-to-point generally is the easiest. There's not much we need to do to get that to work. With multi-point, we need to deal with the fact that there may be some interference. It's also the case in point-to-point, but more so in multi-point communications that it becomes a little bit more complex to make sure it will work well. And when we communicate, we also look at the direction. And the terminology we use is simplex, half-duplex and full-duplex. Simplex is a communications medium where we send in one direction only. For example, broadcast TV. There's a TV station somewhere, they have a transmitter, some TV tower maybe, or if it's satellite TV, they go via the satellite and they transmit a signal and your TV with the antenna receives the signal. So it's going from the TV station to your TV. Your TV does not send anything back to the TV station. So it's simplex communications. Full-duplex at the other end is a, think of a link where we can send from A to B and at the same time be sending from B to A. So both directions at the same time. Half-duplex, both directions are possible but only one at a time. A can send to B but if A is sending to B, B cannot send back to A. They must wait until A is no longer sending to B. That's half-duplex. Handheld radios, sometimes called CB radios or private radios that are an example where you press a button to talk. You press the button, talk. The other person hears and listens. Then you release the button and then they press the button and talk back to you. So we can communicate in both directions but only one person at a time. That's half-duplex. Any questions about this introductory terminology? What is this lecture? Which medium, which configuration, which direction? The lecture, which medium do we use? Guided or unguided? When I'm talking to you, when we're lecturing first, medium unguided, we're using wireless communications. Well, there's some form of wired communications if we use the microphone but assume there's no microphone, if I just talk then wireless all the way from my mouth to your ears. Configuration, this lecture, point-to-point or multi-point? Multi-point. One transmitter, multiple receivers, more than two. Direction. Hands up for simplex. Hands up for full-duplex. Hands up for half-duplex. I prefer half-duplex. If I talk, you don't talk. But if you have a question then do so but don't interrupt other people. So we prefer half-duplex. Sometimes it turns out people get excited and talk a lot and it becomes full-duplex. But let's not make it simplex. Make sure you ask some questions during the lecture but try not to interrupt too many other people. For some reason I've never fixed the title of this slide. It's wrong. It's not appropriate. Maybe a better title for this slide, and you can change it, is electromagnetic signals. It's a copy and paste that I didn't fix at some stage. Electromagnetic signals. Those three things, a frequency spectrum and bandwidth, come up later. So the signals that we use to transmit the data from transmitter to receiver, the transmitter generates an electromagnetic signal. So my LAN card generates a signal and outputs it in the case of a LAN cable. The LAN cable has copper wires inside. So it outputs an electrical signal under those copper wires and that signal propagates to the receiver. The signal represents the data and I think we've mentioned before a simple case would be if you think of a signal, a high signal could represent bit one and a low signal, say in terms of voltage, could represent a bit zero. We'll see some other schemes. In this topic we're going to look at the mathematics of those signals and see that a complex communication signal can actually be broken down into simple signals that we can analyse and design. If I ask you to draw in an exam or a quiz a signal, what would you draw? A simple signal. Someone does this, a digital, a square wave, and another one, a sine wave, a sinusoid. So that's what we'll deal with and we'll see that even complex communication signals like sending a radio signal from a laptop to this access point, we can think in the perspective of just a set of sinusoids, sine waves. So that's what we'll go through today. The two domains we'll come to later. We'll focus on the time domain. I'll introduce the frequency domain after we cover the time domain. Very simple stuff today. Some waveforms or example signals we can distinguish between analog and digital. Analog. It varies in a continuous manner over time. Digital, discrete manner. So digital signal maintains some level for some period of time and then instantaneously changes to another level. And so on. So just the difference between analog and digital in terms of a signal. And if you look at these plots, this axis is time. So things are changing over time and this axis is shown as volts, sometimes also power watts. The signal amplitude, the height of the signal, measured in volts typically. If you think of an electrical signal coming out of my laptop, you can measure the signal amplitude. Any problems, analog versus digital in terms of signals? Continuously varying versus the discrete variations. Going back to simple signals. Some concepts. This is from high school physics, so this is nothing new to you. We can talk about periodic signals. These two are examples of periodic signals. They repeat. And these two are examples of aperiodic signals. There's no repetition. They continuously change. In much of our analysis, we'll look at periodic signals. But in practice, aperiodic signals are common. Nothing interesting there, period. Let's look at a simple sine wave. Again, a refresher from when? High school. Sinusoids. An equation for a sine wave. The signal strength has a function of time. I have my pen. I have a flat battery, I think. A mouse. The signal strength has a function of time. S is the signal strength of the amplitude in those previous plots. T is time. Generally, it can be written as the amplitude, or the peak amplitude, A, times by a sine, the sine function, of 2 pi f t plus where 2 times pi f will be the frequency of the signal. T is time. And phase c is related to the relative position of that signal to some starting point. To zero. Three components, or three key parameters in this equation. Sine is just a function. 2 and pi are just constants. T is the input parameter. We have peak amplitude A, which is a multiplier on the sine function. We have frequency f, which will be the rate at which the signal repeats. And we have the phase phi here. Let's just remind you of how those impact on the shape of a signal. These are four plots of that equation with different values of the f and the phase. And it's probably easier to read, maybe a little bit easier, but it's hard to read on the screen. The top left plot, if you read here that amplitude is 1, the frequency is 1, and the phase is 0. So if you plug those values into this equation, A is 1, f is 1, and phase is 0, it becomes what? Sine 2 pi t. Sine 2 pi t, where t is time. And in our plot, time varies in this case from 0 to 1.5 seconds. So sine of 2 pi t, if t is 0, sine of 0 is 0. If t is 0.25, then sine of 2 pi t is an output of 1. And we get our sine plot. What's the period of this signal? What's the period? 1 what? No? 1 is correct, 1 something. What is the value of the period? 1 second. The period, remember, is the duration in time of one cycle. So one wave. It goes up, comes back down, and back to the origin here. So the period is from 0 to 1. Period is 1 second. How many times does a cycle repeat per second? How many cycles per second? In 1 second, how many cycles? 1. Therefore the frequency is 1. The frequency is the measure of the number of cycles per second. The repetitions per second. Frequency is 1. The period is the inverse of the frequency. If a frequency is 1, the period is 1 divided by 1. Also 1 in this case. The amplitude, or actually I always call it amplitude, is the peak amplitude is the maximum height. It goes up to plus 1 and it comes down to minus 1 here. The phase we'll see as we get to the other ones. It's the offset from the origin. When time is 0, our signal is 0. If we change the phase, that will change. Move to the right. Same equation except peak amplitude A is 0.5. Same frequency, same period, same phase, but you see the amplitude is shrunk to half. That's all. Bottom left. Peak amplitude is 1. Frequency is 2. Within one second there are two repetitions. Two repetitions per second. Frequency of 2. Two cycles per second. How do we measure frequency? How do we measure frequency? What are the units? Hurts. A frequency of 2 hertz Z is the symbol of the abbreviation. Frequency of 2 hertz 2 repetitions per second. Period of what's the period of this bottom left signal? A half a second. Period is 1 divided by frequency. If the frequency is 2, the period is a half. This is nothing new to all of you, I'm sure. The time for one repetition is half a second. Any questions on the first three? They just illustrate the impact of the peak amplitude and the frequency. And the last one illustrates the impact of the phase. Ampitude 1, frequency 1, phase, what we call a phase offset of pi over 4. Phase is a measure of angle measured in radians. Pi divided by 4 radians. You see the impact on our waveform compared to the top left and the bottom right. It shifts it along. So think of this one. It's been shifted back some portion relative to this one. So we don't start at 0, we start at 0.7 something with this phase offset. The offset's in time. The original sine wave. Any questions so far on sine waves? Remember that equation. Let's have a look at some. Why do we introduce this? Because our signals will represent as sine waves, sinusoids. But more complex than just a single sinusoid, what we'll eventually come up with with communication signals is if you add multiple together, you get another wave. And if you add multiple together, you can start to generate communication signals to represent the data that we want to send. So that's what we'll end up with with this topic. We combine sinusoid together. Let's go through a few examples. And I'll try and plot some. And you can answer some questions about them. I need to remember how to do this. Objective. I've just got some mathematics software that will produce some plots of sine waves. Just so you can see the impact of the different parameters. And then we'll start to combine them. Just so everyone's clear. But to run this software I need to set things up. So just bear with me as I set up the picture so it's nice to display. We're going to create some plots. I'll do it a bit quickly. I'll copy and paste some commands that I did before and then it will make sense. Just set up the axes. The labels. And we're going to plot a sine wave from time 0 to 1 second. Very simple. And set the axes. Access values. And let's get ready. Start simple and then you don't have to worry about those commands. I was just setting up this picture. Now I'm going to create a plot. On the x-axis we'll have time. And then on the time here, on the y-axis we'll have the signal. The signal strength. Our sinusoid. The notation may be a little bit confusing to get started with but you'll make sense of it. 1 times sine 2 times pi times 1 times t plus 0. I'll zoom in then we'll zoom back out so people can see. I'm going to plot time versus our signal. Where the signal the peak amplitude a this multiplies 1 I'll set it to 1. Sine of 2 times pi the frequency I'll set to 1 and the phase to 0. The simplest signal we can start with. And I'll just make the color of that plot to be blue. Exciting? Same as what we saw before. Let's just vary a little bit. Let's change the frequency from 1 to 2. 2 times pi times 2t the general formula 2pi ft And you see the frequency changes and we can change maybe a green one we can change the peak amplitude to say 1.5 and also change the frequency to 3 what are we going to see? The frequency is 3 the peak amplitude is 1.5 try and think of what you're going to see. Within 1 second 0 to 1 the frequency is 3 so we see 3 repetitions of that sine wave and the peak amplitude is 1.5 it goes from 0 to plus 1.5 down to minus 1.5 Let's try and look at the phase a little bit because that's maybe the hardest one to visualize or to recognize what the impact will be. Let's start again with a clean plot. Let's try again our first one we had a phase of 0 plus 0 plus nothing here. Let's change the phase keep everything else the same a red one the phase is measured it's an angle it's measured in radians so not in degrees you can convert it to degrees if you like measured in radians pi over 4 how many degrees how many degrees pi over 4 5 a circle is 2 pi 360 degrees is 2 pi so pi is 180 pi on 2 is 90 pi on 4 will be 45 degrees so a phase offset you can see the shift you can think it's shifted back in time pi over 2 a phase of 90 degrees it looks it back even further another 45 degrees 3 pi on 4 and pi what will we get? a phase of pi what will our side wave look like? anyone plot it with their finger? a phase of pi what shape will it be? should be upside down that is goes down first then up all back to this point where we go down first and then up a phase of 2 pi 2 pi is the same as 0 all the way around 360 degrees is the same as 0 in terms of the phase offset in a side so we can vary let's summarize with a sinusoid we can vary 3 parameters the peak amplitude sometimes just referred to as the amplitude the frequency and the phase and in fact what we're going to study in signals is that there are many different approaches of varying those parameters to create different real signals who's listened to radio before? what channel? not internet radio FM, what's FM mean? frequency modulation the other form of radio AM, amplitude modulation so with radio there are two common approaches where to send the audio radio is audio, music and people talking to send that as a signal from the radio tower to your car or your radio receiver they with FM they apply some approach which involves changing the frequency of the some signal sent, frequency modulation and with AM they change the amplitude of the signal so we get amplitude modulation we'll see them in the signal encoding techniques and some other ones which again just changing these 3 parameters amplitude frequency and phase someone I asked before how do you draw a signal and someone drew a square wave can you create a square wave using sine waves? a square wave a digital wave form let's try because that's what we think of in terms of what we call digital signaling we can send plus some voltage for some time and maybe zero voltage or minus some voltage and hold that level to create this digital wave form let's clear this and try some other things now for these demonstrations let's set the phase to zero so I'll remove the plus zero just to ignore that and we'll set the in the initial one I'll set the peak amplitude instead of typing one times there's no need to type one times it's just sine just to save some space sine 2 pi and for an example let's set the frequency to 2 what color is k? black here's our base signal it has a frequency of 2, 2 hertz 2 repetitions within 1 second let's try a different one let's change the peak amplitude to be 1 third instead of 1, 1 third and let's change the frequency instead of 2 hertz to be 6 hertz so it's 2 pi 2 times 3t or 2 pi 6t go back to our lecture notes the general formula peak amplitude sine 2 pi ft 2 pi t times the frequency so in this specific example 2 pi 6t frequency is 6 you'll see why I write it as 2 times 3 in a moment that'll make more sense then just a difference sine wave instead of the height the peak amplitude is 1 third 3 times the frequency frequency of 6 so you see 3 times the number of repetitions in 1 second just 2 sine waves now we'll add them together so what do we get if we add the 2 together anyone want to predict or draw the shape add the 2 together that's a little bit harder to visualize but if you look at the shape at each point in time add the 2 values together so at this peak point it's the value there 1 plus whatever this is minus 0.3 so we 0.7 so add them together and see what we get so take the first one and I'll add the second one and it's the blue one is the shape that we get when we add those 2 sine at size together you can see it's not this smooth sine wave anymore the peak has some 2 humps at the top because of this 1 third small one added together produces that shape it starts at 0 it crosses 0 here goes down and then back up at 0 and so on what's the frequency of the blue signal what is the frequency of the blue signal in 1 second you can see it goes up it comes back to the origin and then comes back to the origin here 2 repetitions in 1 second it's a frequency of 2 hertz of that blue signal the first sine wave had a frequency of 2 hertz the second one had a frequency of 6 hertz when we added them together the resulting sine wave had a frequency of 2 hertz we'll see that we'll take advantage of that as we go through why do we do that let's see why we do it let's add some more to that one I'll draw it again but without the 2 components I'll draw that one again but just the resulting wave so that was the resulting wave just to be a bit clearer the frequency of 2 hertz 2 repetitions in 1 second peak amplitude is it 1? not quite okay so the peak have to be careful there I want to change the peak amplitude same plot exactly the same equation except I'm going to multiply everything on times by 4 over pi it's going to be 4 over pi sine 2 pi 2t plus 4 over pi times 1 third sine 2 pi 6t everything's multiplied by 4 over pi what will that do this will be a red one what will the red plot look like can you visualize what the red one when I press enter will look like multiplying by something out the front what does it do just changes the peak amplitude increases the height as we saw here we change the peak amplitude from 1 to 0.5 the height was cut in half here we're just changing the peak amplitude by multiplying by 4 over pi just move things up okay why did I do that it'll make sense soon so there's still a question why would I multiply by 4 over pi it'll make sense as we go through the next few steps so let's focus on the red one we've got 2 sin added together sine 2 pi 2t 1 third sine 2 pi 6t add them together multiply by 4 over pi those 2 sin I'll call them 2 components of the resulting signal the resulting signal is made up of 2 different components let's add a third component and see what shape we get and then we'll come back and explain why we're doing this so I'll clear this figure to make it a bit nicer we'll plot an original there's our original sine wave but for now I'm multiplying everything by 4 over pi so it's gone up above 1 there 4 over pi is about 1.3 and then our second one 2 components we added this red one we added an extra part of 1.3 of the original one and 2 pi 6t and that's what we got there 4 over pi sine 2 pi 2t plus 1.3 sine 2 pi 6t the way that I wrote it you'll start to see some pattern arriving 1.3 sine 2 pi 2 3t the 3 and the 3 here are related the way that I've chose them is that they're the same I want to add another component a third sine wave I'm going to add one which is one fifth of the original size a smaller one and the frequency will be 2 pi 2 times 5t and instead of typing I'll just copy and paste so I don't make mistakes it wraps around but the 3 sine waves sine 2 pi 2t 1.3 sine 2 pi 2 times 3t 1.5 sine 2 pi 2 times 5t and in green we get this what shape is the green one starting to resemble the original one the blue one was the original sine wave smooth there's a couple of humps at the top 2 humps there not as smooth as the sine wave the green one actually has 3 humps at the top the way that I've chosen adding these sine waves together is producing a shape and what I want to do is add more sine waves until I get a shape of a digital wave form square so that's why I've chosen the values in this way because I know that if I keep adding these sine waves in such a pattern the resulting signal will be a perfect square wave form trying to demonstrate the point that what we can do is create a digital wave form just by combining sinusoid and in fact any communication signal doesn't matter the shape or the holding signal we can think of it as made up of adding together sine waves and that makes the analysis of communication systems much easier let's add another component same as before 1 5th sine 2 pi 5 t 1 7th sine 2 pi 2 times 7 t you see the pattern 1 3rd 2 times 3 1 7th getting smaller and increasing the frequency of those individual components it's a bit harder to see there I can keep adding components but to illustrate the point I've created one with something like 30 odd components took me a long time to type this one goes up to I think 59 okay the same pattern 1 over 27 2 times 27 1 over 29 2 times 29 we'll see the pattern in a moment and we're close to a square wave there are some variations here but the black one we're getting close to a perfect square wave how do we get a perfect square wave how do we get it even nicer than this what do I do how do I get it so that those it doesn't go up and down just on those edges of the square wave sigma is just the sum of here I'm typing the actual sum plus plus plus and then do what add more what I call components add more these sine waves 1 over 61 sine 2 pi 2 times 61 t add another one how many should I add if I add an infinite number of components you'll get a perfect square wave but it would take me too long to type an infinite number of components so in theory adding an infinite number of components in this pattern produces a perfect square wave any communication signal can be made up of combining sinusoids together let's let's look at some of the properties of these resulting signals in all of them what's the frequency it's the same it's still 2 hertz didn't matter how many components we added there the resulting signal is still 2 hertz it's still 2 repetitions per second the period is still half a second this resulting signal why is it 2 hertz maybe you can see in the pattern if you can almost see here I type 2 pi 2 times 57 2 pi 2 times 59 2 times 53 and so on the original sine wave was 2 pi 2t the frequency with 2 each component is a multiple of 2 an integer multiple of 2 if we have such a resulting signal where each component is an integer multiple of the frequency of the first component then the resulting signal is the same as the first one and that resulting well that that first frequency these 2 hertz in this case is called the fundamental frequency and the other frequencies like 2 times 55 110 hertz are called harmonics, harmonic frequencies those details are not so important although the fundamental frequency will be important when we do some analysis what can we do next come back to our slides let's introduce some concepts make note of some things we'll do this again and then write down an equation to represent some of these start with this one this is the red one from the same as before let's write the equation for this and then look at some of the characteristics of this one try and write the s of t equals you can almost copy from the software there try and write the equation in a nicer way s of t equals 4 pi all of this 4 pi times by sine 2 pi 2t plus 1 third sine 2 pi 6t I'll just write that and then we'll analyze or talk about some characteristics of that equation I'll call it s2 of t because we'll have some others later we had 4 over pi was that multiplier and all inside we had the first component of sine what do we have 2 pi 2t or simply 4 pi t plus 1 third sine it was 2 pi 2 2 times 3t or 12t 12 pi t and close the square brackets that's the signal equation for the one that we just plotted with the two humps combination of two components but instead of the full 2 times pi times 2t just 4 times pi t and you see the first component has a peak amplitude if you expand the multiplication 4 over pi sine 4 pi t remember the general equation a sine 2 pi ft plus the phase ignores the phase the phase is 0 in these examples so a sine 2 pi ft what is a 4 over pi if we look at the two components the first one we'd say here a is 4 over pi and what is the frequency of this component someone said 4 someone said 1 this component this one we split it into two sine waves the general equation is a sine 2 pi ft f is the frequency so what value of f do we need to have 2 2 pi ft 2 times pi times 2 so the frequency of the first component is 2 hertz the amplitude I should write units of say volts but I'll be lazy and not write the units we don't care at this stage sometimes we represent as volts other times watts some power level the second component and the phase was 0 it's right at just to be complete the second component the peak amplitude is 1 over 3 4 times pi times 1 over 3 let's keep it as that frequency of 12 pi t is 6 hertz because the general formula 2 pi ft don't forget that 2 phase is also 0 so if we add 2 sinusoid with these parameters together we get this plot okay that's what we did there note let's look at the frequencies the first component has a frequency of 2 hertz the second component has a frequency of 6 hertz which is an integer multiple of the other this is 3 times 2 if we have such then we can say the resulting signal the fundamental frequency of our resulting signal s2 of t equals 2 hertz if the two components frequencies such that the others are integer multiples of 1 then that 1 is the fundamental frequency of that s2 of t or the frequency of that signal the frequency of s2 is 2 hertz and we see that here we can say now that s2 contains two components a component with frequency 2 hertz and a component with frequency 6 hertz and they have different amplitudes we chose the amplitudes to get that nice shape such that if we keep adding them in that way we would eventually get a square wave but it's not always like that the range of frequencies inside s2 or the set of frequencies sorry don't copy the set of frequencies the set of frequencies in s2 of t are 2 and 6 hertz that is s2 of t is made up of two sinusoids one has the frequency of 2 hertz one has the frequency of 6 hertz so we can say the set of frequencies in this signal are 2 and 6 hertz we call that the spectrum of the signal the set of frequencies inside a signal is called the spectrum so we can say the spectrum of s2 is 2 and 6 hertz so we're introducing some characteristics that we'll use to talk about signals the spectrum is one thing the fundamental frequency will refer to this sometimes the let's say the width of the spectrum is that the spectrum contains 2 and 6 hertz the width is the difference between the minimum frequency component and the maximum in this case there are just 2 2 and 6 what's the width what's the difference between 6 and 2 4 so we say the width of the spectrum the spectrum ranges from 2 all the way up to 6 the width how wide is it what's the name of that we refer to the width of the spectrum as bandwidth the width of the band of frequencies so we say the bandwidth of s2 is 4 hertz and this will be an important parameter when we talk about real signals the bandwidth of a signal so with any communication signal doesn't matter how complex the shape is in theory it can be broken down into the addition waves of sinusoids and each of those sinusoids have a frequency so we can determine the spectrum of that signal and the difference between the minimum frequency component and the maximum frequency component is the bandwidth of that signal so we can talk about for some signal it has some bandwidth and as we go through this topic we'll see that the bandwidth can impact upon some practical things like data rate how many bits can we send per second the bandwidth will have a role in that but we're not there yet any questions before we do a next example simple concept so far but just looking at the very fundamentals of signals let me know if there's some errors in the calculations or there's some questions about the writing let's go back to our plot that was with two components I'll do the green one with three components sine 2 pi 2T one third sine 2 pi 2 times 3T one fifth sine 2 pi 2 times 5T all multiplied by 4 over pi at the front the green one which has those three pumps at the top and we kept adding components until we got close to a square wave write the equation for the green one and determine its spectrum fundamental frequency and bandwidth the question how do we get the fundamental frequency S2 of T the red one had two components frequency of 2 hertz and 6 hertz this component is an integer multiple the frequency is an integer multiple of this component this frequency 6 hertz is 3 times 2 hertz in that case when all the components they're all integer multiples of another that one is the fundamental frequency this is 1 times 2 this is 3 times 2 the fundamental frequency therefore is 2 and the signals in these simple examples will have a fundamental frequency that we can easily determine write the equation for the green one write the equation determine the spectrum and bandwidth of the green signal it's the same as the previous one plus another component write it down just so you understand the structure of this signal and maybe if it's hard to read it's hard to read in the for this software I'll help you by writing it it's the same as the first one but there's a third component 1 over 5 see if we can fit it in let's call it s3 of t I'm going to have to squeeze some things in here because we'll run out of space 4 over pi was the multiplier at the front what do we have 4 pi t plus 1 third sine 12 pi t that was the same as before plus 1 fifth what's the the third component 1 fifth sine what if you can't remember from the software you can work it out by the pattern the first component was 2 pi 2t 2 pi 2 times 3t 2 pi 2 times 5t 20 hertz not 20 hertz 20 pi t 3 components the peak amplitudes of component 1, 2 and 3 just the multipliers out the front find the frequencies of each component the frequencies of component 1, 2 and 3 2, 6 and 10 from before 2 and 6 10, 20 pi t the general formula is 2 pi ft so f must be 10 10 hertz 6 hertz then find those 3 parameters of that resulting signal how do we get 20 pi if we look at our plot let's see if I can zoom in a little bit maybe hard to see but the way that I created the plot sine 2 pi the last 5 minutes let's keep it down and just explain so everyone's clear just wait 1 minute just so others can hear the way that I created it I followed some pattern ignore the multiplier for a moment sine 2 pi 2t our general formula is sine 2 pi ft so f is 2 in this case the next one was 1 third of the height and 3 times the frequency sine 2 pi 2 times 3t or sine 2 pi 6t that's the pattern I was following 1 third of the height 3 times the frequency of the first component and the next one and I have to zoom back out where to go 1 fifth sine 2 pi 2 times 5t see the pattern 1 third 3 times 2 1 fifth 2 and if I added another one it would be 1 seventh 7 times 2 the frequency of the second component is 6 2 times 3 of the third component the frequency is 10 2 times 5 not all signals have that pattern I just chose it so that if we kept going like that we would get a perfect square wave fundamental frequency component 1 2 hertz 2 frequency of 6 hertz component 3 10 hertz they're all integer multiples of 2 hertz 2 times 1 2 times 3 2 times 5 so they're all integer multiples of this other one f1 so the fundamental frequency is still 2 hertz in this case the spectrum is the set of frequencies inside this signal and I'll just write it as 2 6 and 10 hertz giving us a bandwidth of what so I've heard 2 numbers 8 and 4 I think 10 minus 2 the width so from the minimum to the maximum the bandwidth is 8 hertz and if you draw the next one with another component we will not 1 over 7 what would the fourth component be 1 over 7 2 pi 2 times 7 T which is what 28 I will not write it down but if we had 107 2 times pi 2 times 7 2 times 7 is 14 times 2 28 pi T the frequency of the fourth component would be 14 hertz 12 hertz so we'll stop there we'll continue next week and then we'll start to see that the bandwidth of a signal can impact upon the data rate how fast we can send bits and it may also impact upon the cost of using that signal so we'll come back to see why the bandwidth and spectrum are important next week questions