Fuzzy Logic Exercise: Fan Speed Control

Interactive fuzzy logic exercise demonstrating fan speed control based on temperature and humidity. This system uses min-max operators for rule evaluation and centroid method for defuzzification.

Exercise Problem

Task: Design a fuzzy system to control fan speed based on temperature and humidity.

Example Rules:

  • IF temperature is High OR humidity is High THEN fan speed is Fast
  • IF temperature is Medium AND humidity is Medium THEN fan speed is Medium
  • IF temperature is Low AND humidity is Low THEN fan speed is Slow

Worked Example (Solution Guide)

Example Inputs: Suppose the crisp inputs are: Temperature = 30°C and Humidity = 70%. During fuzzification, these inputs are mapped to degrees of membership, for example: µ(Temp=Medium)=0.4, µ(Temp=High)=0.6, µ(Humid=Medium)=0.3, µ(Humid=High)=0.7.

Rule Evaluation: The fuzzy rules are then evaluated using min–max operators:

  • Rule 1 (OR): degree = max(0.6, 0.7) = 0.7
  • Rule 2 (AND): degree = min(0.4, 0.3) = 0.3
  • Rule 3 (AND): degree = min(0.0, 0.0) = 0.0

Output: These truth values are applied to the output membership functions (Fast, Medium, Slow), and then aggregated. Finally, during defuzzification using the centroid method, the crisp output might result in a value corresponding to around 80% fan speed, meaning the system decides to run the fan fairly fast.

Note: Use the interactive controls below to explore how different temperature and humidity values affect the fuzzy inference process. Set the inputs to 30°C and 70% to see this example in action.

Input Variables

Adjust the sliders to change the temperature and humidity values and observe how they affect the fuzzy inference process.

30°C
70%

Step 1: Fuzzification

Convert crisp inputs (temperature and humidity) into fuzzy membership values.

Temperature Membership Functions

μ(Temp=Low) = 0.00

μ(Temp=Medium) = 0.67

μ(Temp=High) = 0.33

Humidity Membership Functions

μ(Humid=Low) = 0.00

μ(Humid=Medium) = 1.00

μ(Humid=High) = 0.60

Step 2: Rule Evaluation

Evaluate fuzzy rules using min (AND) and max (OR) operators to determine rule firing strengths.

Rule 1: IF Temp=High OR Humid=High THEN Fan=Fast

Calculation: max(μ(Temp=High), μ(Humid=High)) = max(0.33, 0.60) = 0.60

Firing Strength: 0.60

Rule 2: IF Temp=Medium AND Humid=Medium THEN Fan=Medium

Calculation: min(μ(Temp=Medium), μ(Humid=Medium)) = min(0.67, 1.00) = 0.67

Firing Strength: 0.67

Rule 3: IF Temp=Low AND Humid=Low THEN Fan=Slow

Calculation: min(μ(Temp=Low), μ(Humid=Low)) = min(0.00, 0.00) = 0.00

Firing Strength: 0.00

Step 3: Aggregation

Apply firing strengths to output membership functions (clipping) and aggregate using MAX operation.

Step 4: Defuzzification (Centroid Method)

Convert the aggregated fuzzy output into a crisp value using the centroid (center of gravity) method.

Final Crisp Output:

Recommended Fan Speed = 64.6%

Calculation Breakdown:

Numerator = Σ(speed × μ(speed))

= 31 × 0.05 + 32 × 0.10 + 33 × 0.15

= 1.55 + 3.20 + 4.95 + ...

= 2151.08

Denominator = Σ(μ(speed))

= 0.05 + 0.10 + 0.15 + ...

= 33.32

Output = 2151.08 / 33.32 = 64.56%

Complete Calculation:

All contributing points:

Speed 31%: μ = 0.05, Contribution = 31 × 0.05 = 1.55

Speed 32%: μ = 0.10, Contribution = 32 × 0.10 = 3.20

Speed 33%: μ = 0.15, Contribution = 33 × 0.15 = 4.95

Speed 34%: μ = 0.20, Contribution = 34 × 0.20 = 6.80

Speed 35%: μ = 0.25, Contribution = 35 × 0.25 = 8.75

Speed 36%: μ = 0.30, Contribution = 36 × 0.30 = 10.80

Speed 37%: μ = 0.35, Contribution = 37 × 0.35 = 12.95

Speed 38%: μ = 0.40, Contribution = 38 × 0.40 = 15.20

Speed 39%: μ = 0.45, Contribution = 39 × 0.45 = 17.55

Speed 40%: μ = 0.50, Contribution = 40 × 0.50 = 20.00

Speed 41%: μ = 0.55, Contribution = 41 × 0.55 = 22.55

Speed 42%: μ = 0.60, Contribution = 42 × 0.60 = 25.20

Speed 43%: μ = 0.65, Contribution = 43 × 0.65 = 27.95

Speed 44%: μ = 0.67, Contribution = 44 × 0.67 = 29.33

Speed 45%: μ = 0.67, Contribution = 45 × 0.67 = 30.00

Speed 46%: μ = 0.67, Contribution = 46 × 0.67 = 30.67

Speed 47%: μ = 0.67, Contribution = 47 × 0.67 = 31.33

Speed 48%: μ = 0.67, Contribution = 48 × 0.67 = 32.00

Speed 49%: μ = 0.67, Contribution = 49 × 0.67 = 32.67

Speed 50%: μ = 0.67, Contribution = 50 × 0.67 = 33.33

Speed 51%: μ = 0.67, Contribution = 51 × 0.67 = 34.00

Speed 52%: μ = 0.67, Contribution = 52 × 0.67 = 34.67

Speed 53%: μ = 0.67, Contribution = 53 × 0.67 = 35.33

Speed 54%: μ = 0.67, Contribution = 54 × 0.67 = 36.00

Speed 55%: μ = 0.67, Contribution = 55 × 0.67 = 36.67

Speed 56%: μ = 0.67, Contribution = 56 × 0.67 = 37.33

Speed 57%: μ = 0.65, Contribution = 57 × 0.65 = 37.05

Speed 58%: μ = 0.60, Contribution = 58 × 0.60 = 34.80

Speed 59%: μ = 0.55, Contribution = 59 × 0.55 = 32.45

Speed 60%: μ = 0.50, Contribution = 60 × 0.50 = 30.00

Speed 61%: μ = 0.45, Contribution = 61 × 0.45 = 27.45

Speed 62%: μ = 0.40, Contribution = 62 × 0.40 = 24.80

Speed 63%: μ = 0.35, Contribution = 63 × 0.35 = 22.05

Speed 64%: μ = 0.30, Contribution = 64 × 0.30 = 19.20

Speed 65%: μ = 0.25, Contribution = 65 × 0.25 = 16.25

Speed 66%: μ = 0.30, Contribution = 66 × 0.30 = 19.80

Speed 67%: μ = 0.35, Contribution = 67 × 0.35 = 23.45

Speed 68%: μ = 0.40, Contribution = 68 × 0.40 = 27.20

Speed 69%: μ = 0.45, Contribution = 69 × 0.45 = 31.05

Speed 70%: μ = 0.50, Contribution = 70 × 0.50 = 35.00

Speed 71%: μ = 0.55, Contribution = 71 × 0.55 = 39.05

Speed 72%: μ = 0.60, Contribution = 72 × 0.60 = 43.20

Speed 73%: μ = 0.60, Contribution = 73 × 0.60 = 43.80

Speed 74%: μ = 0.60, Contribution = 74 × 0.60 = 44.40

Speed 75%: μ = 0.60, Contribution = 75 × 0.60 = 45.00

Speed 76%: μ = 0.60, Contribution = 76 × 0.60 = 45.60

Speed 77%: μ = 0.60, Contribution = 77 × 0.60 = 46.20

Speed 78%: μ = 0.60, Contribution = 78 × 0.60 = 46.80

Speed 79%: μ = 0.60, Contribution = 79 × 0.60 = 47.40

Speed 80%: μ = 0.60, Contribution = 80 × 0.60 = 48.00

Speed 81%: μ = 0.60, Contribution = 81 × 0.60 = 48.60

Speed 82%: μ = 0.60, Contribution = 82 × 0.60 = 49.20

Speed 83%: μ = 0.60, Contribution = 83 × 0.60 = 49.80

Speed 84%: μ = 0.60, Contribution = 84 × 0.60 = 50.40

Speed 85%: μ = 0.60, Contribution = 85 × 0.60 = 51.00

Speed 86%: μ = 0.60, Contribution = 86 × 0.60 = 51.60

Speed 87%: μ = 0.60, Contribution = 87 × 0.60 = 52.20

Speed 88%: μ = 0.60, Contribution = 88 × 0.60 = 52.80

Speed 89%: μ = 0.55, Contribution = 89 × 0.55 = 48.95

Speed 90%: μ = 0.50, Contribution = 90 × 0.50 = 45.00

Speed 91%: μ = 0.45, Contribution = 91 × 0.45 = 40.95

Speed 92%: μ = 0.40, Contribution = 92 × 0.40 = 36.80

Speed 93%: μ = 0.35, Contribution = 93 × 0.35 = 32.55

Speed 94%: μ = 0.30, Contribution = 94 × 0.30 = 28.20

Speed 95%: μ = 0.25, Contribution = 95 × 0.25 = 23.75

Speed 96%: μ = 0.20, Contribution = 96 × 0.20 = 19.20

Speed 97%: μ = 0.15, Contribution = 97 × 0.15 = 14.55

Speed 98%: μ = 0.10, Contribution = 98 × 0.10 = 9.80

Speed 99%: μ = 0.05, Contribution = 99 × 0.05 = 4.95

Sum of contributions (Numerator) = 2151.08

Sum of membership values (Denominator) = 33.32

Final Output = 2151.08 / 33.32 = 64.56%

Summary

  1. Fuzzification: Temperature 30°C → μ(Temp=Low)=0.00, μ(Temp=Medium)=0.67, μ(Temp=High)=0.33
  2. Fuzzification: Humidity 70% → μ(Humid=Low)=0.00, μ(Humid=Medium)=1.00, μ(Humid=High)=0.60
  3. Rule Evaluation: Rule 1 (OR) = 0.60, Rule 2 (AND) = 0.67, Rule 3 (AND) = 0.00
  4. Aggregation: Combined output using MAX operation
  5. Defuzzification: Centroid method → Fan Speed = 64.6%